If you want to update your version of Cordova 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.
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 firstname.lastname@example.org
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: email@example.com
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 firstname.lastname@example.org
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 see what version you have installed, then from the app’s root directory in the Terminal, type:
cordova platform version android
cordova platform version ios
For Android, it returned:
Installed platforms: android 4.0.2 ios 3.8.0 Available platforms: amazon-fireos ~3.6.3 (deprecated) blackberry10 ~3.8.0 browser ~4.1.0 firefoxos ~3.6.3 osx ~4.0.1 webos ~3.7.0 ┌──────────────────────────────────────────┐ │ Update available: 6.5.0 (current: 6.4.0) │ │ Run npm install -g cordova to update. │ └──────────────────────────────────────────┘
To update the platform, use the update command:
cordova platform update android
Go ahead and run cordova platform version android to verify the upgrade was successful.
You can also update to a specific version:
cordova platform update email@example.com
cordova platform add firstname.lastname@example.org --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.