Hybrid mobile application development is a hot topic these days. PhoneGap is one of the frameworks that can be used to develop hybrid mobile apps. If you are new to hybrid mobile application development read this post. You only have to follow these steps to have a PhoneGap app up and running in your Ubuntu. Before that,

What’s PhoneGap

PhoneGap is a free and open source framework that allows you to create mobile apps using standardized web APIs for the platforms you care about.

See the image below for the build process of PhoneGap.

Image Courtesy : build.phonegap.com
Image Courtesy : build.phonegap.com

Note that You need to have Java on your Ubuntu. Let’s start.

1. Install nodejs

sudo apt-get update
sudo apt-get install nodejs

Let’s install npm, which is the Node.js package manager. You can do this by typing

sudo apt-get install npm

The NodeJS is installed & named as nodejs. But PhoneGap, expect the executable to be named node. To fix this inconsistency, create a symlink named node that points to nodejs as follows.

sudo ln -s /usr/bin/nodejs /usr/bin/node

2. Install Git

sudo apt-get install git

3. Install Ant

sudo apt-get install ant

4. Install PhoneGap

sudo npm install -g phonegap

let’s install libraries that PhoneGap is dependent on.

sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0 lib32stdc++6

type phonegap on the command line and check whether PhoneGap has installed correctly as shown below.

Phonegap Install
Successful Phonegap Installation

5. Get the Android SDK

You can download the SDK here. Extract the package to /usr/local/android-sdk using below command. Any other preferred place would be fine but make sure to change the path accordingly.

sudo tar -zxvf ~/Downloads/android-sdk_r24.0.2-linux.tgz -C /usr/local/

If you have any issue refer this thread. Complete Installation Guide for Android SDK / ADT Bundle on Ubuntu.

Now let’s set the environment variables in the bash configuration file, so that PhoneGap can call the Android emulator. Edit the .bashrc file as below.

vim ~/.bashrc

Add the below lines.

export PATH=$PATH:/usr/local/android-sdk-linux/
export PATH=$PATH:/usr/local/android-sdk-linux/tools
export PATH=$PATH:/usr/local/android-sdk-linux/platform-tools
export PATH=$PATH:/usr/local/android-sdk-linux/build-tools

Update the newly added alias in the existing terminal.

source ~/.bashrc

Type android and see whether Android SDK Manager is started as shown below.

Android SDK Manager
Android SDK Manager

 

6. Let’s install a faster emulator

You can use the android emulator if you really prefer it but rather than using the slow android emulator today I’ll show an emulator which is faster and better. Genymotion. You may have to create an account download the appilcation. Also note that account will be used at later when you run the application as well.

Let’s download from this link. Set the permission before you start running the application as shown below.

chmod u+x genymotion-2.1.0_x64.bin
./genymotion-2.1.0_x64.bin

You might see the below error if VirtualBox is not installed in your system which is required by Genymotion.

Genemotion Install Error
Genemotion Install Error

Below command will fix the issue.

sudo apt-get install virtualbox

Now let’s run Genymotion.

cd /home/dasunhegoda/Downloads/genymotion/
./genymotion

Now login to the genymotion account and create an emulator. Refer this link for more info on setting up Genymotion.

7. Let’s create a phonegap appilcation

Create a PhoneGap project using below command.

phonegap create testapp

Add Android as a platform to be built.

phonegap platform add android

To list the available platform try the below command(Optional).

phonegap platform -ls

Now let run the application. Make sure you have started your emulator so that application will be started in it.

phonegap run android

Tips & Tricks

Phonegap is built on Apache Cordova. Apache Cordova is the engine that powers PhoneGap. Therefore you can replace some of the Phonegap command with Cordova. If you really want to know the exact difference read this post. Is there a difference between PhoneGap and Cordova commands? Answer is here. Instead of typing

phonegap run android

type

cordova run android

which will work fine as well. But when you type Cordova commands you will see a more detailed output then PhoneGap commands which is helpful for debugging purposes. See the Apache Cordova installation guide here. Also refer the PhoneGap Wiki as well.

If you have any questions let me know in the comments below. Your feedback is highly appreciated(happy-face).

Loading

