86

When I install node 0.10.33 from the msi ( http://nodejs.org/download/ ), I get an old version of npm (1.4.28). How can I upgrade npm on Windows?

npm install -g npm

does not work; I still have the old npm.

Sam Mikes
  • 10,438
  • 3
  • 42
  • 47
  • You could also view the answers to the question on: http://stackoverflow.com/questions/18412129/how-do-i-update-node-and-npm-on-windows – bohem.be Feb 12 '15 at 10:13
  • @bohem.be - that addresses how to update `node` on Windows, which is useful; but this question/answer is about how to update `npm`. – Sam Mikes Mar 20 '15 at 15:26
  • for as far as I know, npm is a part of the node update or installation (Node Package Manager) – bohem.be Mar 23 '15 at 07:41
  • This is my last answer sinse this is not a discussion board. Please check this http://stackoverflow.com/questions/9237715/what-does-npm-mean-for-socket-io-installing-stuff. And also re-read my answer to http://stackoverflow.com/questions/18412129/how-do-i-update-node-and-npm-on-windows and you will see I am updating npm and not node. – bohem.be Mar 30 '15 at 10:11
  • "it's an unfortunately common misconception that the acronym stands for "node package manager"." – Sam Mikes Mar 30 '15 at 12:26

13 Answers13

161

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

dolpsdw
  • 78
  • 5
Sam Mikes
  • 10,438
  • 3
  • 42
  • 47
  • 1
    This is the problem that I've been facing for weeks, now it's solved :) Thanks for the answer ! – sonlexqt Jan 20 '15 at 17:28
  • 1
    The key piece here is once you've done of the above, restart your shell so that it switches from the version installed in the node folder to the one installed in the AppData folder – Kyle Chadha Apr 24 '15 at 23:52
  • 1
    Reco for Option 3 ... Copy/Paste : cd /c/'Program Files/nodejs' && npm install npm@latest – benek Sep 10 '15 at 12:22
  • 2
    npm install npm@latest worked great except on the clients that were still < 2.0 – beauXjames Nov 30 '15 at 23:40
  • Why not using the `-g` flag with the `npm install npm@latest` approach ? It worked for me with the `-g` flag, while none of the rest did – Overdrivr Feb 15 '18 at 10:16
47

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
josliber
  • 43,891
  • 12
  • 98
  • 133
