Install Android, Cordova, and Ionic Framework in Ubuntu

After recognizing that I develop almost entirely on Ubuntu Linux, a subscriber of mine asked me how to properly set up an Ubuntu machine for Ionic Framework Android development.  Now there are a ton of options to handle this task, but not many bare bones solutions.  Most solutions on the internet explain how to use an IDE, or fail to elaborate a complete installation.

If you’re not interested in learning how to accomplish the task of installing NPM, Android, Apache Cordova, and Ionic Framework, you can just download a convenient shell script that I made.  If you want to know how this shell script works and would like to get the most out of it, continue reading the article.

To install everything using the shell script I provided, download it and do the following:

The above will make the script executable and then it will be installed using a privileged account.  Failing to use sudo will probably give you strange results.

The installation script will download and configure the following:

  • Java JDK
  • Apache Ant
  • Android SDK
  • NodeJS / NPM
  • Apache Cordova
  • Ionic Framework

You can find most of these items installed to your operating system’s /opt directory.  Once setup has completed, you will need to restart your Ubuntu session, by logging out or restarting your machine.  When you sign back in you will need to download the various Android targets that could not be installed via a command line.

To download the necessary Android targets and platform tools you will need to enter android from a command prompt to launch the Android UI.

Install Android Targets

Start by installing whatever the SDK Manager recommends when launching it.  You will need Android API 19 for Ionic Framework, so install that when you’re able to.

So what exactly are we doing in this wonderful script?  Pretty much only very basic downloading and extracting in an automated fashion.

Let’s start by looking at the following line:

The above line of code will parse the system’s CPU information looking for the architecture.  Because there are no universal binaries for x86 and x64 architectures we need to figure out what we are installing.  The above line will either return x86_64 for 64-bit architectures or i686 for 32-bit architectures.

Next in our script we want to update our Ubuntu software repository list.  Because we will be installing Java and Ant from the software channel, we need it to be up to date.  Updating the list can be done as follows:

Because the file names for each Ubuntu architecture are different, we need to create a conditional that first determines which binary set should be downloaded and installed.  If you’re familiar with Linux, you’ll know that we can do this check like so:

For the x86 and x64 architectures, the process is pretty much the same.  Only the file names are different.  However, a critical difference in the x64 architecture is that we need to download a few x86 libraries.  This can be done as follows:

Once that’s done we start downloading the defined versions of NodeJS and the Android SDK by making use of the wget linux command.  After downloading, we need to extract the tarballs and rename the directories for easier management.  All this can be demonstrated below:

Since the Android SDK is being placed in a location that requires higher permissions, we need to change the permissions to allow for read and write.  This is because the SDK doesn’t ship with everything out of the box.  You’ll need install these items after running the install script.

When our NodeJS and Android SDK directories are placed in the correct location, we need to make sure that they get added to our user profile.  Adding the paths to the user profile makes them usable every time you sign into your computer.  Adding to the profile can be done like so:

Adding to the profile isn’t good enough for our script because for changes to happen the Ubuntu session must be restarted.  Because of this, we also need to temporarily alter our path by running the following:

Just a few things left to do, then we are done.  By default, Ubuntu doesn’t ship with the Java JDK or Apache Ant.  These must be installed separately.  Because I wanted to keep a silent installation, I added a few tags to a standard install:

The last thing we want to do before cleanup, is install Apache Cordova and Ionic Framework using NPM:

Just like that we are good to go.  If everything went smooth you should be able to use Ionic Framework with Android in a few lines of code:

If you’re interested in seeing the full source code to this script you can either download and open it in a text editor, or see below:

A video version of this article can be seen below.

Nic Raboy