40 Comments

  1. ಭಾರತೀಯ April 16, 2015 at 1:13 pm

    Hi,

    Installed phonegap using,,

    sudo npm install -g phonegap

    but …..

    sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0 lib32stdc++6

    …is not working…. error is given below

    E: Unable to locate package lib32z1
    E: Unable to locate package lib32ncurses5
    E: Unable to locate package lib32bz2-1.0
    E: Couldn’t find any package by regex ‘lib32bz2-1.0’
    E: Unable to locate package lib32stdc++6
    E: Couldn’t find any package by regex ‘lib32stdc++6

    typed phonegap on the terminal but showing nothing…

    help me

    Thank you in advance

    Reply
    1. Dasun Hegoda April 16, 2015 at 2:49 pm

      Execute the below command 1st then try the command.

      
      
      sudo apt-get install package-name:i386
      Reply
      1. Julien Coron April 26, 2016 at 6:18 am

        Hello,
        The following command does not work. The package is not located too.

        sudo apt-get install lib32z1:i386

        Reply
        1. kloshar4o July 28, 2016 at 6:12 pm

          Hey Julien, im having the same issue, did you manage to find solution?

          Reply
          1. Julien Coron July 29, 2016 at 8:41 am

            Hi kloshar4o, I aborted this installation. I’ve better results with the Kivy Framework.

  2. Dickriven Chellemboyee May 8, 2015 at 10:55 pm

    Thanks for this article.

    Didn’t know about genymotion and it’s really great :)

    Reply
  3. Akshay Patni May 20, 2015 at 10:16 am

    Hi,

    Can u please tell me how to install phonegap on centos

    Reply
  4. noob June 22, 2015 at 4:50 pm

    Do I need to install JDK?

    Reply
    1. Dasun Hegoda June 22, 2015 at 5:02 pm

      Yes, You need to have Java on your Ubuntu

      Reply
  5. chit July 1, 2015 at 9:06 pm

    Hi, This is a great article. I followed your instructions. I could not install the libraries mentioned in the article. Errors were unable to locate the packages. And also the commands listed after typing phonegap from the command line, doesn’t list all the commands that you have. I have only these

    Commands:

    create create a phonegap project
    build build a specific platform
    install install a specific platform
    run build and install a specific platform
    local [command] development on local system
    remote [command] development in cloud with phonegap/build
    help [command] output usage information
    version output version number

    Options:

    -v, –version output version number
    -h, –help output usage information

    Platforms:

    android target Android
    blackberry target BlackBerry 10
    ios target iOS
    wp7 target Windows Phone 7
    wp8 target Windows Phone 8

    Examples:

    $ phonegap help create
    $ phonegap help remote build
    $ phonegap create path/to/my-app
    $ phonegap remote build android

    Can you please help solving? phonegap -v shows 0.9.4

    Thanks much in advance.

    Reply
    1. Dasun Hegoda July 2, 2015 at 11:52 am

      These are commands that come with PhoneGap. But underneath it uses Cordova.Therefore you should be able to access them but makes sure all the libs are installed.

      Reply
      1. chit July 8, 2015 at 9:50 am

        Thanks.. But I couldn’t able to install the libs that u have mentioned. I get unable to locate package

        Reply
  6. adhy September 30, 2015 at 3:18 am

    Hi, This is a great article. I followed your instructions, but i have not progressing at point 5, exactly on editing ./bashrc,

    when i type android, it says “android:comand not found”

    what should i do?

    *sorry for my bad english.

    Reply
    1. Dasun Hegoda September 30, 2015 at 4:03 pm

      That’s because .bashrc has nt been updated correctly. Please check the paths.

      Reply
      1. adhy September 30, 2015 at 11:44 pm

        okay… i only export paths via terminal…

        problem solved…

        thank you

        Reply
      2. Anes P.A March 21, 2016 at 11:07 am

        Dear Dasun,
        I got error as “bash: /usr/local/android-sdk-linux/tools/android: Permission denied”. What I do ?

        Reply
          1. Anes P.A March 23, 2016 at 11:07 am

            When I try with sudo get as
            sudo: android: command not found

          2. Dasun Hegoda March 23, 2016 at 3:55 pm

            That’s because you haven’t set the paths in .bashrc for sudo

          3. Anes P.A March 24, 2016 at 3:57 am

            Thanks Dasun ,
            $ sudo -s
            command do the trick…

    2. twicejr November 2, 2015 at 11:17 am

      For others: when you are using zsh instead of bash for example, edit ~/.zshrc instead.

      Reply
  7. Anthony Dobaj October 26, 2015 at 5:02 am

    Hi, thanks for offering your wisdom. I cannot get my
    phonegap app to install – the error is Failure
    [INSTALL_FAILED_UPDATE_INCOMPATIBLE] – the target is a device
    running Android 5.1.1, but “phonegap platform list” only shows
    android 4.1.1. when I attempt to run “phonegap platform add
    android@5.1.1 I get an error

    “Failed to fetch
    platform android@5.1.1

    Probably this is
    either a connection problem, or platform spec is incorrect.

    Check your
    connection and platform name/version/URL.

    Error: version not
    found: cordova-android@5.1.1”

    what should I try to
    get this app to install?

    Reply
      1. Anthony Dobaj October 29, 2015 at 3:35 am

        Thank you for that, but I tried every way from Sunday to make sure the app wasn’t already installed – wasn’t until I started using the phonegap build utility that I could get the app to install and run. that utility is a little inconvenient, I might come back to the command line some time in the future.

        Reply
  8. Em Ji Madhu December 9, 2015 at 8:54 am

    i have followed your instructions.. i have installed evrything andriodsdk, emulator, phonegap and everything else you mentioned.. but when i give “phonegap” to test its installed, nothing happened.. not just that one alone, but every command which inculdes phonegap like “phonegap platform -ls” ther goes, nothing happen.. if i give commands its just goes to next line.. thats all.. im usint ubuntu 14.04

    Reply
  9. Em Ji Madhu December 9, 2015 at 8:57 am

    i have followed your instructions.. i have installed evrything andriodsdk, emulator, phonegap and everything else you mentioned.. but when i give “phonegap” to test its installed, nothing happened.. not just that one alone, but every command which inculdes phonegap like “phonegap platform -ls” ther goes, nothing happen.. if i give commands its just goes to next line.. thats all.. im using ubuntu 14.04

    Reply
    1. Kev December 14, 2015 at 3:49 am

      I tried installing cordova, nodejs, npm and phonegap on 14.04 and I could not get it to to work no matter how hard I tried. I upgraded to 15.10 (latest) and I installed cordova, nodejs and npm following this link http://jeffmcmahan.info/blog/installing-cordova-on-linux/ . And followed this tutorial without so much as a drop of sweat! Back up and save all your data because I had a problem upgrading from 14.04 to 15!

      Reply
  10. Pingback: Are there any simple PhoneGap tutorials? | Some Cordova Questions and Answers

  11. Sam ian Hernandez March 16, 2016 at 3:30 am

    I finished until set up #6 but then i get an error at #7 when i typed the command “phonegap create testapp”
    It throws an error:

    module.js:340
    throw err;
    ^
    Error: Cannot find module ‘bplist-parser’
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object. (/usr/local/lib/node_modules/phonegap/node_modules/cordova/node_modules/cordova-lib/node_modules/cordova-common/src/ConfigChanges/ConfigFile.js:20:14)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)

    Please help. Thanks

    Reply
  12. Trioxin March 18, 2016 at 2:04 am

    if we’re running 64bit ubuntu should those packages be the 64bit versions? why 32?

    Reply
    1. M.Hanny Sabbagh August 12, 2016 at 11:53 am

      You have to run:
      $ sudo apt-get install libz1 libncurses5 libbz2-1.0 libstdc++6

      Reply
  13. Anes P.A March 24, 2016 at 6:46 am

    Dear friends,
    when I try to run (on my ubuntu 15.10)
    root@insight:~/testapp# cordova run android
    ERROR running one or more of the platforms: Android SDK not found. Make sure that it is installed. If it is not at the default location, set the ANDROID_HOME environment variable.
    You may not have the required environment or OS to run this project

    as error . Please advise

    Thanks

    Reply
  14. Konrad Slepoy June 24, 2016 at 9:02 pm

    I’m confused … Why is this all geared towards android? Like why are we using an android-sdk and such? Is that just for testing purposes? Could this just as easily be geared towards ios or another platform? I thought that was the point of phonegap.. It would have been helpful if you talked about that on some level

    Reply
  15. Daniel Villarreal October 9, 2016 at 3:54 am

    Hi, I am developing and mobile app with phonegap,
    I will use android-sdk , and I installed it, but it has many many packages, which are the minimum necessary? do they depend on my hardware? 64bit i5 ?

    Reply
  16. Shaik Babji January 3, 2017 at 2:33 pm

    Surely I will try this method. Good information. Thank you very much dear admin.
    English grammar

    Reply
  17. Pingback: Computer doesn't recognise file – 1OO Club

Leave A Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.