Using PhoneGap CLI 3.6.3 Commands

Here is a rundown on the phonegap commands you can execute with version 3.6.3 PhoneGap CLI (command-line interface) using the Terminal or console.

These commands assume you have set in Terminal the starting folder in which the project files are located. So if you want the command to act on /myApp2, for example, the Terminal window command line should already include myApp2 at left, somewhere before the $. You would type your commands to the right of the $. To set the starting folder:
a. Open a Finder window and select the folder you want to create your project’s folder inside of, such as /PhonegapApps
b. Open the Terminal app (click on its icon in the dock below, or click on the magnifying glass at top right and type in “terminal”), type cd and a space (for “change directory”), drag the selected folder to the Terminal screen, let go, click on the Terminal to select it, then hit Return. This will orient all commands to that folder.


Install phonegap CLI with the following:

npm install -g phonegap

. . . or with the following, which requires system password:

sudo npm install -g phonegap

(Note that commands with “npm” assume you have node.js installed on your system. For more information on this, read:


Find out or verify what version is installed on your system with:

phonegap --version


Update to 3.6.3-0.22.6 or higher with the following to gain new functionality over previous versions:

npm update -g phonegap

. . . or use the following, which requires system password (use the following if the earlier command resulted in the line: “npm ERR! Please try running this command again as root/Administrator.”):

sudo npm update -g phonegap


Get proper command format for using the phonegap CLI commands with:


Get help for specific commands with the -h or –help flags:

phonegap platform add -h

Get more information to accompany your output with the -d or –verbose flags added to your command (helpful when you want to diagnose error output):

phonegap platform add android -d


Follow these next steps with me to see what they do.


phonegap create myApp1

This will create a default phonegap app that includes the following in your config.xml file:

<widget id="com.phonegap.helloworld" version="1.0.0" xmlns="" xmlns:gap="">
 <name>Hello World</name>

create +

phonegap create myApp2 "com.companyname.appname" "App Name"

This will create a default phonegap app that includes the following in your config.xml file:

<widget id="com.companyname.appname" version="1.0.0" xmlns="" xmlns:gap="">
 <name>App Name</name>


phonegap create myApp3 --copy-from myApp2

This will create a new app in the folder /myApp3 that is a duplicate of /myApp2. Any files in /myApp2/hooks and /myApp2/www will be copied, but not the files in /myApp2/plugins or /myApp2/platforms. Config.xml is default phonegap:

<widget id="com.phonegap.helloworld" version="1.0.0" xmlns="" xmlns:gap="">
 <name>Hello World</name>

–copy-from +

phonegap create myApp4 "com.companyname.appname4" "App Name4" --copy-from myApp2

This will create a new app in the folder /myApp4 that is a duplicate of /myApp2. Any files in /myApp2/hooks and /myApp2/www will be copied, but not the files in /myApp2/plugins or /myApp2/platforms. Config.xml includes the “com.companyname.appname4” “App Name4” information from the command line:

<widget id="com.companyname.appname4" version="1.0.0" xmlns="" xmlns:gap="">
 <name>App Name4</name>


phonegap create myApp5 --link-to myApp2

Looking inside the folder, we see symlinks (aliases or shortcuts) to myApp2’s config.xml, /hooks, and /www folders. Note that if you delete myApp2’s files, then create myApp2 again, the symlinks will point to the files in the Trash, not the new myApp2 folders of the same name.


cd myApp5
phonegap info

This will give you the contents of the config.xml file and list all the plugins and platforms associated with the project.

platform add

phonegap platform add android

Adds the android platform files to the project. Added to /platforms/android.

platform rm

phonegap platform rm android

Removes the android platform from the project. All files of /platforms/android, including the folder, are removed.


phonegap build android

Adds the android (or other specified platform) to the project if it’s not there already and builds it, creating a debug version apk. Look in /myApp5/platforms to see the files generated. (See /myApp5/platforms/android/ant-build/AppName-debug.apk for the apk file to test on your device.)

plugin add

phonegap plugin add <...>

Add plugins to phonegap for increased functionality. Use the plugin syntax listed at and For instance, the following command adds the InAppBrowser plugin to the project:

phonegap plugin add org.apache.cordova.inappbrowser

Look in the /plugins folder for the files.

plugins list

phonegap plugins ls

This command will list all the plugins downloaded that are in the /plugins folder, along with their version number. For instance, this output:

org.apache.cordova.inappbrowser 0.5.3 "InAppBrowser"

plugin rm

phonegap plugin rm <...>

Removes the specified plugin. For example the following command removes the InAppBrowser plugin from the project:

phonegap plugin rm org.apache.cordova.inappbrowser

install, run

Install has been deprecated, meaning it will be removed from further use in a future version. Use run instead. Plug your Android device into your computer, fire up to the home screen, make sure you give it debugging permissions in Settings, and run:

phonegap run android

The project is built and displayed on the device.


phonegap emulate android

If Eclipse is installed and working properly, this command starts up the emulator and displays the app in it (usually starts up very slowly). Doesn’t always work for me.


phonegap serve android

Displays the app in the browser. Console returns:

[phonegap] starting app server...
[phonegap] listening on

You then copy the URL,, and paste it into a browser like Chrome. Click on Cancel for all the popups. To stop the server, click on the Terminal window then press ctrl-c.


phonegap prepare android

Use this command to update the project after any changes to the /www folder. For example, if you are making changes to files in the /www folder in response to a warning or error in Eclipse, then run the prepare command when the changes are done, then in Eclipse run Clean so Eclipse can recognize the changes.


phonegap compile android

Compiles the platform project without preparing it. If you made changes that need to be incorporated into the project, run the prepare command first.


Use this with development in cloud with Phonegap Build. I don’t  use that service, so I can’t give any further information.

save –experimental

Add a plugin then run the following to write the info into config.xml:

phonegap save plugins --experimental

For example, if the InAppBrowser was recently added and this command was run, it’ll write the following into config.xml:

<feature name="InAppBrowser">
 <param name="id" value="org.apache.cordova.inappbrowser" />

(However, if you have removed all the gap:plugin lines from config.xml, it will not add it back in, such as <gap:plugin name=”org.apache.cordova.inappbrowser” />.)

Add a platform then run the following to save the platform info into config.xml:

phonegap save platforms --experimental

The following line is added to config.xml. It is the prerequisite for the following restore command:

<cdv:engine id="android" />

restore –experimental

phonegap restore plugins --experimental

After performing the save command and removing the plugins from the /plugins folder, this command restores all the plugins to that folder. This is helpful when debugging, and you need to remove all the plugins and reinstall them. This one command will take care of restoring all of them for you, saving time.

phonegap restore platforms --experimental

This command will restore the platforms removed from the project’s /platforms folder earlier, but only if the save command was used first. This one command will take care of restoring all of them for you, saving time.

One thought on “Using PhoneGap CLI 3.6.3 Commands

  1. Pingback: PhoneGap Desktop App Beta | iPhone Dev Log

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s