Nic Raboy is an advocate of modern web and mobile development technologies. He has experience in Java, JavaScript, Golang and a variety of frameworks such as Angular, NativeScript, and Apache Cordova. Nic writes about his development experiences related to making web and mobile development easier to understand.

  • willy

    Hi
    Thank you for your tutorial is very nice!

    I have one error when this command ‘ionic platform add android’

    This is the error:
    /home/willy/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:126
    throw e;
    ^
    Error: Could not find JAVA_HOME. Try setting the environment variable manually
    at Q.then.then.msg (/home/willy/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/lib/check_reqs.js:107:31)
    at _fulfilled (/home/willy/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:798:54)
    at self.promiseDispatch.done (/home/willy/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:827:30)
    at Promise.promise.promiseDispatch (/home/willy/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:760:13)
    at /home/willy/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:821:14
    at flush (/home/willy/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:108:17)
    at process._tickCallback (node.js:419:13)
    at Function.Module.runMain (module.js:499:11)
    at startup (node.js:119:16)
    at node.js:906:3
    Error: /home/willy/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/create: Command failed with exit code 8
    at ChildProcess.whenDone (/usr/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:135:23)
    at ChildProcess.emit (events.js:98:17)
    at maybeClose (child_process.js:756:16)
    at Process.ChildProcess._handle.onexit (child_process.js:823:5)

    How Can I solve?

    Thanks a lot!

    • Hi Willy,

      It appears a recent Ubuntu update may have wiped out the $JAVA_HOME variable. I will fix this in the script in the coming days, but for the temporary add the following to your .profile file in your home directory:

      export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-amd64

      Note that your version of the JDK may not be java-1.6.0-openjdk-amd64. Use whatever is available in the /usr/lib/jvm directory.

      After you add this, restart your Ubuntu session by signing out and then back in. The missing JAVA_HOME problem should be resolved.

      Regards,

  • Hi Nic,

    Thanks for creating this script man, make things easy 🙂

    anyway dude I just installed this on a fresh ubuntu 13.10 VM. I’ve been having the same issue both on ubuntu 14.04 LTS and on ubuntu 13.10. Please see error below:
    Please will you kindly assist?

    [email protected]:/home/muzikayise-dev/apps/ionic/mfbApp# ionic platform add android
    npm http GET https://registry.npmjs.org/cordova-android/3.6.3
    npm http 200 https://registry.npmjs.org/cordova-android/3.6.3
    npm http GET https://registry.npmjs.org/cordova-android/-/cordova-android-3.6.3.tgz
    npm http 200 https://registry.npmjs.org/cordova-android/-/cordova-android-3.6.3.tgz
    Creating android project...

    /root/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:126
    throw e;
    ^
    Error: ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions.
    at /root/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/lib/check_reqs.js:158:19
    at _fulfilled (/root/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:798:54)
    at self.promiseDispatch.done (/root/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:827:30)
    at Promise.promise.promiseDispatch (/root/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:760:13)
    at /root/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:821:14
    at flush (/root/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:108:17)
    at process._tickCallback (node.js:415:13)
    at Function.Module.runMain (module.js:499:11)
    at startup (node.js:119:16)
    at node.js:902:3
    Error: /root/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/create: Command failed with exit code 8
    at ChildProcess.whenDone (/usr/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:135:23)
    at ChildProcess.EventEmitter.emit (events.js:98:17)
    at maybeClose (child_process.js:743:16)
    at Process.ChildProcess._handle.onexit (child_process.js:810:5)

    • Hi Muzikayise,

      If the script completed successfully, you should have android in your path. Did you run the script with sudo?. If you open ~/.profile do the following lines exist at the bottom?:

      export PATH=$PATH:/opt/android-sdk/platform-tools
      export PATH=$PATH:/opt/android-sdk/tools

      As for ANDROID_HOME. For whatever reason, my installation didn’t complain about it, but since yours did, you can add the following to your ~/.profile.

      export ANDROID_HOME=/opt/android-sdk

      It is basically just the root directory of your SDK. Restarting your Ubuntu session will put the change into play.

      Let me know what is going on with your ~/.profile and we’ll troubleshoot from there.

      Cheers,

      • Hey Nic,

        Trust you are well bud, thanks for getting back to me.
        So I had a look at the ~/.profile file. I did use sudo when I ran the script. This is what the ~/.profile file looks like now (I updated it):


        # ~/.profile: executed by the command interpreter for login shells.
        # This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
        # exists.
        # see /usr/share/doc/bash/examples/startup-files for examples.
        # the files are located in the bash-doc package.

        # the default umask is set in /etc/profile; for setting the umask
        # for ssh logins, install and configure the libpam-umask package.
        #umask 022

        # if running bash
        if [ -n "$BASH_VERSION" ]; then
        # include .bashrc if it exists
        if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
        fi
        fi

        # set PATH so it includes user's private bin if it exists
        if [ -d "$HOME/bin" ] ; then
        PATH="$HOME/bin:$PATH"
        fi

        export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-amd64

        export PATH=$PATH:/opt/android-sdk/platform-tools
        export PATH=$PATH:/opt/android-sdk/tools
        export ANDROID_HOME=/opt/android-sdk

        When I try add an android platform without using sudo (ionic platform add android), I get the following error:

        [email protected]:~/apps/ionic/mfbApp$ ionic platform add android
        addCliHookDirectory fs.chmodSync: Error: EPERM, operation not permitted 'hooks/after_prepare/010_add_platform_class.js'
        Creating android project...
        Creating Cordova project for the Android platform:
        Path: platforms/android
        Package: com.ionicframework.mfbapp463874
        Name: mfbApp
        Android target: android-19
        Copying template files...
        shell.js: internal error
        Error: ENOENT, no such file or directory 'platforms/android/assets'
        at Object.fs.mkdirSync (fs.js:642:18)
        at /home/muzikayise-dev/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/shelljs/src/cp.js:173:14
        at Array.forEach (native)
        at Object._cp (/home/muzikayise-dev/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/shelljs/src/cp.js:156:11)
        at Object.cp (/home/muzikayise-dev/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/shelljs/src/common.js:172:23)
        at /home/muzikayise-dev/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/lib/create.js:245:19
        at setShellFatal (/home/muzikayise-dev/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/lib/create.js:45:5)
        at /home/muzikayise-dev/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/lib/create.js:243:9
        at _fulfilled (/home/muzikayise-dev/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:798:54)
        at self.promiseDispatch.done (/home/muzikayise-dev/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:827:30)
        Error: /home/muzikayise-dev/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/create: Command failed with exit code 1
        at ChildProcess.whenDone (/usr/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:135:23)
        at ChildProcess.EventEmitter.emit (events.js:98:17)
        at maybeClose (child_process.js:743:16)
        at Process.ChildProcess._handle.onexit (child_process.js:810:5)

        when I use sudo (sudo ionic platform add android), I get the following error:

        [email protected]:~/apps/ionic/mfbApp$ sudo ionic platform add android
        [sudo] password for muzikayise-dev:
        Creating android project...

        /home/muzikayise-dev/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:126
        throw e;
        ^
        Error: ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions.
        at /home/muzikayise-dev/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/lib/check_reqs.js:158:19
        at _fulfilled (/home/muzikayise-dev/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:798:54)
        at self.promiseDispatch.done (/home/muzikayise-dev/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:827:30)
        at Promise.promise.promiseDispatch (/home/muzikayise-dev/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:760:13)
        at /home/muzikayise-dev/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:821:14
        at flush (/home/muzikayise-dev/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:108:17)
        at process._tickCallback (node.js:415:13)
        at Function.Module.runMain (module.js:499:11)
        at startup (node.js:119:16)
        at node.js:902:3
        Error: /home/muzikayise-dev/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/create: Command failed with exit code 8
        at ChildProcess.whenDone (/usr/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:135:23)
        at ChildProcess.EventEmitter.emit (events.js:98:17)
        at maybeClose (child_process.js:743:16)
        at Process.ChildProcess._handle.onexit (child_process.js:810:5)

        I’m confused because ANDROID_HOME has been added to the PATH in the ~/.profile

        Did I miss something?

        thanks again for your kind assistance.

        ta.
        muzi

        • Something is not correct here. Did you do anything after running the script?

          The script recursively sets ANDROID_HOME to full privilege with the following command:

          chmod 777 "/opt/android-sdk" -R

          When you run android from the terminal does it run without sudo? Check ownership on the ANDROID_HOME and /opt/node directories as well as the permission.

          The only thing I can think of is you’ve done something after the script that changed the ownership or permissions. The script itself is not very complex and doesn’t do a whole lot. In the video you can see it worked flawless for me.

          Please let me know what your permissions and ownership are set to.

          Regards,

          • Howzit Nic,

            thanks again for getting back to me.
            I did reset the permissions using
            chmod 777 "/opt/android-sdk" -R
            still no luck.

            What I’m going to do is start from beginning again re-create a new VM and run the script on this new VM, just like you did in your video.
            will let you know how I go.

            thanks again man for your assistance.

            ta.
            muzi

          • Hi Muzikayise,

            Who is the owner of /opt/node and /opt/android-sdk? Also what are the current permissions for /opt/node? I can’t recommend changing the permissions of that directory to 777, but I’m curious to know what they are.

            Let me know how the install goes. I’ll try the install on a fresh VM in the next day or so to see if anything has changed as well.

            Regards,

          • Mounir

            I am having similar problem and still now working 🙁

            When executing :sudo cordova platform add android

            Error: ANDROID_HOME is not set and “android” command not in your PATH. You must fulfill at least one of these conditions.

          • If you’re using sudo when using cordova or ionic, you’re doing something wrong.

            The PATH for sudo is not the same as your user account which is why you’re getting ANDROID_HOME errors.

            Regards,

  • Nes

    Hi Nic, I have some problems with your snippet 🙁

    [email protected]:~/Escritorio/ExampleProject$ ionic platform add android
    Unable to fetch platform android: Error: EACCES, open ‘/home/nes/.cordova/lib/npm_cache/3271f72c-cordova-android-3-6-3.lock’

    • Hi Nes,

      What version of Ubuntu are you using and did you run the script with sudo?

      • Nes

        Ubuntu 14.04 TLS,
        don’t remember if I used sudo, sorry!

    • Nes

      Just wrote:

      sudo chmod 777 “/opt/android-sdk” -R

      But same error 🙁

      • Can you try to run npm cache clean?

        • Nes

          [email protected]:~/Escritorio/ExampleProject$ npm cache clean
          [email protected]:~/Escritorio/ExampleProject$ ionic platform add android
          Unable to fetch platform android: Error: EACCES, open ‘/home/nes/.cordova/lib/npm_cache/3271f72c-cordova-android-3-6-3.lock’

          Don’t know why..

          • Can you try to manually delete the lock file in question? It should cause no damage to your installation to remove. Also make sure your user account can access all sub directories in that path.

          • Nes

            [email protected]:~/.cordova/lib/npm_cache$ ls
            cordova-android

            File doesn’t exists

          • Sounds like somewhere something went wrong with file / folder ownership and permissions. Had you attempted to install any of this on your own before running my script? Please verify all permissions and ownership for .cordova and below.

          • NES

            Hi again Nic!

            Chmod for .cordova and other folders:

            [email protected]:~$ stat /home/nes/.cordova/
            Fichero: «/home/nes/.cordova/»
            Tamaño: 4096 Bloques: 8 Bloque E/S: 4096 directorio
            Dispositivo: 806h/2054d Nodo-i: 1312084 Enlaces: 3
            Acceso: (0775/drwxrwxr-x)

            775

            I tried before to setup manually all packages, but same result 🙁

          • Nes

            Hey Nic!

            Finally it works!

            sudo chmod -R 777 ‘/home/nes/.cordova/’

            Thanks 🙂

          • Hi Nes,

            I’m happy to hear it works now. However, you shouldn’t have to give it 777. Sounds like the directory has incorrect ownership.

  • Hi Nic,

    I executed ionic emulate android command and after BUILD SUCCESSFUL message I get following error:

    /home/atul/Desktop/firstIonicApp/platforms/android/cordova/node_modules/q/q.js:126
    throw e;
    ^
    ERROR : No emulator images (avds) found, if you would like to create an
    avd follow the instructions provided here:
    http://developer.android.com/tools/devices/index.html
    Or run ‘android create avd –name –target ‘
    in on the command line.
    Error: /home/atul/Desktop/firstIonicApp/platforms/android/cordova/run: Command failed with exit code 8
    at ChildProcess.whenDone (/usr/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:135:23)
    at ChildProcess.emit (events.js:98:17)
    at maybeClose (child_process.js:756:16)
    at Process.ChildProcess._handle.onexit (child_process.js:823:5)

    • Hi Atul,

      If you plan to use the emulate command of Ionic Framework, you need to install the Android emulators. My script does not do this for you. My script and instructions will only set you up to develop and build.

      I encourage you to follow the official Android documentation if you wish to emulate. If you own an Android device, installing on the device is always a better choice than using an emulator.

      Cheers,

  • Fábio

    Hello, I followed the tutorial correctly however when I ran the command node -v he is not found, the command works correntamente android, make sure the folder is in the correct location and are, I am new to linux but I believe this will be the access permissions, you know how I can fix this?

    [email protected]:~$ echo $PATH
    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/android-sdk/tools:/opt/android-sdk/platform-tools:/opt/node/bin
    [email protected]:~$ node -v
    bash: /opt/node/bin/node: Arquivo ou diretório não encontrado

    • Hi Fábio,

      Try to run this:

      chmod 777 /opt/node -R

      That will recursively give Node maximum permissions. I am going to change this in the script because it seems like a lot of people are having issues with Ubuntu permissions after installation. Let me know how that command goes for you.

      Regards,

      • Fábio

        hello, the command you gave me worked fine however I’m having an error when the application build because the ant to check the installed version got the following reply, you know how I can fix this?

        Apache Ant (TM) version 1.9.3 compiled on April 8 2014
        Trying the default build file: build.xml
        Buildfile: build.xml does not exist!
        Build failed

        • Hi Fábio,

          Ant is not working because the current directory is not the correct directory. Here is a sample you can use to test your setup:

          cd ~/Desktop
          ionic start IonicProject blank
          cd IonicProject
          ionic platform add android
          ionic build android

          Of course that will build an Ionic Android application, but it does do a thorough test to make sure everything is set up. Ionic does require ADT 19 as mentioned in my write-up.

          Let me know how this goes.

          Regards,

        • Hi Fabio,

          I had to delete your most recent comment because it was far too long for a blog comment. If pasting a terminal dump, please only paste the first few lines of the error.

          Your error is a result of having spaces in your path. Your path cannot contain spaces otherwise you will receive errors.

          Regards,

          • Fábio

            Here is the path that was added to my $ PATH
            export PATH = $ PATH: / opt / android-sdk / tools
            export PATH = $ PATH: / opt / android-sdk / platform-tools
            export PATH = $ PATH: / opt / node / bin

            fabio pereira @: ~ $ echo $ PATH
            /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/android-sdk/tools:/opt/android-sdk/platform-tools:/opt/node/bin

            I don’t see what is wrong

          • Hi Fabio,

            I meant the path to your project sorry. I noticed it was in a directory that had several spaces which was causing Ant to fail. Your actual $PATH is fine.

            Regards,

  • Fábio

    As I do so for the Ant to work properly ?

    • Hi Fabio,

      In general, never use spaces in files or directories when developing. Spaces cause many negative results.

      Based on your comments, it appears my script has completed and everything is installed correctly. It appears all the current problems are from your personal configuration.

      I would change your home directory to fpereira instead of fabio pereira and make sure all your development directories contain no spaces. Example: /home/fpereira/androidproject.

  • Davidsneal

    Hi Nic,

    Thanks for the really helpful script, I’ve just run it and have finally got ionic running after much previous frustration!

    I spotted you’re using my plugin Simple Share Buttons Adder which is coincidental! As a thanks can I offer you a free copy of the Plus version? https://simplesharebuttons.com/plus/

    Thanks,

    David

  • Vamshi

    hi nic, im getting an error saying Hit http://in.archive.ubuntu.com utopic-backports/universe Translation-en
    Reading package lists… Done
    ./ubuntu_ionic_installer.sh: line 35: cd: /root/Desktop: No such file or directory
    –2015-01-11 23:54:26– http://nodejs.org/dist/v0.10.32/node-v0.10.32-linux-x64.tar.gz
    Resolving nodejs.org (nodejs.org)… 165.225.133.150
    Connecting to nodejs.org (nodejs.org)|165.225.133.150|:80… failed: Connection refused.
    –2015-01-11 23:54:27– http://dl.google.com/android/android-sdk_r23.0.2-linux.tgz
    Resolving dl.google.com (dl.google.com)… 74.125.236.198, 74.125.236.199, 74.125.236.200, …
    Connecting to dl.google.com (dl.google.com)|74.125.236.198|:80… failed: Connection refused.
    Connecting to dl.google.com (dl.google.com)|74.125.236.199|:80… failed: Connection refused.
    Connecting to dl.google.com (dl.google.com)|74.125.236.200|:80… failed: Connection refused.
    Connecting to dl.google.com (dl.google.com)|74.125.236.201|:80… failed: Connection refused.
    Connecting to dl.google.com (dl.google.com)|74.125.236.206|:80… failed: Connection refused.
    Connecting to dl.google.com (dl.google.com)|74.125.236.192|:80… failed: Connection refused.
    Connecting to dl.google.com (dl.google.com)|74.125.236.193|:80… failed: Connection refused.
    Connecting to dl.google.com (dl.google.com)|74.125.236.194|:80… failed: Connection refused.
    Connecting to dl.google.com (dl.google.com)|74.125.236.195|:80… failed: Connection refused.
    Connecting to dl.google.com (dl.google.com)|74.125.236.196|:80… failed: Connection refused.
    Connecting to dl.google.com (dl.google.com)|74.125.236.197|:80… failed: Connection refused.
    Connecting to dl.google.com (dl.google.com)|2404:6800:4007:803::1003|:80… failed: Network is unreachable.

    gzip: stdin: unexpected end of file
    tar: Child returned status 1
    tar: Error is not recoverable: exiting now

    gzip: stdin: unexpected end of file
    tar: Child returned status 1
    tar: Error is not recoverable: exiting now
    mv: cannot stat ‘android-sdk-linux’: No such file or directory
    mv: cannot stat ‘node-v0.10.32-linux-x64’: No such file or directory
    E: Unmet dependencies. Try ‘apt-get -f install’ with no packages (or specify a solution).
    chown: cannot access ‘android-sdk’: No such file or directory
    chmod: cannot access ‘android-sdk’: No such file or directory
    E: Unmet dependencies. Try ‘apt-get -f install’ with no packages (or specify a solution).
    ./ubuntu_ionic_installer.sh: line 89: npm: command not found
    ./ubuntu_ionic_installer.sh: line 90: npm: command not found
    chmod: cannot access ‘node’: No such file or directory
    ./ubuntu_ionic_installer.sh: line 95: cd: /root/Desktop: No such file or directory
    ./ubuntu_ionic_installer.sh: line 96: cd: /root/Desktop: No such file or directory

    • Looks like you’re trying to run under the root account. This is not the correct way to do it.

      Use your user account with the sudo command. You’re getting all kinds of directory related errors because they don’t exist in /root which is the home directory of your root account.

      • Vamshi

        Actually im behind a proxy protocol is there anything of such kind of a problem where i need to specify my proxy settings?

        • I don’t know much about proxies. You can always download the files manually and run each component of the script. It is pretty linear.

      • Vamshi

        here is the main error while i trying to run my user account with the sudo command.

        Reading package lists… Done
        –2015-01-12 01:12:21– http://nodejs.org/dist/v0.10.32/node-v0.10.32-linux-x64.tar.gz
        Resolving nodejs.org (nodejs.org)… 165.225.133.150
        Connecting to nodejs.org (nodejs.org)|165.225.133.150|:80… failed: Connection refused.
        –2015-01-12 01:12:22– http://dl.google.com/android/android-sdk_r23.0.2-linux.tgz
        Resolving dl.google.com (dl.google.com)… 74.125.236.193, 74.125.236.194, 74.125.236.195, …
        Connecting to dl.google.com (dl.google.com)|74.125.236.193|:80… failed: Connection refused.
        Connecting to dl.google.com (dl.google.com)|74.125.236.194|:80… failed: Connection refused.
        Connecting to dl.google.com (dl.google.com)|74.125.236.195|:80… failed: Connection refused.
        Connecting to dl.google.com (dl.google.com)|74.125.236.196|:80… failed: Connection refused.
        Connecting to dl.google.com (dl.google.com)|74.125.236.197|:80… failed: Connection refused.
        Connecting to dl.google.com (dl.google.com)|74.125.236.198|:80… failed: Connection refused.
        Connecting to dl.google.com (dl.google.com)|74.125.236.199|:80… failed: Connection refused.
        Connecting to dl.google.com (dl.google.com)|74.125.236.200|:80… failed: Connection refused.
        Connecting to dl.google.com (dl.google.com)|74.125.236.201|:80… failed: Connection refused.
        Connecting to dl.google.com (dl.google.com)|74.125.236.206|:80… failed: Connection refused.
        Connecting to dl.google.com (dl.google.com)|74.125.236.192|:80… failed: Connection refused.
        Connecting to dl.google.com (dl.google.com)|2404:6800:4007:803::1001|:80… failed: Network is unreachable.

        gzip: stdin: unexpected end of file
        tar: Child returned status 1
        tar: Error is not recoverable: exiting now

        gzip: stdin: unexpected end of file
        tar: Child returned status 1
        tar: Error is not recoverable: exiting now
        mv: cannot stat ‘android-sdk-linux’: No such file or directory
        mv: cannot stat ‘node-v0.10.32-linux-x64’: No such file or directory
        chown: cannot access ‘android-sdk’: No such file or directory
        chmod: cannot access ‘android-sdk’: No such file or directory

  • Ivan Gorshkov

    IF you run this script and have:

    – No errors
    – No response from Ionic

    Try installing nodejs-legacy:

    sudo apt-get install nodejs-legacy

    Thanks Nic 🙂

    • Thanks for sharing! Might I ask what version of Ubuntu you’re using?

      Regards,

      • Ivan Gorshkov

        14.04

        • Thanks for reporting back. It is weird that it didn’t work out of the box for that version.

  • Rajat Saxena

    Hi, I tried following the steps from Ionic’s website for 2 days but kept running into a build error. I downloaded your script and everything ran seamlessly. Still, when I build my project I get this error and I am absolutely clueless as to what might be the cause behind it.

    Total time: 36 seconds

    /home/rajat/Desktop/myApp/platforms/android/cordova/node_modules/q/q.js:126
    throw e;
    ^
    Error code 1 for command: ant with args: debug,-f,/home/rajat/Desktop/myApp/platforms/android/build.xml,-Dout.dir=ant-build,-Dgen.absolute.dir=ant-gen
    ERROR building one of the platforms: Error: /home/rajat/Desktop/myApp/platforms/android/cordova/build: Command failed with exit code 1
    You may not have the required environment or OS to build this project

    I am on the verge of giving up on Ionic Framework :/

    Edit:
    I am using Ubuntu 14.04 on 64-bit.

    • The script can’t do everything. Did you install the appropriate Android targets after running the script? Had you undone all the things the previous tutorials had you do? If you left what my script did and what you had done previously, there could be confusion since my script does not offer clean up of faulty installs.

      Also run the following and tell me what they say:

      Your error is more than likely not an issue with Ionic Framework. More probably an issue with Android or Cordova.

      Regards,

      • Hi Nic,

        I did install the Android targets and undid everything from the previous configurations.

        Here’s the result:

        [email protected]:~$ ant -version
        Apache Ant(TM) version 1.9.3 compiled on April 8 2014
        [email protected]:~$ cordova -v
        4.2.0
        [email protected]:~$ ionic -v
        1.3.11
        [email protected]:~$ npm -v
        2.5.1
        [email protected]:~$ android list target

        Available Android targets:

        id: 1 or “android-17”
        Name: Android 4.2.2
        Type: Platform
        API level: 17
        Revision: 3
        Skins: QVGA, WQVGA400, WXGA800, WXGA720, HVGA, WSVGA, WVGA800 (default), WXGA800-7in, WQVGA432, WVGA854

        Tag/ABIs : no ABIs.

        id: 2 or “android-19”
        Name: Android 4.4.2
        Type: Platform
        API level: 19
        Revision: 4
        Skins: QVGA, WQVGA400, WXGA800, WXGA720, HVGA, WSVGA, WVGA800 (default), WXGA800-7in, WQVGA432, WVGA854
        Tag/ABIs : no ABIs.

        So I’m guessing this part is good.

        Also, the error I am getting is due to this:
        ….
        [apkbuilder] keytool error: java.io.FileNotFoundException: /home/rajat/.android/debug.keystore (Permission denied)

        ….

        BUILD FAILED
        /opt/android-sdk/tools/ant/build.xml:962: The following error occurred while executing this line:
        /opt/android-sdk/tools/ant/build.xml:973: The following error occurred while executing this line:
        /opt/android-sdk/tools/ant/build.xml:312: com.android.sdklib.build.ApkCreationException: Unable to get debug signature key

        I tried accessing my .android folder but it is locked and I can’t access it. Maybe that’s why even Ionic couldn’t and hence the error. Any clues?

        Thanks.

        • Yea the keystore error is a permission issue. Just change the permissions to 777 or something. Might have been botched in your previous installation.

          What command are you trying to run when you get all these errors?

          Regards,

          • Yes this was the problem. I had to go into root and changed ownership of the folder (it was a little tricky because it was a hidden folder).

            So I changed the ownership of .android to my user and I could build successfully.

            Thank you! 🙂

          • Glad I could help 🙂

  • Hi Nic,

    Thanks for sharing the awesome script and instructions. This save my day.
    For 64 bit build, you may want to add:

    Add i386 architecture before running apt-get update

    if [ “$LINUX_ARCH” == “x86_64” ]; then
    dpkg –add-architecture i386
    fi

    Just before “apt-get update” around Line 30…otherwise, apt-get install *:i386 may fail.
    What do you think?

    • That might be useful, but have you experienced a situation where apt-get install *:i386 failed? I’ve not run into one yet, but I’m not confirming that it cannot happen.

      In any case, thanks for your input!

      Regards,

      • Thanks for the quick reply. Yes, I installed on fresh image of Ubuntu Server 14.04 LTS (HVM) AMI on AWS, and our script for “npr install” did not go through, so I started to research. I found this discussion:
        http://askubuntu.com/questions/551840/unable-to-locate-package-libc6-dbgi386-in-docker
        and recalled that your script had *:i-386 apt-get installs, so I tried dpkg -add-architecture i386 then everything went fine.

        • Ah, I didn’t even think about services like AWS and Docker that might be using custom Ubuntu images.

          Would you like to fork the repository and make a pull request so you get credit? Otherwise, I’ll add it.

          Regards,

          • Oops, I did not realize that your script was hosted on github. I will make a pull request shortly. Thanks.

          • No worries. Thought I’d offer to let you do it. Didn’t want to rob you of the credit of your good find 🙂

  • webcok

    Hi, i follow instructions and used script you made. Everthing was fine , but when i tried to create a project using “ionic start ExampleProject” it gave an error like that

    Fetching plugin “org.apache.cordova.device” via plugin registry
    Error: EACCES, mkdir ‘/home/fatih/tmp/npm-7243-bJuWSl_F’
    Unable to add plugins. Perhaps your version of Cordova is too old. Try updating (npm install -g cordova), removing this project folder, and trying again. (CLI v1.3.13)

    Your system information:

    OS: Distributor ID: Ubuntu Description: Ubuntu 14.04.2 LTS
    Node Version: v0.10.32
    Cordova CLI: 4.3.0
    Ionic Version: 1.0.0-rc.0
    Ionic CLI Version: 1.3.13

    While i was intalling android packages i intalled both 21 and 19 can this cause that error? What could possibly cause that problem ?

    • Sounds like you’re having a permission issue.

      Can you run the following:

      Once in the past my tmp folder got messed up during an update.

      Regards,

      • webcok

        It worked. Thank you very much for both your script and your quick answer.

        I would like to ask one last question. Is there a possibility that giving all permissions to tmp directory can lead to some security problems?

        • You should be fine.

          You could also delete the tmp directory and let NPM recreate it for you with the correct permissions.

          Regards,

          • webcok

            Thank you very much.

            Have a nice day sir.

      • umesh

        i enter this command but am getting this msg
        chmod: cannot access ‘/home/fatih/tmp’: No such file or directory

        • I answered your question on YouTube too. Try deleting the directory if it exists, or creating it with 777 permissions if it doesn’t exist.

          The tmp directory is required for NPM and Cordova commands. If it can’t be created or has incorrect permissions, those commands will fail.

          Regards,

  • simone

    Hi Nic,
    Thanks for the script and the video.
    I take advantage of your knowledge to ask you a question. I try to find an answer googling around but every post I’ve read confused me more. I would like to develop an app that work both on Android and iOS. Unfortunately I have not a mac. From the overview of Cordova I got that is that I could do this only with a mac. My question is: can I develop my app for Android firstly and than, maybe borrowing a mac, export the app on iOS?
    Thanks,
    Simone

    • Yep, that is the joys of Apache Cordova and I do it all the time.

      Pick a computer you want to develop on. Then when you’re ready to build for iOS, find someone with a Mac and give them your project. Of course you’ll need to first configure all of the Apple certificates on their computer, but that isn’t so bad.

  • Kamaro Lambert

    After running the script I got this error while try to build android [Error: ANDROID_HOME is not set and “android” command not in your PATH. You must fulfill at least one of these conditions.]

    Can you please help me ?

    • Sounds like you might be trying to run various commands using sudo. The current user and sudo both have different PATH variables set up which would probably explain your error.

      Can you give me more information so I can help you better?

      Regards,

      • Kamaro Lambert

        below are more info

        [email protected]:~/projects/mobile/sidemenu$ ionic build android
        Adding in default Ionic hooks
        Running command: /home/kamaro/projects/mobile/sidemenu/hooks/after_prepare/010_add_platform_class.js /home/kamaro/projects/mobile/sidemenu
        add to body class: platform-android
        Running command: /home/kamaro/projects/mobile/sidemenu/hooks/after_prepare/020_remove_sass_from_platforms.js /home/kamaro/projects/mobile/sidemenu
        Running command: /home/kamaro/projects/mobile/sidemenu/platforms/android/cordova/build
        [Error: Please install Android target: "android-21".

        Hint: Open the SDK manager by running: /opt/android-sdk/tools/android
        You will require:
        1. "SDK Platform" for android-21
        2. "Android SDK Platform-tools (latest)
        3. "Android SDK Build-tools" (latest)]
        ERROR building one of the platforms: Error: /home/kamaro/projects/mobile/sidemenu/platforms/android/cordova/build: Command failed with exit code 2
        You may not have the required environment or OS to build this project
        Error: /home/kamaro/projects/mobile/sidemenu/platforms/android/cordova/build: Command failed with exit code 2
        at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:131:23)
        at ChildProcess.EventEmitter.emit (events.js:98:17)
        at maybeClose (child_process.js:743:16)
        at Process.ChildProcess._handle.onexit (child_process.js:810:5)

        • Looks like it is telling you to install android-21.

          After you do that, circle back and let me know.

          Regards,

    • Stoicuta Alexandru

      Try moving the android-sdk folder outside from the opt folder and into the home folder. If ANDROID_HOME is not set, cordova will search for it in home/android-sdk.

      maybeSetAndroidHome(path.join(process.env[‘HOME’], ‘android-sdk’)); – from APP/platforms/android/cordova/lib/check_reqs.js line 180.

  • Nitish

    events.js:72

    Error: spawn EACCES

    after running ionic build android

    • Sounds like it is a permission issue. Can you check the permissions on the Android SDK directory? Make sure the permissions are recursive on it.

      • Nitish

        sir , gave all the permissions to android sdk . i am working on root

        • I believe that is your problem. The ‘root’ user account does not act like the rest. I built the script around regular user accounts.

          Regards,

    • wambe

      The “Error: spawn EACCES” can come from a forgotten shebang.
      For nodejs, the first line in an unix-like box could be:

      #!/usr/bin/env node

  • Mahesh Kumar K R

    Hi Nic,

    Wow thanks for this perfect script, have been getting “cb() never called” error till now, this script saved me.

    Thanks,
    Mahesh

    • No problem! Glad I could help 🙂

  • hamid

    Hello.i wanna run this cmd i linux ubunto12 server:

    ionic build android

    but when i run this,it error is shown :

    [email protected]:~/tmp# ionic build android

    Updated the hooks directory to have execute permissions

    Running command: /root/tmp/hooks/after_prepare/010_add_platform_class.js /root/tmp

    add to body class: platform-android

    Running command: /root/tmp/platforms/android/cordova/build

    ANDROID_HOME=/root/sdk-dir/android-sdk-linux

    JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64

    Running: /root/tmp/platforms/android/gradlew cdvBuildDebug -b /root/tmp/platforms/android/build.gradle -Dorg.gradle.daemon=true

    FAILURE: Build failed with an exception.

    Where:

    Script ‘/root/tmp/platforms/android/CordovaLib/cordova.gradle’ line: 64

    What went wrong:

    A problem occurred evaluating root project ‘android’.

    No installed build tools found. Please install the Android build tools version 19.1.0 or higher.

    Try:

    Run with –stacktrace option to get the stack trace. Run with –info or –debug option to get more log output.

    BUILD FAILED

    Total time: 1.859 secs

    /root/tmp/platforms/android/cordova/node_modules/q/q.js:126

    Error code 1 for command: /root/tmp/platforms/android/gradlew with args: cdvBuildDebug,-b,/root/tmp/platforms/android/build.gradle,-Dorg.gradle.daemon=true

    ERROR building one of the platforms: Error: /root/tmp/platforms/android/cordova/build: Command failed with exit code 8

    You may not have the required environment or OS to build this project

    Error: /root/tmp/platforms/android/cordova/build: Command failed with exit code 8

    • Do not run the script as the root user. It will not work.

      Use sudo to run it as any other user.

      Regards,

      • hamid

        please say me more clear dear Nic 🙂
        what should i do?say more for me.explain plesae

        Regards Hamid

        • Create a user account on your server. Give it sudo access. Sign into the new user account and run the script with sudo.

          I encourage reading up on Linux if you’re unfamiliar with the commands necessary.

          Regards,

          • hamid

            i build a user and give his sudo access,but user can’t access projects file for build android file with cmd (ionic build android)
            please explain for me more 🙂

            Regards

          • I’m not sure how I can explain this further. Did you watch my video on the subject? I walk through every step in the video.

            I suggest you do some research on Linux or use a different platform (Mac or Windows) as it sounds like your issues are not related to my script.

            Regards,

          • hamid

            ok,i check yout video and test it in other platforms like mac or win.but in linux i can’t get result(ionic build android)
            can you solve this problem in my server??
            i work with this problem 4 days,but i doesn’t solve this problem.
            can i send server details for you and you check?
            please help me

            Regards
            Hamid

          • Sorry I cannot help you any further. Do research on Linux. It sounds like you are very unfamiliar with it. The video shows 100% start to finish without any loose ends.

            Best of luck,

  • Thanks!

    • No problem!

      • Haven’t got around to IOS yet, but does anyone know of a similar script for when I get there =D

        • It is not difficult to get set up with Android and Apache Cordova with a Mac. You shouldn’t need a script. Just remember though that you can only build iOS applications with a Mac and nothing else.

          Regards,

  • Ankit Dahiya

    Hi Nic,
    Thanks for the helpful shell script, After it’s installation , I am getting some error . I have posted a question on stack here
    http://stackoverflow.com/questions/30952795/when-using-the-command-cordova-build-android-i-am-getting-the-following-erro
    I really hope you can help

    • That is a permission related error. Did you use sudo? Did you run the script under your ankit user account and not root? What command are you running to generate that error as it isn’t in that stackoverflow thread?

      Any information you can provide would be great. Right now you’re very vague.

      Regards,

  • sulistyo_x

    hi nic thanks for this script , but find error when the prosess installing cordova and ionic
    this

    • Weird!

      Not sure why Ripple Emulator is being installed with Cordova. Are you doing something extra that you haven’t mentioned? Were you trying to run the script on top of an existing installation?

      What further info can you give me?

      Regards,

  • windong

    Hi Nic, so thankful for this tutorial.
    I got an error [Error: Please install Android target: “android-22]. How can i resolve this?

    Thanks.

  • windong

    Hi Nic,
    I get some erros while i ran this command “ionic build android” error says: Unknown platforms: adroid

    • Sounds like you didn’t install your Android platforms. As mentioned in the tutorial, the script cannot download the necessary Android SDK tools for you. You still need to open the SDK manager and download the items necessary for building Ionic apps.

      Regards,

  • Jorge Cacho

    I was desperate using other guides … This script has done the installation seamlessly on Ubuntu 15.04. Thanks!!!

    • I’m glad you found it useful. Also, thanks for confirming it works in 15.04.

      Best,

  • Ken

    Hi – Great script. Do you have a Vagrant file for Ubuntu and how do I get a GUI version of Ubuntu so android can run? I am getting this error when I run android and the command line:

    [email protected]:~$ android

    Exception in thread “main” org.eclipse.swt.SWTError: No more handles [gtk_init_check() failed]

    • I don’t know if I’d run this with Vagrant. You’re probably going to get errors including the ones you’re already getting. This script was intended for sandboxed virtual machines like VMWare, Virtual Box, or Parallels. It was also intended for host installs of Ubuntu (primary operating system).

      Sorry,

  • Muhammad Ahsan

    Getting this error: Could not find or load main class com.android.sdkmanager.Main
    When I restart my ubuntu session and entered “android” to download the necessary Android targets.
    Any help?

    • I’ve not seen that error before. Can you give me more information:

      What version of Ubuntu are you using?
      What architecture of Ubuntu are you using?
      Are you running “android” with or without “sudo”?
      What account did you run the script as (root, mahsan, etc.)?

      Regards,

      • Muhammad Ahsan

        Thank you Nic for your acknowledgement.

        Ubuntu version: 12.04
        OS Type: 64bit
        Without “sudo”
        Yes, I’m running this from root.

        • Two things:

          You cannot do this from the root account. You must do this from a user account that has sudo
          Ubuntu 12.04 is ancient. My guess is it might not have all the necessary dependencies to work on that version.

          Regards,

  • kumar

    hi Hic,
    I’m using xubuntu 14.04 , facing this error when trying to build android on a project with

    sudo ionic build android

    but i’m getting erorr like following

    [Error: Failed to find ‘ANDROID_HOME’ environment variable. Try setting setting it manually.
    Failed to find ‘android’ command in your ‘PATH’. Try update your ‘PATH’ to include path to valid SDK directory.]
    ERROR building one of the platforms: Error: /home/kumar/myapp1/platforms/android/cordova/build: Command failed with exit code 2
    You may not have the required environment or OS to build this project
    Error: /home/kumar/myapp1/platforms/android/cordova/build: Command failed with exit code 2
    at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:139:23)
    at emitTwo (events.js:87:13)
    at ChildProcess.emit (events.js:172:7)
    at maybeClose (internal/child_process.js:817:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)

    • Try not using sudo. The script didn’t install things to your sudo $PATH, it installed things to your user $PATH.

      Regards,

      • kumar

        which means should i execute this script without ‘sudo’ ?

        like this ./ubuntu_ionic_installer.sh

        • You need to install the script with sudo because it needs to access protected directories. I am saying don’t use sudo when trying to use Ionic or Android.

          Can you just run:

          ionic start MyProject blank

          No sudo in that.

          Regards,

          • kumar

            yeah i ran that way

            ionic start myapp3 blank

            which created a project and i can view it in my browser with

            $ ionic serve but there’s an error like this happened when i used ‘start’ and ‘serve’

            Unable to save ionic data: /home/kumar/.ionic/ionic.config Error: EACCES: permission denied, open ‘/home/kumar/.ionic/ionic.config’

            but it got opened successfully in browser.

            but for adding android to this project i used

            [email protected]:~/myapp3$ cordova platform add android

            it gave me error like this

            Failed to fetch platform android
            Probably this is either a connection problem, or platform spec is incorrect.
            Check your connection and platform name/version/URL.
            Error: EACCES: permission denied, open ‘/home/kumar/.cordova/lib/npm_cache/cordova-android/4.1.1/package/.npmignore’

            so i tried it with sudo like this

            sudo cordova platform add android

            and then i ran sudo ionic build android which gave me the same error

            again

            [Error: Failed to find ‘ANDROID_HOME’ environment variable. Try setting setting it manually.
            Failed to find ‘android’ command in your ‘PATH’. Try update your ‘PATH’ to include path to valid SDK directory.]
            ERROR building one of the platforms: Error: /home/kumar/myapp1/platforms/android/cordova/build: Command failed with exit code 2
            You may not have the required environment or OS to build this project
            Error: /home/kumar/myapp1/platforms/android/cordova/build: Command failed with exit code 2
            at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:139:23)
            at emitTwo (events.js:87:13)
            at ChildProcess.emit (events.js:172:7)
            at maybeClose (internal/child_process.js:817:16)
            at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)

          • Did you install the script with the kumar account or did you use root? The script must be installed from the kumar account like so:

            sudo ./ubuntu_ionic_installer.sh

            After you install everything you need to launch Android and install the platform tools and images. This must be done from your kumar account WITHOUT the sudo command.

            My guess is somewhere along the road you may have used the wrong command sudo or not sudo. You might try uninstalling what the script did for you, or changing the permissions to something more open on the directories that are complaining.

            sudo chmod -R 755 /home/kumar/.cordova

            That might do the trick.

            Regards,

  • Basu S

    Hi NIC RABOY,

    Great scrip, was very helpful. Thanks a lot

  • Basu S

    Hi NIC,
    Getting debug build. How to get build which I can upload to playstore.
    Will playstore allow to upload debug build?

    • For compiling a release build see here:

      http://ionicframework.com/docs/guide/publishing.html

      Regards,

      • Basu S

        Thanks a lot.
        will try with this.

      • Basu S

        [Storing my-release-key.keystore]

        [email protected]:~/Desktop/ionic/myApp$ jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore android-release-unsigned.apk alias_name

        Enter Passphrase for keystore:

        jarsigner: unable to open jar file: android-release-unsigned.apk

        How to resolve this
        Sorry and Thanks

  • Basu S

    [Storing my-release-key.keystore]

    [email protected]:~/Desktop/ionic/myApp$ jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore android-release-unsigned.apk alias_name

    Enter Passphrase for keystore:

    jarsigner: unable to open jar file: android-release-unsigned.apk

    How to resolve this?

    Sorry and Thanks

    • Because application signing is not part of this article, I’m going to have to defer you to the forums. I want to try to keep the comments on topic to the post.

      Sorry,

  • Halil İbrahim Özdoğan

    Thanks a lot man

  • RK

    Thanks for plugin. Could you please help I am stuck in a issue. When I executed ionic build android I am getting this “[Error: Please install Android target: “android-22″.” I dont know what does it means.

    • You need to open the Android SDK Manager and install API 22 like it is requesting.

      • RK

        Thanks man it worked.

  • Bayu Bimantara

    Thanks! 🙂

  • Christ Noel

    thanks Nic, when i’ve told you since 2 weeks i’m trying to install Install Android, Apache Cordova, and Ionic Framework in Ubuntu 15.05.

    But it’s not done successfully because of theses errors

    npm ERR! Linux 3.19.0-30-generic
    npm ERR! argv “/opt/node/bin/node” “/opt/node/bin/npm” “install” “-g” “ionic”
    npm ERR! node v0.12.2
    npm ERR! npm v2.7.4
    npm ERR! code ELIFECYCLE

    npm ERR! [email protected] postinstall: node postinstall
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the [email protected] postinstall script ‘node postinstall’.
    npm ERR! This is most likely a problem with the spawn-sync package,
    npm ERR! not with npm itself.
    npm ERR! Tell the author that this fails on your system:
    npm ERR! node postinstall
    npm ERR! You can get their info via:
    npm ERR! npm owner ls spawn-sync
    npm ERR! There is likely additional logging output above.

    npm ERR! Please include the following file with any support request:
    npm ERR! /home/christ/npm-debug.log
    ./ubuntu_ionic_installer.sh: ligne 100 : cd: /home/christ/Desktop: Aucun fichier ou dossier de ce type
    ./ubuntu_ionic_installer.sh: ligne 101 : cd: /home/christ/Desktop: Aucun fichier ou dossier de ce type

    How can i fix it without reinstalling my OS please?!

    • Did you run the script with sudo?

      • Christ Noel

        yes i do

        • Christ Noel

          i did sorry

      • Christ Noel

        yes i did it

      • Christ Noel

        i did it again always with sudo but always the same errors

        • Are you absolutely sure those are all of the errors? I get the feeling you’ve not pasted all of them.

          • Christ Noel

            ok wait for a momment please i’m trying again and will paste you all errors

          • Christ Noel

            these are all errors

            ./ubuntu_ionic_installer.sh: ligne 40 : cd: /home/christ/Desktop: Aucun fichier ou dossier de ce type
            –2015-10-20 19:25:13– http://nodejs.org/dist/v0.12.2/node-v0.12.2-linux-x64.tar.gz
            Résolution de nodejs.org (nodejs.org)… 104.20.23.46, 104.20.22.46, 2400:cb00:2048:1::6814:172e, …
            Connexion à nodejs.org (nodejs.org)|104.20.23.46|:80… connecté.
            requête HTTP transmise, en attente de la réponse… 200 OK
            Taille : 9487774 (9,0M) [application/gzip]
            Enregistre : «nodejs.tgz»

            nodejs.tgz 100%[=====================>] 9,05M 412KB/s ds 54s

            2015-10-20 19:26:08 (170 KB/s) – «nodejs.tgz» enregistré [9487774/9487774]

            –2015-10-20 19:26:08– http://dl.google.com/android/android-sdk_r24.2-linux.tgz
            Résolution de dl.google.com (dl.google.com)… 173.194.67.93, 173.194.67.136, 173.194.67.190, …
            Connexion à dl.google.com (dl.google.com)|173.194.67.93|:80… connecté.
            requête HTTP transmise, en attente de la réponse… 200 OK
            Taille : 168119905 (160M) [application/x-tar]
            Enregistre : «android-sdk.tgz»

            android-sdk.tgz 100%[=====================>] 160,33M 389KB/s ds 6m 58s

            2015-10-20 19:33:06 (393 KB/s) – «android-sdk.tgz» enregistré [168119905/168119905]

            mv: impossible to move «android-sdk-linux» vers «android-sdk/android-sdk-linux»: the folder is not empty
            mv: impossible to move «node-v0.12.2-linux-x64» vers «node/node-v0.12.2-linux-x64»: the folder is not empty
            npm WARN engine [email protected]: wanted: {“node”:”0.8.x || 0.10.x”} (current: {“node”:”0.12.2″,”npm”:”2.7.4″})
            /opt/node/bin/cordova -> /opt/node/lib/node_modules/cordova/bin/cordova
            [email protected] /opt/node/lib/node_modules/cordova
            ├── [email protected]
            ├── [email protected]
            ├── [email protected] ([email protected])
            └── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected].0, [email protected], [email protected], [email protected], [email protected].8, [email protected], [email protected])

            [email protected] postinstall /opt/node/lib/node_modules/ionic/node_modules/ionic-app-lib/node_modules/cross-spawn/node_modules/spawn-sync
            node postinstall

            [email protected] install /opt/node/lib/node_modules/ionic/node_modules/ionic-app-lib/node_modules/node-sass
            node scripts/install.js

            npm WARN engine [email protected]: wanted: {“node”:”~0.10.x”} (current: {“node”:”0.12.2″,”npm”:”2.7.4″})
            npm WARN engine [email protected]: wanted: {“node”:”0.8.x || 0.10.x”} (current: {“node”:”0.12.2″,”npm”:”2.7.4″})
            npm ERR! Linux 3.19.0-30-generic
            npm ERR! argv “/opt/node/bin/node” “/opt/node/bin/npm” “install” “-g” “ionic”
            npm ERR! node v0.12.2
            npm ERR! npm v2.7.4
            npm ERR! code ELIFECYCLE

            npm ERR! [email protected] postinstall: node postinstall
            npm ERR! Exit status 1
            npm ERR!
            npm ERR! Failed at the [email protected] postinstall script ‘node postinstall’.
            npm ERR! This is most likely a problem with the spawn-sync package,
            npm ERR! not with npm itself.
            npm ERR! Tell the author that this fails on your system:
            npm ERR! node postinstall
            npm ERR! You can get their info via:
            npm ERR! npm owner ls spawn-sync
            npm ERR! There is likely additional logging output above.

            npm ERR! Please include the following file with any support request:
            npm ERR! /home/christ/npm-debug.log
            ./ubuntu_ionic_installer.sh: ligne 100 : cd: /home/christ/Desktop: file or folder missing

            ./ubuntu_ionic_installer.sh: ligne 101 : cd: /home/christ/Desktop:file or folder missing

          • What happens if you run the following:

            node -v
            npm -v
            ionic -v
            cordova -v

            Just want to see if maybe they installed.

          • Christ Noel

            ~$ node -v
            ~$ npm -v
            2.7.4
            ~$ ionic -v
            command « ionic » unfound, would you like :
            command « ionice » from paquage « util-linux » (main)
            command « ironic » from paquage « python-ironicclient » (main)
            commande « sonic » from paquage « sonic » (universe)
            ionic : command unfound
            ~$ cordova -v
            ~$

          • Christ Noel

            ~$ node -v
            nothing

            ~$ npm -v
            2.7.4
            ~$ ionic -v
            command « ionic » unfound, would you like :
            command « ionice » from package « util-linux » (main)
            command « ironic » from package « python-ironicclient » (main)
            commande « sonic » from package « sonic » (universe)
            ionic : command unfound
            ~$ cordova -v
            ~$nothing

          • It is weird that it failed. Never seen it happen before.

            You might try downloading the latest Node.js from the official Node.js website and installing that. My guess is everything except for Node installed correctly.

            After you install the most recent version of Node, try to install Ionic and Cordova.

            You don’t need to uninstall anything.

          • Christ Noel

            ok thanks i’ll tell you it’s work

          • Christ Noel

            hi and thanks Nic it’s done i have installed them !!!

          • Christ Noel

            [email protected]:~$ node -v
            v4.2.1
            [email protected]:~$ npm -v
            2.14.7
            [email protected]:~$ ionic -v
            1.7.7

            [email protected]:~$ cordova -v
            5.3.3
            [email protected]:~$

          • Awesome!

            No idea why it didn’t work the first time with my script, but it looks like you should be good now 🙂

          • Christ Noel

            me too i’d like to know, but now i can start my first app so i’ll write you if i want to know somothing thanks again for your help

      • Christ Noel

        yes i did

      • Christ Noel

        but i want to uninstall all files installed by executing sudo ./ubuntu_ionic_installer.sh how can i do it please?!

  • Drss

    thank you man 🙂

  • Aravind S

    Nic,
    Excellent job! I had no trouble in setting up the environment. However, if I run ‘Ionic build’ or ‘Ionic run’ its just not working. No error. Nothing. Can you help?

    • You’re not using an uppercase “i” in ionic are you?

      If there was a problem you should get an error. Can you add a screenshot of your terminal right after you run one of those commands, including the command itself in the screenshot?

      Best,

  • Arun D Nambissan

    I completed installing all the required packages and tools. But I am getting the following error when I am using the “ionic build android” command. Please help me out to solve this issue

    [email protected]:~/test10$ ionic build android

    Running command: /home/arun/test10/hooks/after_prepare/010_add_platform_class.js /home/arun/test10

    add to body class: platform-android

    Running command: /home/arun/test10/platforms/android/cordova/build

    ANDROID_HOME=/opt/android-sdk

    JAVA_HOME=/usr/lib/jvm/default-java

    Running: /home/arun/test10/platforms/android/gradlew cdvBuildDebug -b /home/arun/test10/platforms/android/build.gradle -Dorg.gradle.daemon=true

    Deleting directory /home/arun/.gradle/wrapper/dists/gradle-2.2.1-all/2m8005s69iu8v0oiejfej094b/gradle-2.2.1

    Unzipping /home/arun/.gradle/wrapper/dists/gradle-2.2.1-all/2m8005s69iu8v0oiejfej094b/gradle-2.2.1-all.zip to /home/arun/.gradle/wrapper/dists/gradle-2.2.1-all/2m8005s69iu8v0oiejfej094b

    Exception in thread “main” java.lang.RuntimeException: java.util.zip.ZipException: invalid distance code

    Caused by: java.util.zip.ZipException: invalid distance code

    /home/arun/test10/platforms/android/cordova/node_modules/q/q.js:126

    Error code 1 for command: /home/arun/test10/platforms/android/gradlew with args: cdvBuildDebug,-b,/home/arun/test10/platforms/android/build.gradle,-Dorg.gradle.daemon=true

    ERROR building one of the platforms: Error: /home/arun/test10/platforms/android/cordova/build: Command failed with exit code 1

    You may not have the required environment or OS to build this project

    Error: /home/arun/test10/platforms/android/cordova/build: Command failed with exit code 1

  • DotSlashAttack

    Excellent script, Nic! I found this while trying to get the Android SDK installed for eclipse – forgot all about Ionic! lol

  • Osyounes

    thanks ..

    i have this error when i am trying to build

    [Error: Failed to find ‘ANDROID_HOME’ environment variable. Try setting setting it manually.
    Failed to find ‘android’ command in your ‘PATH’. Try update your ‘PATH’ to include path to valid SDK directory.]

    • Full logs please.

      • Osyounes

        thanks for replay

        this is the full messages

        • You have permission errors. My guess is that you tried to run the script as root rather than sudo. When running the script you have to run it as your user account using sudo.

          Regards,

          • Osyounes

            thank’s for reply

            the same problem

          • Did you undo all the changes that were made the first time you ran the script incorrectly?

          • Osyounes

            every thing work correctly
            but when i try to build the android app give me this error message

            i do not know what i have to do to build the android

          • Osyounes

            i am trying to run
            the same problem

            and i am truing using ionic Lab

          • Tom Gruintjes

            Same problem for me. I can run android smoothly out of the terminal, and still Cordova complains about path (including android_home). Does it import the variables as set in .profile?
            Downloading and installing all the time makes it a bit of a hassle..

          • What user account did you install the script under?

          • Tom Gruintjes

            Dear Nic, Sorry for giving minimal information. And thanx for the script. It is just so annoying things don’t work out after such a long time and my hopes where high (like a small child waiting for a present).

            Anyway, I have one account setup on the Ubuntu 14 distribution (called tom) which is a sudoer. I used sudo to do the installation. /opt/has the android stuff as well as ~/Android/Sdk. In despair I added many paths in .profile. And echo $PATH or $ANDROID_HOME gives positive results in terminal. I can run android out of the prompt. Besides dropping a line here, I will search through the cordova forum. And maybe even try to put a PATH statement or something in the cordova scripts to force-find. I am wondering which programs of android cordova is looking for? Anyway, thanks for the reply and hope it will give some inspiration for a direction.

            I run ionic CLI through sudo (sudo ionic build android)

          • Why is the Android SDK at ~/Android/Sdk? The script should have placed it at /opt/android-sdk.

            This leads me to believe you maybe had a botched setup before running the script? In any case, you should probably check all the directory permissions. In your ~/ directory you want to make sure your “tom” user is on all the directories, not root.

            Best,

          • Tom Gruintjes

            Hi

            I sudo rm -R all directories in /opt and ~/ related to android (android-sdk and Android). I removed PATH and JDK entries in .profile as created by the script. Then I reran the script as sudo (sudo ), rebooted (which I didnt do before, maybe explaining ~/Android), ran android and installed API 19 besides many other stuff recommended. Ran sudo ionic commands to install a blank project. sudo ionic platform add android. And then hoped for some magic while running sudo ionic build android…….

            [email protected]:~/test/exampleproject$ sudo ionic build android

            Running command: /home/tom/test/exampleproject/hooks/after_prepare/010_add_platform_class.js /home/tom/test/exampleproject

            add to body class: platform-android

            Running command: /home/tom/test/exampleproject/platforms/android/cordova/build

            [Error: Failed to find ‘ANDROID_HOME’ environment variable. Try setting setting it manually.

            Failed to find ‘android’ command in your ‘PATH’. Try update your ‘PATH’ to include path to valid SDK directory.]

            ERROR building one of the platforms: Error: /home/tom/test/exampleproject/platforms/android/cordova/build: Command failed with exit code 2

            You may not have the required environment or OS to build this project

            Error: /home/tom/test/exampleproject/platforms/android/cordova/build: Command failed with exit code 2

            Still having high hopes here… 🙂

          • If you’re using sudo to run ionic commands you’re doing it wrong.

            Best,

          • Tom Gruintjes

            Hi
            valid point. Doesnt feel right running sudo all the time. But running out of user tom gives me permission errors on some files in .config (owned by root) and ./cordove (owned by dialout?!!?).

            Will continue to change permissions and ownership of these files and see how it works

            Tom

          • Nothing in your home directory should have an owner other than the user that defaults to that directory. If I were you I’d scrap everything and start over.

          • Tom Gruintjes

            Hi Nic

            Thanx. I wasn’t aware of these .named directories being so important, so indeed, best would be to scrap the whole installation (of Ubuntu) and redo. I think there were some leftovers from earlier attempts and other experiments. Also, I am likely to have installed node incorrectly before beacuse I always need to sudo npm install , but no sudo needed for all other npm commands.

            Anyway, with changing the ownership of directories .config, .ionic etc all is now actually working and have deployed succesfully an APK into a virtual device.

            So thanks for the help, patience, the script. I am now off into to exciting journey of Ionic2 app development!

            Regards,

            Tom

          • Awesome, I’m glad you got everything squared away 🙂

          • Bharath

            Hi, How to run without sudo in my mechine, kindly help me to resolve this.

          • hari krishnan

            Hello Nic, I cant buil ionic project without sudo. It shows “Error: EACCES: permission denied”. And when i run it with sudo like “ionic build android” then it says “Failed to find ‘ANDROID_HOME’ environment variable”. Can u please help?

          • @disqus_q530berDII:disqus,

            You posted the same question two times in the same day. Doing this is against my rules. I’m a busy person and cannot answer all questions immediately.

            I posted this link on your other comment, but this time you are violating #2:

            https://www.thepolyglotdeveloper.com/2015/10/how-to-get-programming-help-in-forums-and-on-my-blog/

            You’ve been warned. If it happens again, you won’t get further help from me.

            Regards,

  • Sanal S

    Hi Nic,
    I have this error when i am trying to build

    Error: Could not find gradle wrapper within Android SDK. Might need to update your Android SDK.
    Looked here: /opt/android-sdk/tools/tools/templates/gradle/wrapper

  • Dronca Raul

    Hi Nic,

    How can I uninstall everything?

    • There is no automated uninstall with this script. You would have to go through each of the steps that this script did and revert them manually.

      This is why I encouraged everyone to read the blog post rather than just blindly running the script file.

      Best,

  • Nic, thanks so much for this scrip, it helped a whole heap to get up and running.
    Although I have enhanced this script a little to get it up to date. If you don’t mind I will be adding a post to my blog with the enhancements I’ve made.
    I will include a link to your orginal post and clearly state and attribute yoru post where needs be.

    Your blog is helping me immensely on my journey through ionic! thanks

  • baranyizigiye kevin

    HI nic,I am facing a problem

    HI nic,I am facing a problem
    could you please help
    [email protected]:~$ node -v
    v0.10.25
    [email protected]:~$ npm -v
    1.3.10
    [email protected]:~$ ionic -v
    module.js:327
    throw err;
    ^

    Error: Cannot find module ‘xmlbuilder’
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object. (/usr/local/lib/node_modules/ionic/node_modules/xml2js/lib/xml2js.js:12:13)
    at Object. (/usr/local/lib/node_modules/ionic/node_modules/xml2js/lib/xml2js.js:436:4)
    at Module._compile (module.js:397:26)
    at Object.Module._extensions..js (module.js:404:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)

    [email protected]:~$ cordova -v
    module.js:327
    throw err;
    ^

    Error: Cannot find module ‘bplist-parser’
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)

    (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/cordova-common/src/ConfigChanges/ConfigFile.js:20:14)
    at Module._compile (module.js:397:26)
    at Object.Module._extensions..js (module.js:404:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    [email protected]:~$

    could you please help
    [email protected]:~$ node -v
    v0.10.25
    [email protected]:~$ npm -v
    1.3.10
    [email protected]:~$ ionic -v
    module.js:327
    throw err;
    ^

    Error: Cannot find module ‘xmlbuilder’
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object. (/usr/local/lib/node_modules/ionic/node_modules/xml2js/lib/xml2js.js:12:13)
    at Object. (/usr/local/lib/node_modules/ionic/node_modules/xml2js/lib/xml2js.js:436:4)
    at Module._compile (module.js:397:26)
    at Object.Module._extensions..js (module.js:404:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)

    [email protected]:~$ cordova -v
    module.js:327
    throw err;
    ^

    Error: Cannot find module ‘bplist-parser’
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)

    (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/cordova-common/src/ConfigChanges/ConfigFile.js:20:14)
    at Module._compile (module.js:397:26)
    at Object.Module._extensions..js (module.js:404:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    [email protected]:~$

    • You probably want to use a version of Node more recent than 0.10.x. This blog post is old, but I keep the GitHub script up to date:

      https://github.com/nraboy/ubuntu-ionic-installer

      I’m not sure why you are having issues with bplist-parser and xmlbuilder. It could be a result of using too old a version of Node.js. You could always try installing the modules anyways:

      npm install -g bplist-parser xmlbuilder

  • Sompil

    [email protected]:~/Desktop$ ionic start MyProject blank

    Error: Cannot find module ‘utile’
    at Function.Module._resolveFilename (module.js:339:15)
    at Function.Module._load (module.js:290:25)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at Object. (/usr/local/lib/node_modules/ionic/node_modules/prompt/lib/prompt.js:10:13)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)

    Cannot find module ‘utile’ (CLI v1.7.14)

    Your system information:

    Cordova CLI: 6.0.0
    Ionic CLI Version: 1.7.14
    Ionic App Lib Version: 0.7.0
    OS: Distributor ID: elementary OS Description: elementary OS Freya
    Node Version: v5.6.0

    • Are you sure Ionic supports 5.x now? I don’t know for sure, but not too long ago it did not.

      Best,

      • Sompil

        same error using 0.xx version

  • Ean je’Lavell

    hey man, i have read through the script and done exactly what you have done by running the script and also watching your video,… but i think they may be a problem when install cordova now….. , but then when you create your first project (Plz remember i am doing exactly as you have also said in the comments to not use sudo), so i am not using sudo for anything just installed your script using the sudo command as you have on here, as i said you type in ionic start exampleproject blank, well there is a red area in the code that comes up first stating that cordova needs to be updated( I have not installed any versions of cordova at b4.), and then when i try to add platform android, it comes up with error as what other people here have…. error access: this is the first one i mentioned [

    Dependency warning – for the CLI to run correctly,

    it is highly suggested to install/upgrade the following:

    Please install your Cordova CLI to version >=4.2.0 npm install -g cordova

    ]

    and this is the second error: [

    /home/slater/.node/lib/node_modules/cordova/node_modules/update-notifier/node_modules/configstore/index.js:53

    Error: EACCES, permission denied ‘/home/slater/.config/configstore/update-notifier-cordova.json’

    You don’t have access to this file.

    ]

    so I am really baffled at all this happening, have no idea,… i have uninstalled everything…. so that nodejs and npm and anything else relating to this script is off my computer even anywhere that i can find node or other stuff, and i tried doing your script again…. same problem…. Frustrating…. But i have patience and hopefully you can possibly find where the problem lies, as my computer was a fresh install too… Hope you can help

    • What happens when you run this:

      It is possible things changed slightly and I need to update the script. Everything in your home directory should have the user ‘slater’ and nothing else.

      Best,

      • Ean je’Lavell

        hey man, tried that and no go, it seems things may have changed, because going by your script when it get to the installation of cordova and iconic, they wont install because they do not have sudo in front (I know, i know you have set it up that way)… But after going through your code on several virtual machines, all comes to the same conclusion that for some reason they both will not install (without sudo)…. Another note i did (After hours and hours) got it going on windows 10 (which i really hate) and had to search through all the forums when errors occurred and that has come down to one error to do with the build, and that is @drawable/icon thing…. anyway off topic, i have read that node and cordova do not play nice together, when node is the latest version… but checking with my own i have the one before the latest so should be fine,… but sadly your script does not work when getting to the cordova and iconic install…very strange indeed..

        • I’m going to investigate the script this weekend

      • Ean je’Lavell

        Hey man so i got it working going another route i followed this tutorial http://dasunhegoda.com/installrun-phonegap-ubuntu/797/ but where it says to install nodejs, i basically skipped that as installing npm installs node anyway, then if i got any errors i did your advice and sudo chown them…. when i got the @drawable icon error when building, i found this http://stackoverflow.com/questions/24206902/phonegap-3-5-not-cordova-icons-specified-in-config-xml-not-copied-during-build, so DO NOT copy config.xml to www folder, that is only for the phonegap cloud requirement,… basically open up the config file, and change icon src=”icon.png” to icon src=”www/icon.png” … after all that the build worked perfectly…. thanks for all your help NIC… this now rocks after days and hours of trying to get this going

  • Daniel Alvarez-Torres

    This worked for me but had to first remove the references to node an npm that were previously installed at /usr/local/bin, then I re-run the script and made symlinks to these binaries at /usr/local/bin (just in case)

  • santhoshkumar kotteeswaran

    Total newbie here i get this error while running “android” on terminal after the installation and restarting the machine

    Error: Unable to access jarfile /opt/android-sdk/tools/lib/archquery.jar
    Error: Unable to access jarfile /opt/android-sdk/tools/lib/archquery.jar
    Exception in thread “main” java.lang.NoClassDefFoundError: com/android/utils/ILogger
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2615)
    at java.lang.Class.getMethod0(Class.java:2856)
    at java.lang.Class.getMethod(Class.java:1668)
    at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
    Caused by: java.lang.ClassNotFoundException: com.android.utils.ILogger
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    … 6 more

    • I’ve not seen that one before. What is your environment?

      • santhoshkumar kotteeswaran

        ubuntu 14.04

        • Can you check the permissions on your Android SDK directory? I’m thinking one of the permissions or ownership became messed up.

          You should be safe recursively giving the Android SDK 777 permissions.

          Other than that, I’m not sure what could be wrong. I’ve tested this script many times on the same version of Ubuntu.

          Best,

  • hari krishnan

    Hello Nic, I cant build ionic project without sudo. It shows “Error: EACCES: permission denied”. And when i run it with sudo like “ionic build android” then it says “Failed to find ‘ANDROID_HOME’ environment variable”. Can u please help? Please see this question http://stackoverflow.com/questions/36198165/failed-to-find-android-home-environment-variable

  • Fabio Andres Pino Gutierrez

    i have a problem with setting variables enviroment for
    execute SDK of Android studio, i set the following path , export
    ANDROID_HOME=/home/fabio/Android/Sdk, export
    PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools and when
    write echo “$ANDROID_HOME” –> “/home/fabio/Android/Sdk”, echo
    “$PATH” –>
    “/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin:/home/fabio/Android/Sdk/tools:/home/fabio/Android/Sdk/tools:/home/fabio/Android/Sdk//tools:/home/fabio/Android/Sdk//platform-tools:/home/fabio/Android/Sdk/platform-tools:/home/fabio/Android/Sdk/tools:/home/fabio/Android/Sdk/platform-tools”
    if somebady knows how setting correctly plss tellme, i would appreciate it and thanks in advance for any help , im trying to set
    variables enviroments for run the following command “sudo phonegap build
    android” –> ERROR building one of the platforms: Failed to find
    ‘ANDROID_HOME’ environment variable. Try setting setting it manually.
    Failed to find ‘android’ command in your ‘PATH’. Try update your ‘PATH’ to include path to valid SDK directory.
    You may not have the required environment or OS to build this project

    Error: Failed to find ‘ANDROID_HOME’ environment variable. Try setting setting it manually.
    Failed to find ‘android’ command in your ‘PATH’. Try update your ‘PATH’ to include path to valid SDK directory.

    • Don’t use sudo to build.

      • Fabio Andres Pino Gutierrez

        thanks for the replay, but if i dont use sudo for build appear the following error –> Error: EACCES: permission denied, open ‘/home/fabio/.config/configstore/update-notifier-cordova.json’
        You don’t have access to this file.

        • Fabio Andres Pino Gutierrez

          i can give to that file chmod 777, but i didnt know if that is a goog practice for development of node

    • Fabien Flament

      Hi Fabio!

      I have the same problem… I would like to know if you solved it.

      Best regards,

      Fabien

      • You can change the permissions or the owner or the group. If it is in your home directory, your ownership is wrong. You should not 777 items in your home directory.

        • Fabien Flament

          Hi Nic,

          Thanks for the reply.

          If I understand what you mean, I have not to do “chmod 777” when I’m in my home directory. So, what do I need to do ?

          I use Ubuntu 14.04.

          • In your home directory run ls -la and see what the directory owners are. If anything comes back as root, it is not correct. Everything in your home directory should have a user of whatever your user account is. You can change ownership with the chown command. More Linux information can be found here:

            http://www.cyberciti.biz/faq/how-to-use-chmod-and-chown-command/

            Best,

  • chamod jayasundara

    npm error in last movement ,why this?

    • I’m not sure what you’re saying, but I’m going to need more information than this.

      Best,

  • Reaksmey SE

    I have a big problem with this :

    [Error: Failed to find ‘ANDROID_HOME’ environment variable. Try setting setting it manually.

    Failed to find ‘android’ command in your ‘PATH’. Try update your ‘PATH’ to include path to valid SDK directory.]

    Please, help me

    • Reaksmey SE

      @Nic [email protected]:disqus , can you lelp me for this ?

      • Posting more than one comment in a row to get my attention is a great way to not get a response at all. We’re obviously on different time zones. Let this be a lesson for next time.

        That said, I need more information. What are you running when you get that error?

  • Eric Fitzsimmons

    Thank you for the script. I tried running it, but I think I had some permission or version issues between my node modules, which was a real pain to fix. I ended up forcing npm global modules to be in my home directory and putting my directory first thing on the $PATH in my profile. I figured I would share in case anyone has had some similar issues. Not ideal for a shared computer, but for a 1 user machine, it should do just fine.

    This will help for making sure you are pointing to the right folders.
    http://www.sitepoint.com/beginners-guide-node-package-manager/

  • Boutar Badii

    hey I’ve just used the tips you mentioned above, thanks a lot for that it helped a lot,
    but, only one issue when I come to do ionic run android it comes out like that

    [email protected]:~/Desktop/todo$ ionic run android

    Running command: /home/lua/Desktop/todo/hooks/after_prepare/010_add_platform_class.js /home/lua/Desktop/todo

    add to body class: platform-android

    Error: Android SDK not found. Make sure that it is installed. If it is not at the default location, set the ANDROID_HOME environment variable.
    ..
    I really spent like two days googling for that issue, and I found nothing helping, like even when I tried to run the command android that’s what i get :

    [email protected]:~$ android
    Error: Unable to access jarfile /opt/android-sdk/tools/lib/archquery.jar
    Error: Unable to access jarfile /opt/android-sdk/tools/lib/archquery.jar
    Exception in thread “main” java.lang.NoClassDefFoundError: com/android/utils/ILogger
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2625)
    at java.lang.Class.getMethod0(Class.java:2866)
    at java.lang.Class.getMethod(Class.java:1676)
    at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
    Caused by: java.lang.ClassNotFoundException: com.android.utils.ILogger
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    … 6 more

    ..
    It’s really driving me insane.. like I even tried the export commands
    like
    export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
    export ANDROID_HOME=/home/lua/Android/Sdk
    .
    restarted the machine several times but nothing worked.. can you help me please?

    • What are the file and directory permissions? Maybe some of the permissions got messed up.

  • shivkrishna shah

    its not working , i got error like:

    Error: Cannot find module ‘xmlbuilder’

    • Any more details? When do you get this error?

      • shivkrishna shah

        sorry buddy, i resolved same issue .

        • DotSlashAttack

          How did you resolve the issue? I don’t get that error, but it’s beneficial to others who may be seeing the same error.

  • HI nic i was using this blog to install ionic now i am trying to install ionic 2 with this comman sudo npm install -g [email protected] but i and i am trying to create an new project in ionic 2 but i am getting error

    • Looks like an Ionic issue. Have you tried posting to the issue tracker like the error says?

      • i got that error cleared sorry and thanks for your reply

  • Lavanya Parvathi

    Is there something same which I can do with windows10. please help me i am very confused with path i am getting error with shell.js internall error like that help me

    • I don’t use Windows so this is out of my scope of knowledge.

  • Kiran Ghuge

    hello Nic,

    I followed all the steps you told in this article and thank you for sharing this article but I get some error at the time of running the command “ionic run android” or”ionic build android” or “ionic emulate android” i try all these three commands. can you tell whats the problem

    [email protected]:~/Geo_Location$ ionic emulate android
    Running command: /home/vimal/Geo_Location/hooks/after_prepare/010_add_platform_class.js /home/vimal/Geo_Location
    add to body class: platform-android
    ANDROID_HOME=/opt/android-sdk
    JAVA_HOME=/usr/lib/jvm/default-java
    Downloading http://services.gradle.org/distributions/gradle-2.13-all.zip
    ………………………..^Z
    [1]+ Stopped ionic emulate android
    [email protected]:~/Geo_Location$ ionic emulate android
    Running command: /home/vimal/Geo_Location/hooks/after_prepare/010_add_platform_class.js /home/vimal/Geo_Location
    add to body class: platform-android
    ANDROID_HOME=/opt/android-sdk
    JAVA_HOME=/usr/lib/jvm/default-java
    Exception in thread “main” java.lang.RuntimeException: Timeout of 120000 reached waiting for exclusive access to file: /home/vimal/.gradle/wrapper/dists/gradle-2.13-all/7hsc6vr6mi3i6i5m7q9hj4ci1q/gradle-2.13-all.zip
    at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:61)
    at org.gradle.wrapper.Install.createDist(Install.java:47)
    at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:129)
    at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48)
    Error: /home/vimal/Geo_Location/platforms/android/gradlew: Command failed with exit code 1 Error output:
    Exception in thread “main” java.lang.RuntimeException: Timeout of 120000 reached waiting for exclusive access to file: /home/vimal/.gradle/wrapper/dists/gradle-2.13-all/7hsc6vr6mi3i6i5m7q9hj4ci1q/gradle-2.13-all.zip
    at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:61)
    at org.gradle.wrapper.Install.createDist(Install.java:47)
    at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:129)
    at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48)
    [email protected]:~/Geo_Location$

    • Sounds like you either don’t have your AVD emulators created correctly or there is a bug in the Ionic CLI on your machine. I’ve never encountered or heard other reports of this issue. If it is not an AVD issue, I’d recommend opening a ticket for Ionic Framework.

      Best,

  • Crib

    Hi Nic,

    I have one Problem, i can’t find out my mistake, but i think you can!

    Exception in thread “main” java.lang.UnsupportedClassVersionError: com/android/dx/command/Main : Unsupported major.minor version 52.0

    :transformClassesWithDexForDebug FAILED

    BUILD FAILED

    Total time: 13.323 secs

    FAILURE: Build failed with an exception.

    What went wrong:
    Execution failed for task ‘:transformClassesWithDexForDebug’.

    com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command ‘/usr/lib/jvm/java-7-openjdk-amd64/bin/java” finished with non-zero exit value 1

    Try:
    Run with –stacktrace option to get the stack trace. Run with –info or –debug option to get more log output.

    Error: /home/ionic/Desktop/Example/platforms/android/gradlew: Command failed with exit code 1 Error output:
    Note: Some input files use or override a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    Note: /home/ionic/Desktop/Example/platforms/android/src/org/apache/cordova/splashscreen/SplashScreen.java uses or overrides a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    Exception in thread “main” java.lang.UnsupportedClassVersionError: com/android/dx/command/Main : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:803)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)

    FAILURE: Build failed with an exception.

    What went wrong:
    Execution failed for task ‘:transformClassesWithDexForDebug’.

    com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command ‘/usr/lib/jvm/java-7-openjdk-amd64/bin/java” finished with non-zero exit value 1

    Try:
    Run with –stacktrace option to get the stack trace. Run with –info or –debug option to get more log output.

    I hope you can help me, im very frustrated …..

    • Unsupported major.minor version 52.0

      That error means you’re trying to use a library that was built with a different version of Java than what you’re currently using. Whatever version of Ubuntu you’re using, it is defaulting to Java 7. You manually install to Java 8 and things should correct themselves. I believe the latest Ubuntu versions are using Java 8 by default, but I could be wrong.

      Best,

  • Najam us saqib

    hi, Nic,
    I have been following you since 6 months and on every stage i go through your tutorials and resolved my problems. Thanks for your Tutorials.
    Now i am facing an issue when i create an Ionic app.
    Problem:
    ionic start myApp blank (works Fine, create new folder and files)
    but after that npm install gives errors….

    npm-degub.log file is missing.. i tried everything on INTERNET but couldn’t able to resolve this issue.

    Your system information:

    Cordova CLI: 6.4.0
    Ionic CLI Version: 2.1.4
    Ionic App Lib Version: 2.1.2
    OS: Distributor ID: Ubuntu Description: Ubuntu 16.04.1 LTS

    Node Version: v4.2.6

    i used your shell script to install these thing on my system.
    my old node version is V0.12.9
    may be my old node is out dated but as you see now i have newer version but still my problem is same.
    any solution??? https://uploads.disquscdn.com/images/b128cd57c31c9d210a2d4a8898113a6e3478e1f013dbd9acfd433e8f0f2ce9ce.png

    • Try fixing the directory permissions on your ~/.npm directory. Make sure you do this recursively so the permission denied error goes away. Anything in your home directory should have your ownership, not root.

      Best,

      • Najam us saqib

        can you Please Guide me how can i change my permissions?? I am new to linux 🙁

        • Research chmod and chown. Honestly if you don’t know Linux you should start smaller than this.