How do I update npm on Windows?
Solution 1:
You need to follow the Windows upgrade instructions ( https://docs.npmjs.com/try-the-latest-stable-version-of-npm )
tl;dr - npm -g install npm
does work, but the old version of npm is still in your PATH.
To fix this, do one of these:
Option 2: remove both of
C:\Program Files (x86)\nodejs\npm
C:\Program Files (x86)\nodejs\npm.cmd
Or
Option 3: Open cmd.exe as administrator, navigate to C:\Program Files (x86)\nodejs and then run the installation without -g:
npm install npm@latest
*There is an npm package that automate this Option 3:
npm install -g npm-win-upgrade
Solution 2:
We at Microsoft Open Source wrote a small tool to automate the process outlined above. You can find it here or just install and run it by executing the following in an elevated command prompt / PowerShell:
npm install -g npm-windows-upgrade
npm-windows-upgrade
Solution 3:
There May be many ways to update your npm
in Windows
Way 1
- Open you power shell as Administrator and run following commands step by step.
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install -g npm-windows-upgrade
npm-windows-upgrade
- Here you can select your preferred version of npm
- Ready to go !
Way 2
- You can simply upgrade to the latest
npm
version with following command npm install npm@latest -g
- or if you want a specific version of
npm
simply run -
npm install npm@{version} -g
for examplenpm install [email protected] -g
Now simply run npm --version
or npm -v
to know your current version of npm
3.3.12
is my preferred version ofnpm
that best suits for approximately every package.
Solution 4:
So, TL;DR; this worked:
Uninstall node
From a command prompt, run
where npm
- If you had npm installed via chocolatey, you'll see a path like C:\ProgramData\chocolatey\bin\npm.exe - DELETE it!
- Now install NodeJS using the appropriate MSI from https://nodejs.org/en/download/
- In your favourite shell, type
npm --version
- this should now echo the version of NPM that came with NodeJS (at the time of this writing, that version is 3.10.10)
This is what worked for me (goofy me!) I had (age ago) installed npm via chocolatey, which created a chocolatey initiated npm.exe in C:\ProgramData\chocolatey\bin\npm.exe. This was npm version 1.4.9 and wouldn't update no matter what one did including uninstall and reinstall NodeJs.
=======
EDIT: Better way to install node and npm
As of today (27/06/2017), the best way to install and manage node and npm is to install nvm (Node Version Manager) as explained here: https://github.com/coreybutler/nvm-windows. Once you have nvm, installing any node version is super easy:
- Open your favourite console (CMD, Cmder, PowerShell)
- Type
nvm install 6.10.2
(to install node version 6.10.2) - To see the currently active version, type
nvm list
. This prints something like below:
6.9.3
* 6.9.2 (Currently using 64-bit executable)
6.9.1
6.10.2