I just installed Node.js
and npm
(for additional modules).
How can I update Node.js and the modules which I\'m using to the latest versions
I just installed Node.js on a new Windows 7 machine, with the following results:
> node -v
v0.12.0
> npm -v
2.5.1
I then did the above described procedure:
> npm install -g npm
and it upgraded to v2.7.3. Except than doing npm -v
still gave 2.5.1.
I went to the System configuration panel, advanced settings, environment variables. I saw a PATH variable specific to my user account, in addition to the global Path variable.
The former pointed to new npm: C:\Users\PhiLho\AppData\Roaming\npm
The latter includes the path to node: C:\PrgCmdLine\nodejs\
(Nowadays, I avoid to install stuff in Program Files and derivates. Avoiding spaces in paths, and noisy useless protections is saner...)
If I do which npm.cmd
(I have Unix utilities installed...), it points to the one in Node.
Anyway, the fix is simple: I just copied the first path (to npm) just before the path to node in the main, global Path variable, and now it picks up the latest version.
<some stuff before>;C:\Users\PhiLho\AppData\Roaming\npm;C:\PrgCmdLine\nodejs\
> npm -v
2.7.3
Enjoy. :-)
Warning: if you need update Node from an old version (in my case v4.6.0
) it is better to re-install nodejs from scratch (download link: https://nodejs.org) otherwise npm will also update itself to a version that's not compatible with the new Node (see this discussion).
This is the error message that I got after updating Node (on Windows) with npm
$ npm install -g npm stable
[ . . .]
$ npm
C:\Users\me\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js:85
let notifier = require('update-notifier')({pkg})
^^^
SyntaxError: Block-scoped declarations (let, const, function, class) not yet supporte
d outside strict mode
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:974:3
After new installation npm works again:
$ npm -v
6.5.0
$ node -v
v10.15.0
Just listened to an interview with the npm team on the latest episode of nodeup, and they recommended not using update
for the update from 1.x
to 2.x
. Instead, use:
npm install npm -g
Sometimes it's just simpler to download the latest version from http://nodejs.org/
Especially when all other options fail.
http://nodejs.org/ -> click INSTALL -> you'll have the latest node and npm
Simple!
Windows users should read Troubleshooting > Upgrading on Windows in the npm wiki.
The link above Troubleshooting#upgrading-on-windows points to a github page npm-windows-upgrade the lines below are quotes from the readme. I successfully upgraded from npm 2.7.4 to npm 3.9.3 using node v5.7.0 and powershell (presumably powershell version 5.0.10586.122)
First, ensure that you can execute scripts on your system by running the following command from an elevated PowerShell. To run PowerShell as Administrator, click Start, search for PowerShell, right-click PowerShell and select Run as Administrator.
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
Then, to install and use this upgrader tool, run (also from an elevated PowerShell or cmd.exe):
npm install --global --production npm-windows-upgrade
npm-windows-upgrade
sudo npm install npm@latest
I run this on Linux so I am not sure about other operating systems.
sudo apt-get update
sudo apt-get upgrade
This will tell the apt-get
package manager to update and upgrade all packages.