Felix Rieseberg
  • 712
  • 5
  • 2
  • 1
    It needs powershell. What if I can't run powershell scripts downloaded from internet and I don't have privileges to change the settings? I suppose I need to create certificate and sign it. To much headache – rofrol Nov 08 '15 at 18:46
  • 1
    I followed all of the steps and all I get is an error: PS C:\Windows\system32> npm-windows-upgrade npm-windows-upgrade : The term 'npm-windows-upgrade' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + npm-windows-upgrade + ~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (npm-windows-upgrade:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException – Dan Csharpster May 03 '16 at 18:42
  • 1
    I'm having the exact same problem as @DanCsharpster following all the steps for Powershell as Admin. – Wesley Musgrove Sep 09 '16 at 16:19
  • 2
    Correction: I **was** having the exact same problem as @DanCsharpster following all the steps for Powershell as Admin, but this issue was fixed by adding C:\Users\UserAdmin\AppData\Roaming\npm to my PATH, closing Powershell and reopening it as Admin. – Wesley Musgrove Sep 09 '16 at 16:25
  • Was have the same issue as Dan and Wesley. Was able to resolve it with Wesley's tip above. – Loathian Mar 07 '17 at 21:54
  • Hi Felix, I noticed you archived the repository for this project recently. Do you no longer recommend for people to use your tool? If that's the case, would you mind updating the front page of your repo to tell people what you suggest using instead? – Coderer Sep 20 '21 at 10:03
15

There May be many ways to update your npm in Windows

Way 1

  1. Open you power shell as Administrator and run following commands step by step.
  2. Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
  3. npm install -g npm-windows-upgrade
  4. npm-windows-upgrade
  5. Here you can select your preferred version of npm
  6. Ready to go !

Way 2

  1. You can simply upgrade to the latest npm version with following command
  2. npm install npm@latest -g
  3. or if you want a specific version of npm simply run
  4. npm install npm@{version} -g for example npm install npm@3.3.12 -g

Now simply run npm --version or npm -v to know your current version of npm

3.3.12 is my preferred version of npm that best suits for approximately every package.

UPDATE

npm install npm@latest -g

the correct npm version is now already shipped with node.js so you can directly switch node version. you can nvm (Node Version Manager) package to switch node versions very quick and easy.

Vivek Maru
  • 8,347
  • 1
  • 24
  • 34
7

So, TL;DR; this worked:

  1. Uninstall node

  2. From a command prompt, run where npm

  3. If you had npm installed via chocolatey, you'll see a path like C:\ProgramData\chocolatey\bin\npm.exe - DELETE it!
  4. Now install NodeJS using the appropriate MSI from https://nodejs.org/en/download/
  5. 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:

  1. Open your favourite console (CMD, Cmder, PowerShell)
  2. Type nvm install 6.10.2 (to install node version 6.10.2)
  3. 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
Sudhanshu Mishra
  • 6,523
  • 2
  • 59
  • 76
  • 1
    You saved my day!! I had the same problem. I have installed nodejs using chocolatey and i could not upgrade npm version. – dsmyrnaios Mar 01 '17 at 21:07
3

It's late 2021 and a lot of these answers can be confusing. npm install -g npm can break your installation. (When I did this, I had to run the Node MSI "Repair" tool to get it working again.) npm-windows-upgrade has not seen a release in over 2 years, and the repo has been archived by its maintainer.

As far as I can tell, there are two options that seem to work reliably today.

  • Use where npm from DOS prompt or which npm from WSL / Git Bash / etc, to determine which NPM binary is being used.
  • cd to that path, then run npm install npm@latest (without the -g flag!). npm update npm should have the same effect. You may need an elevated prompt (Run As Administrator).
  • Verify that this worked by running npm --version.

This worked for me. The other option is:

  • Completely uninstall NPM + Node using the Add/Remove Programs settings page.
  • Install an MSI from the Node website.
Coderer
  • 25,844
  • 28
  • 99
  • 154
2

To upgrade NPM on windows 10

  1. Uninstall Node.js
  2. Restart your system
  3. on command prompt type where npm
  4. delete if npm and npm-cache folder exists in AppData/Roaming
  5. Install Node.js (https://nodejs.org/en/)
vinay k hegde
  • 243
  • 4
  • 18
1

You need to follow the Windows upgrade instructions

https://www.npmjs.com/package/npm-windows-upgrade

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.

  1. Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
  2. npm install --global --production npm-windows-upgrade
  3. npm-windows-upgrade

Want to just install the latest version? 1.npm-windows-upgrade --npm-version latest

Ganesh Apune
  • 197
  • 1
  • 6
0

I did something similar to Sam Mikes. I'm only sharing this because I couldn't get either of his solutions to work on my rig. After a bit of playing around, this is what worked for me:

  1. Remove NPM/Node from your Environment Variables, both for user and system.
  2. Close your open console if you have one open, then open a console as administrator
  3. Change directories to %USERPROFILE% -- that's a window's environment variable that takes you to C:\Users\CurrentlyLoggedInUser
  4. Run from the console in %USERPROFILE%, "C:\Program Files\nodejs\npm" install npm -g (you might have yours in the x86 folder)
  5. If this solution would work for you, step 4 would have worked, and npm -v will show a an up-to-date version
  6. Re-add Node (in Program Files)/NPM (in App Data -- the one installed in Program Files should be the old one) to your user and system environment variables

Note: I've used the Microsoft automated script in the past to fix this, but only because I didn't realize how easy it would be to do it myself.

kayleeFrye_onDeck
  • 6,648
  • 5
  • 69
  • 80
  • Hah! So I had upgraded, and then needed to downgrade and ran into this issue again... I initially wrote this answer for LTS 4.2.3, and it works for LTS 4.4.0 – kayleeFrye_onDeck Mar 21 '16 at 20:23
0

So none of the previous answers solved the issue for me so I thought I would post my specific solution, which I managed to figure out by going through all the other answers so they were really helpful.

My issue was because I had used chocolatey to install node and possibly npm (looking at chocolatey site now I shouldn't have done that).

To solve the issue I simply had to run the relevant choco uninstall commands for npm and node and then everything switched to the other version of node which I had also installed using the node msi (from node's website).

I hope that helps anyone else that may have gone down the same path as me.

Ben Thomson
  • 1,083
  • 13
  • 29
0

I tried almost every answer but none of them works my way.
Neither npm-windows-upgrade worked nor did the npm install npm@latest etc etc worked.
For people like me I will suggest you guys downloading the latest installer from Node.js website, let the existing version of node directory be on it's place and without changing anything just install the msi installer and you will end up with an upgraded version of node.
My case was upgrading node from 6 to 8.9.3

haMzox
  • 2,073
  • 1
  • 12
  • 25
  • There are many ways to upgrade. I once wasted my whole working day on it. If you are facing the same issue, go with my solution. – haMzox Jun 27 '18 at 06:19
0

all npm install commands were getting stuck and will throw error (behind proxy error) after sometime. setting up proxy was not helping. This is what I did.

Had 8.11 nodeJS

  1. Uninstalled NodeJS from Programs & Features with the uninstaller.
  2. Reboot (or you probably can get away with killing all node-related processes from Task Manager).
  3. Look for these folders and remove them (and their contents) if any still exist. Depending on the version you installed, UAC settings, and CPU architecture, these may or may not exist: • C:\Program Files (x86)\Nodejs • C:\Program Files\Nodejs • C:\Users{User}\AppData\Roaming\npm (or %appdata%\npm) • C:\Users{User}\AppData\Roaming\npm-cache (or %appdata%\npm-cache) • C:\Users{User}.npmrc (and possibly check for that without the . prefix too)
  4. Check your %PATH% environment variable to ensure no references to Nodejs or npm exist.
  5. If it's still not uninstalled, type where node at the command prompt and you'll see where it resides -- delete that (and probably the parent directory) too.
  6. Reboot, for good measure.

Installed 6.11 nodejs then it worked.

-1

Use npm-windows-upgrade tool to simply upgrade. Steps are provided in the link.

ravthiru
  • 8,878
  • 2
  • 43
  • 52
-3

For update node npm on Windows

I have to delete node in:

C:\Users**YOUR USER**\AppData\Roaming

And reinstall node

Batusy
  • 11
  • 3