If you want to update your version of Cordova PhoneGap to the latest version, or you want to revert to an earlier version (to test or debug), here are the steps to follow. I also have instructions on updating the plugins and platform versions here.
Cordova blog for latest updates:
First check what version you are running. Run Terminal and type the following. (You don’t have to be within a project folder to do any of the steps in this article.)
If my output was:
. . . I could update to the latest version of Cordova PhoneGap via CLI by typing:
npm update -g cordova
(Or replace cordova with phonegap, whichever one you started out with.)
If you get this output:npm http GET https://registry.npmjs.org/cordova npm http 304 https://registry.npmjs.org/cordova
. . . there was no update available.
If you get this error output:Please try running this command again as root/Administrator.
. . . try this in Terminal instead:sudo npm install -g cordova
(Updating cordova also updates its tools: cordova-libs, plugman, and cordova-js.)
Is it possible to revert to an earlier version? Yes. We can learn what versions we can update to (or revert to) with:
npm info cordova
To revert from 3.5.0 to 3.4.0, I would first type in the terminal:
npm install -g cordova
. . . then highlight an earlier version in the list:
. . . and paste it at the end so it reads like the following, and hit Enter:
npm install -g email@example.com
Then verify the current install with:
A. At one point I got the error in the console:404 Not Found: 5.0.0'5.0.0' is not in the npm registry.
My mistake was leaving out the “@” symbol in the command: firstname.lastname@example.org
B. Another time I got the error:Error: EACCES, unlink '/usr/local/lib/node_modules/cordova/.npmignore'Please try running this command again as root/Administrator.
So I ran the code with “sudo” in front like this, entered the unit’s Admin password, and it ran successfully:sudo npm install -g email@example.com
If you encounter issues with an individual plugin, by all means let your debugging include removing the plugin and adding it again. To do that, follow these steps:
a. In terminal, type the following to see the plugins installed.
cordova plugin ls
cordova-plugin-inappbrowser 1.0.1 "InAppBrowser"
cordova-plugin-splashscreen 2.1.0 "Splashscreen"
cordova-plugin-whitelist 1.0.0 "Whitelist"
b. Highlight the plugin you want to remove, and copy it.
c. In terminal, type in the remove command and paste in the copied plugin:
cordova plugin rm cordova-plugin-inappbrowser
d. To install again, type in the add command in the terminal, and paste in the copied plugin
cordova plugin add cordova-plugin-inappbrowser
Note that Cordova does not have a way to update plugins. If you know of an updated plugin, then you simply following the a, b, c steps above to install the new plugin version.
You can batch update plugins with rm and add like so:
cordova plugin rm cordova-plugin-inappbrowser cordova-plugin-camera
You can check which plugins are available with a search. For instance, to search for a bar code plugin:
cordova plugin search bar code
You may want to take advantage of the newer, faster WKWebkit engine.
cordova plugin add cordova-plugin-wkwebview-engine --save
Regarding using Whitelist in iOS apps, read this: http://devgirl.org/2016/01/11/a-faster-hybrid-app-for-the-new-year/
Updating a Platform
To update a particular platform (perform this command one at a time for each platform), do the following command. However, this will remove the entire /android folder, so all your images in /platforms/android/res/drawable* will be lost. Make sure you have backups of these images first, or simply copy the /res folder to your root directory before updating, then copy them back.
To see what version of platform is installed, type:
cordova platform ?
Installed platforms: android 4.1.1, ios 3.9.2
Available platforms: amazon-fireos, blackberry10, browser, firefoxos, osx, webos
Note that the information will be returned based on which project you are in. “cd” to your project folder, then run the command.
When I received notice from Google Play of a security risk and was told to update the app to the latest version, it’s not enough to update Cordova. We need to update the Android platform for that project, as follows.
To update the platform, remove the platform, then add it again:
cordova platform rm android
cordova platform add android@latest
Or simply use the update command:
cordova platform update android
cordova platform update firstname.lastname@example.org
cordova platform add email@example.com --save
Cordova 4.0 and higher needs ios-deploy, so add it:
npm install -g ios-deploy
Updating Node and npm
You’ll need to update Node and npm occasionally, especially if you are getting console errors that don’t seem to make sense.
In the console, check the version:
Visit the Nodejs site to check it against the latest stable version: https://nodejs.org/en/ Install the latest version; it will be a pkg file. Double-click on it to start the install process. It might require password access to your computer (Mac), so stick around to enter it. When the process is done, it will tell you (Mac):
Node.js was installed at
npm was installed at
Make sure that /usr/local/bin is in your $PATH.
(This will also update npm.) Start a new console session and check the version as above.
If you get errors that are related to npm (such as Error: Cannot find module ‘semver’), then upgrade npm by itself:
sudo npm update -g
This will require that you enter your password.