601

I tried this:

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

...but it didn't work.

How do I do this on Windows?

user56reinstatemonica8
  • 27,132
  • 16
  • 87
  • 109
Jatin
  • 13,582
  • 14
  • 46
  • 73
  • 3
    The usual procedure for updating software that doesn't have built-in autoupdaters is to download and install the latest version. Have you tried that? – JJJ Aug 23 '13 at 21:29
  • 9
    @Juhana I was thinking maybe there was some way to do it via npm as mentioned in that link. – Jatin Aug 24 '13 at 06:23
  • 1
    You can do it with Chocolatey. See my answer here for more info: http://stackoverflow.com/a/19915418/373655 – rob Apr 15 '14 at 18:08
  • 6
    So how are you using sudo on windows? http://superuser.com/questions/42537/is-there-any-sudo-command-for-windows – Aran Mulholland May 28 '16 at 16:05
  • 3
    `sudo` does not work on Windows... – Blairg23 Sep 07 '16 at 20:11
  • 1
    @rcdmk How can you mark this as a possible duplicate of a question that was asked a month later? – Barry Michael Doyle Oct 19 '16 at 10:22
  • 1
    @Barry The other question had better answers at that time. – Ricardo Souza Oct 19 '16 at 19:11
  • Tagging off topic. I don't see any programming related issue on this question – sandwood Apr 18 '18 at 09:44
  • 1
    @sandwood Please refer to the [help topics](https://stackoverflow.com/help/on-topic) before flagging things as off-topic. Note that questions about `software tools commonly used by programmers` are on-topic. – Beofett Apr 23 '18 at 19:30
  • 1
    I uninstalled, dowloaded the latest msi and reinstalled. I couldn't get other suggestions to work. Hope this helps someone. – anish May 27 '18 at 20:58

29 Answers29

2207

This is the new best way to upgrade npm on Windows.

Run PowerShell as Administrator

Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install -g npm-windows-upgrade
npm-windows-upgrade

Note: Do not run npm i -g npm. Instead use npm-windows-upgrade to update npm going forward. Also if you run the NodeJS installer, it will replace the node version.

user34612
  • 129
  • 2
  • 4
Robert Baker
  • 22,923
  • 1
  • 18
  • 19
  • 9
    Was having issues getting mine to upgrade, this script worked perfectly. Thanks. – atom0s Aug 05 '15 at 22:21
  • 8
    Microsoft recommends using this in their [nodejs-guidlines repo on github](https://github.com/Microsoft/nodejs-guidelines/blob/master/windows-environment.md#command-line-console-and-other-useful-tools). It also suggests tools for managing node versions. – Christopher Currens Dec 11 '15 at 21:51
  • 9
    This worked great for npm. thought I would mention, as the question itself is for updating node and npm, that to get both updated I had to uninstall / reinstall node, and run this upgrader as well (not sure if the node installer would have done it by itself as I did the upgrader first) – edencorbin Mar 02 '16 at 12:49
  • @edencorbin The node installer does not run this tool. Node picks a version of NPM to package in their installer. It's generally a few minor versions back than the latest. Node 5.6 bundles NPM 3.6, the latest is 3.8 right now. You most likely had to uninstall due to either a bug that was present (now fixed) or you manually updated npm at some point and most likely missed a critical step. You should not need to uninstall node/npm going forward. If you do, then I would wipe out the entire programfiles/node directory and %appdata%\npm after you uninstall. That should fix the problem permanently. – Robert Baker Mar 03 '16 at 22:05
  • Should this be expected to work through a corporate proxy? After your second line in Powershell, I get a little spinning baton on the command line and it runs for a long time (several minutes now) with no indication of what's happening. If that's normal, what's a rough timeline for this process, assuming a good internet connection and computer? Seconds? Minutes? Hours? Thanks! – SSilk Jul 25 '16 at 19:00
  • ... npm just answered that question for me. Need to set up a proxy. – SSilk Jul 25 '16 at 19:01
  • I wanted to try this solution, but there is something that makes me uneasy: there is label that says that the windows build status failed. What does that even mean?, and more importantly, should I care? – Edd Aug 13 '16 at 23:45
  • 1
    I am curious as to why the Powershell execution policy needs to be set to unrestricted for the current user for all time. If you're a little more paranoid you can just set it for the current process. Set-ExecutionPolicy Unrestricted -Scope Process -Force – knightpfhor Aug 31 '16 at 20:27
  • This would be better asked on the github repo. If you do it your way, you would need to do that everytime you want to run `npm-windows-upgrade`. By changing the execution policy, you don't need to do that every time. – Robert Baker Sep 06 '16 at 21:05
  • Do this after installing node.js msi, otherwise node.js msi will downgrade npm if not unselected during installation. – Ishan Sharma Sep 11 '16 at 10:04
  • 1
    I've just run the three commands above. npm has been udpated but node not. Is this expected? What can I do to update node to the latest version? – Piotr Berebecki Oct 10 '16 at 07:47
  • 2
    @PiotrBerebecki yes, that is expected. This just updates NPM. To get the latest node, go to nodejs.org, download and run the installer. Node comes with a version of NPM, usually a few minor versions back from the latest. You will need to run `npm-windows-upgrade`, as the node installer will overwrite npm. – Robert Baker Oct 10 '16 at 17:48
  • npm install -g npm-windows-upgrade -> is working for windows7 – Devang Solanki Oct 19 '16 at 13:48
  • @SSilk Yes, you need to setup a proxy for the `PwerShell` session, and sometimes even disable the dns check for this script with `-d` directive. After this worked for me. – VMAtm Nov 17 '16 at 19:57
  • It would be great if you could change "Officially recommended by the NPM team" to a link to the recommendation. – sky-dev Nov 30 '16 at 17:35
  • 138
    and what about node itself? – jenson-button-event Dec 11 '16 at 09:29
  • 1
    http://stackoverflow.com/questions/4037939/powershell-says-execution-of-scripts-is-disabled-on-this-system You will need to change permissions on powershell to get this script to run. `Set-ExecutionPolicy RemoteSigned` – jdeyrup Dec 23 '16 at 01:08
  • 2
    I tried on win 8.1 as admin. Got this error "scripts cannot be executed on this system" – NineCattoRules May 10 '17 at 10:53
  • But then again, one needs PowerShell. I'm not really into installing PowerShell just for upgrading Node. So I'd say this is the new best way *for PowerShell users*. – Neonit Jun 01 '17 at 07:45
  • When using Powershell I cannot use the arrow keys to select a version, but it works in cmd – Legends Jun 08 '17 at 10:23
  • 1
    Successfully updated upto v5.4.0, but I need v6 minimum. Any help? – Sivadass N Aug 31 '17 at 10:15
  • 5
    On Windows (10) PowerShell as Admin, `npm install -g npm-windows-upgrade` is fine, but `npm-windows-upgrade` gives *Scripts cannot be executed on this system*. – Leo Nov 11 '17 at 01:25
  • Did not work, because the first statemen is spelled wrong or could not be found – Yvonne Marggraf Nov 29 '17 at 11:13
  • 1
    This works up to Win 10 Fall creators update and most recent NPM, dont understand what other people are saying about it. – ConstantineK Dec 10 '17 at 16:11
  • 7
    This upgrades NPM version. I want to upgrade Node version. Everyone is lying here – Shahid Karimi Dec 29 '17 at 14:06
  • This upgrades the NPM version like mentioned on the question @ShahidKarimi – Luis Martins Jan 26 '18 at 13:17
  • (Feb 2018; it must be easier now!) This isn't necessary now. The best answer in today's world is from @josh3736. I commented there, too. – BaldEagle Feb 06 '18 at 07:24
  • Successfully upgraded to 5.7.1 – ChrisProsser Sep 21 '18 at 09:52
  • 27
    I followed the instruction, but when running "npm-windows-upgrade" I get the following error: `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.` – Ben Carp Sep 24 '18 at 16:10
  • As of Nov 2nd 2018, I ran the commands but did not upgrade my node. I ended up uninstalling node and installing it from the website. – William Pourmajidi Nov 02 '18 at 17:23
  • 1
    how do you upgrade node itself? – red888 Nov 29 '18 at 18:26
  • 1
    might want to run with --no-dns-check option if being behind a corporate proxy – user4447655 Dec 04 '18 at 04:15
  • 1
    @red888 First download the NodeJS version you need from https://nodejs.org/en/download/releases/. This installs its own packaged version of NPM. If you need to change the version of NPM then, from a *Run-as-Administrator* PowerShell prompt, you can run `npm install -g npm-windows-upgrade` followed by `npm-windows-upgrade -v WantedNpmVersion`. – AlwaysLearning Mar 05 '19 at 05:10
  • Worked for me after updating node version with latest LTE i.e. 10.15.3. Before that `npm-windows-upgrade` is not working for me. – S_K Mar 22 '19 at 10:26
  • In my case, Powershell was getting stuck while running npm-windows-upgrade and selecting the version to upgrade. I used cmd prompt in administrator and it did the job. However it only upgraded npm, not the node. – Vikash Gupta Apr 05 '19 at 07:36
  • @BenCarp try restarting your powershell as the environment variables are not up to date during that session. – vishal gaware Apr 05 '19 at 19:45
  • Actually this does not work if your versions of node/npm are sufficiently outdated. The `npm-windows-upgrader` scripts rely on language features (specifically, `async` functions) that are not supported until node 7.5+. The upgrader won't be working for you if your current versions are any older than that. – aroth Jun 20 '19 at 00:35
  • In the Windows 10 there are somes steps to do : 1. Run PowerShell like an Administrator 2. Execute `Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force` for rules 3. Run `npm install -g npm-windows-upgrade` 4. And after this `npm-windows-upgrade` – Dmitry Krychylskyy Jun 27 '19 at 06:17
  • Followed the instructions. I am getting this error-C:\Users\leena\AppData\Roaming\npm\node_modules\npm-windows-upgrade\src\upgrader.js:26 async ensureInternet () { ^^^^^^^^^^^^^^ SyntaxError: Unexpected identifier at Object.exports.runInThisContext (vm.js:76:16) at Module._compile (module.js:542:28) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) .. at Object. (C:\Users\leena\AppData\Roaming\npm\node_modules\npm-windows-upgrade\bin\npm-windows-upgrade.js:8:16) at Module._compile (module.js:570:32) – Leena Bhandari Nov 18 '19 at 02:32
  • I used `npm i -g npm` and it seemed to work. Why are you saying not to use it? – Qwertie Jan 16 '20 at 22:19
  • I had to run PowerShell as an Administrator – silentsudo Feb 18 '20 at 04:33
  • [@jenson-button-event](https://stackoverflow.com/users/220005/jenson-button-event) go to [node website](https://nodejs.org/en/) and download it from there – Mustapha-Belkacim Mar 10 '20 at 20:18
  • Why should we use this if official doc say to use `npm install npm@latest -g` as far I can see the git of npm-windows-upgrade is more than a year old :/, in which way is better than the official install? – Miao Apr 24 '20 at 09:04
  • 2
    I had to go to `C:\Users\{user_name}\AppData\Roaming\npm` and then run `.\npm-windows-upgrade` – Felippe Duarte Apr 29 '20 at 17:17
  • Doesn't work. I get `cb() never called!`. Not because this command is wrong, but because npm is wrong and needs to be updated. But using npm to update npm doesn't work here. – mcv Apr 28 '21 at 15:04
639

Download and run the latest MSI. The MSI will update your installed node and npm.

josh3736
  • 124,335
  • 26
  • 203
  • 248
  • 26
    Note 32 and 64 bit MSIs. Do not just click on "Windows Installer" link - that's 32 bit. Check where your current nodejs resides, in "Program Files" or on "Program Files (x86)". The "x86" means 32-bit. See the comments below about "old version was installed in a different directory". – tivnet Aug 06 '14 at 21:04
  • 49
    As of now (November 2014) this is will get you the latest node (0.10.33) but not the latest npm -- you will get npm 1.4.28. To update to a modern (2.x.x) npm on Windows, follow the instructions here: https://github.com/npm/npm/wiki/Troubleshooting#upgrading-on-windows – Sam Mikes Nov 13 '14 at 12:17
  • 1
    The node installer contains the latest version of npm that was available at the time of the node release. (on the 1.x branch) – josh3736 Jan 19 '15 at 17:57
  • Current MSI package installation for version 0.12.4 includes a NPM upgrade to version 2.10.1. To update NPM to the latest version follow Option 3 from [here](https://github.com/npm/npm/wiki/Troubleshooting#upgrading-on-windows). – James Jun 19 '15 at 18:34
  • Current MSI package installation for version 4.1.2 includes a NPM upgrade to version 2.14.4 – sergioviniciuss Oct 08 '15 at 02:12
  • MSI installed but didn't actually replace the only installation automatically. `npm install npm` worked for me. – BarryMode Apr 28 '16 at 19:34
  • I needed to update both npm and node (on a Windows box). I did the following (combining two of the answers above). 1. To update npm: npm install npm -g 2. To update node: go to https://nodejs.org/en/ and click the button to download the current version (v6.2.2 as of this date) You'll need this for Angular 2. – Rich Ward Jun 20 '16 at 15:51
  • I had to do something similar to @RichWard but I had to use the installer from this answer to upgrade node then `npm-windows-upgrade` to upgrade npm. – Twig Nov 23 '16 at 21:51
  • 2
    I would recommend uninstalling your current node version from "Programs and Features" first... – wayofthefuture Mar 08 '17 at 22:01
  • @wayofthefuture: Why? In my experience, that's entirely unnecessary. – josh3736 Mar 08 '17 at 22:03
  • Maybe, maybe not. I don't know how the installer works or what kind of recent coding changes have been made to it via GitHub recently. I like clean installs just my preference... – wayofthefuture Mar 08 '17 at 22:06
  • Is the exectution policy thing (and the use of npm-windows-upgrade) necessary also if using Git Bash (installed together with Git for Windows) to upgrade and run npm instead of Powershell? Or would running Git Bash as Administrator during the upgrade be enough? – herman Oct 04 '17 at 08:24
  • 3
    (Feb 2018; it must have gotten easier!) I've been working with Node and npm for a couple years. I get Node msi's from nodejs.org. Each msi I've used has upgraded from an older Node version without complaint or notice. Recent Node msi's have included an npm, though sometimes an old npm. https://docs.npmjs.com/troubleshooting/try-the-latest-stable-version-of-npm says `npm install -g npm` works. I've done it; I haven't had difficulty. Very recently, I upgraded Node and got the current npm, too. – BaldEagle Feb 06 '18 at 07:19
  • I think the whole reason this question and these answers exist is because the nodejs documentation is terse and doesn't explicitly say anything about upgrading from older versions. I just installed over my version with the latest MSI and it worked fine. It noticed my existing node path statements and the installation didn't add new ones. Did it leave files from my old installation that are not in the new installation? I expect if any such files exist, it did leave them in place. That shouldn't harm the new installation, but is wasted space. – KSev Aug 23 '19 at 17:17
  • WOW !! Thankyou so so much .. I have been trying all possible commands but finally this one worked – Sucheta Shrivastava Sep 29 '19 at 11:20
  • This will work even if you are behind a proxy while the other solutions doesnt. – Sisir Jun 22 '20 at 18:28
131

To update NPM, this worked for me:

  • Navigate in your shell to your node installation directory, eg C:\Program Files (x86)\nodejs
  • run npm install npm (no -g option)
Gal Margalit
  • 4,483
  • 5
  • 40
  • 51
meetar
  • 6,683
  • 7
  • 39
  • 68
  • 7
    This is actually one of the recommended approaches on Windows: https://github.com/npm/npm/wiki/Troubleshooting#upgrading-on-windows – grenade Jan 06 '15 at 12:01
  • 3
    This worked for me after I had updated node via the accepted answer. – Jamie Hutber Feb 01 '15 at 22:49
  • 3
    @singe3 The command prompt must be elevated (started as Admin) to be able to modify C:\Program Files. I don't really like this method because "npm install -g" will try to install under Program Files, thus the cmd prompt must always be run elevated to install other global packages. Option 2 in grenade's link is better IMHO: delete Program Files\nodejs\npm.cmd so it'll use the user's local npm. – pmont Aug 15 '15 at 13:53
  • Simple and functional – Rafael Gomes Francisco Sep 04 '15 at 15:27
  • 23
    I needed to use `npm install npm@latest` – TryingToImprove Feb 16 '16 at 22:14
  • 1
    @TryingToImprove You should uninstall node, delete program files\node and %appdata%\node. ReInstall node. Then use npm-windows-upgrade (see my answer). npm-windows-upgrade is the best solution and does not have the pitfalls like the other answers here. The pitfall you have is now 2 npm versions on your system and depending on if the npmrc file, you could have multiple global packages and inconsistency. Like updating a global package but still getting the old version... – Robert Baker Mar 03 '16 at 22:11
  • This doesn't update node, it installs npm into the local `.\node_modules\` relative to where you execute it. – Marc Oct 16 '16 at 13:39
  • This gave me the same errors as running just `npm install -g npm`. What worked for me: Create a new folder directly under the drive (eg `C:/Temp1`), run `npm install npm` in it, then copy the contents into the correct locations in the global npm install directory. (eg copy `C:/Temp1/node_modules/npm/bin/node.cmd` to `C:\Program Files\nodejs\node.cmd`, and `C:/Temp1/node_modules/npm` to `C:\Program Files\npm` -- since it's expecting it a level higher) Not the most elegant, but works. – Venryx May 29 '18 at 09:08
  • I have multiple users on my windows. And, `npm install npm` is best option. `npm-windows-upgrade` will only update npm copy of Administrator account. while `npm install npm` will work for different user account – Manjeet Aug 02 '18 at 06:10
80

Like some people, I needed to combine multiple answers, and I also needed to set a proxy.

This should work for anyone. I have zero desire to run an EXE file or MSI file .. uninstall/ reinstall, or manually delete files and folders. That is so 1999 :P

  1. Run this to update NPM:

    Run PowerShell as administrator

    npm i -g npm    // This works
    

    I am not thinking this code actually upgrades your npm version below

    Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
    npm install -g npm-windows-upgrade
    npm-windows-upgrade
    
    (courtesy of "Robert" answer)
    

Run this to update Node.js:

wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'C:\Program Files (x86)\nodejs\node.exe'    (courtesy of BrunoLM answer)

If you get `wget : Could not find a part of the path .... "**, see below ...scroll down. Reading Web Response... It's at least punching through the firewall /proxy (if you have one or have already ran the code get through ...

Otherwise

You might need to set your proxy

npm config set proxy "http://proxy.yourcorp.com:811"    (yes, use quotes)

2 possible errors

  1. It cannot find path of the path solution "where.exe node" (courtesy of Lonnie Best Answer)

    E.g. if Node.js is NOT living in "Program Files (x86)" perhaps with where.exe, it is living in 'C:\Program Files\nodejs\node.exe'.

    wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'C:\Program Files\nodejs\node.exe'
    
  2. Now perhaps it tries to upgrade but you get another error, "node.exe is being used by another process."

    • Close /shutdown other consoles .. command prompts and PowerShell windows, etc. Even if you're using npm in a command prompt, close it.

npm -v (3.10.8)

node -v ( v6.6.0)

DONE. I'm at the version that I want.

Tom Stickel
  • 16,699
  • 6
  • 102
  • 108
  • 3
    My node is in `c:\Program Files\nodejs` – malix Aug 24 '17 at 14:43
  • 1
    This is the only answer that could still work (others looks pretty old and deprecated) and thanks god it works. – omer.ersoy Jan 04 '18 at 14:20
  • After deleted previous version of nodejs instance( like from program files, user data etc). It was giving me error like a previous version of nodejs is already install when i was trying to install 8.x version of nodejs. It solved my problem. – No one Mar 14 '18 at 13:56
  • This will work only for node version greater than 8.0.0, mine is 6.x.x. It is not working for me. I wanted upgrade on ADO agent – paul Oct 06 '20 at 11:16
62

You can use Chocolatey which is a package manager for windows (like apt-get for Debian Linux).

Install fresh (you might need to uninstall previously installed versions)

> choco install nodejs

Update to the latest version

> choco update nodejs

and for npm

> choco update npm
Ahmad M
  • 1,063
  • 1
  • 11
  • 5
  • 8
    `choco update npm` is deprecated. Use `npm-windows-upgrade` to update npm. https://github.com/felixrieseberg/npm-windows-upgrade – Robert Baker Mar 07 '16 at 22:43
  • 2
    @Robert choco update command is deprecated but we still can use choco upgrade command – Aqib May 19 '16 at 11:13
  • 3
    @Aqib the package npm is deprecated in chocolatey. See https://chocolatey.org/packages/npm – Robert Baker May 20 '16 at 17:49
  • 3
    Followed this advice and chocolatey installed an incredibly old version of npm which overrode my slightly-old version, causing very bad things to happen. – uglycoyote Jul 05 '17 at 04:55
60

You can update your npm to the latest stable version with the following command:

 npm install npm@latest -g

Use PowerShell to run it. This command doesn't need windows administrator privileges and you can verify the result with npm -v

Juan David
  • 2,389
  • 4
  • 23
  • 35
  • 6
    Simplest and best answer for updating npm – nathanchere Jan 02 '17 at 13:55
  • 2
    If you have *nodejs* installed, there are **two** version of npm installed on Windows. Running `npm install npm@latest -g` only update the global ( `-g` ) installed one ( %appdata%\npm\ ). To update npm that comes with nodejs ( %ProgramFiles%\nodejs\node_modules\npm ) you can download the .msi installer from https://nodejs.org/en/ and run it. Other official methods to upgrade npm: https://github.com/npm/npm/wiki/Troubleshooting#upgrading-on-windows – pldg May 11 '18 at 20:19
  • 1
    Worked for me. Thank you :) – mudrak patel Jul 04 '18 at 18:21
  • Worked for me :) – Mayank Pandeyz Aug 22 '18 at 16:41
  • This seems like the best answer because of its simplicity. – Mike Poole May 21 '19 at 10:30
  • Worked for me with small change. I wanted to specify a version when upgrading. So i used this: npm install npm@latest -g – Ish Dec 01 '20 at 06:10
25

The previous answers will work installing a new version of Node.js (probably the best option), but if you have a dependency on a specific Node.js version then the following will work: "npm install npm -g". Verify by running npm -v before and after the command.

Enter image description here

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Will Lopez
  • 1,907
  • 2
  • 31
  • 51
22

This works fine for me to update npm on Windows 7 x64:

  • Windows start
  • All Programs
  • Node.js
  • Node.js command prompt (alternative click)
  • Run as administrator

    $ npm -g install npm

  • remove C:\Program Files\nodejs\npm.cmd the new npm will be at C:\Users\username\appdata\roaming\npm\npm.cmd

Hope this helps.

naXa
  • 26,677
  • 15
  • 154
  • 213
bohem.be
  • 1,577
  • 1
  • 13
  • 17
  • 2
    This solution modifies the nodejs directory, leaving behind an orphaned npm. If you have more than 1 user on the machine, you just broke NPM for everybody else. This method also causes problems with global packages. the npm installed via this answer does not have the npmrc file, so global packages going forward will likely be installed in the wrong directory. If you update node, the nodejs/npm.cmd is now restored. So if nodejs updates npm, you are stuck on the old one unless you run that command again. – Robert Baker Mar 07 '16 at 22:21
18

Open PowerShell as administrator.

To install a first time you can use this small script to download the latest msi and run it

$nodeLatest=((curl https://nodejs.org/download/release/latest/).Content | findstr x64.msi) -replace "<(.*?)>", "" -replace "\s+.+", "";
wget "https://nodejs.org/download/release/latest/$nodeLatest" -OutFile (join-path $env:TEMP node.msi); Start-Process (join-path $env:TEMP node.msi)

On future upgrades you can download just node.exe and update npm with

wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'C:\Program Files\nodejs\node.exe'
npm i -g npm

You should now have the latest node and npm.


I went a little further and decided to implement a nvm for Windows.

https://github.com/brunolm/nvm

Install-Module -Name power-nvm

nvm install latest
nvm default latest
BrunoLM
  • 88,362
  • 76
  • 272
  • 427
  • Excellent answer. Many would of course use `C:\Program Files\nodejs\node.exe` for the last part. – arviman Apr 12 '17 at 08:47
14

1. Installing latest npm version

npm install –g npm@latest 

(You can type "npm –version" to check that)


2. Installing Node

a. Install node new version via following URL: https://nodejs.org/en/download/current/ Follow the default choices
b. Remove C:\Users\\AppData\Roaming\NPM
c. Remove C:\Users\\AppData\Roaming\npm-cache


Optionally:

d. (Delete node_modules folder in your current project folder)
e. npm cache verify
f. npm install

ofir_aghai
  • 2,223
  • 1
  • 28
  • 33
  • This worked for me..You might need to use npm rebuild node-sass --force after you are done with installation because your environment has changed – Abx Jun 14 '18 at 09:09
13

Use Upgrade npm on Windows

This is the official document for a user to upgrade npm on Windows!

Here is my screenshot!

Enter image description here

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
xgqfrms
  • 5,516
  • 1
  • 37
  • 42
  • **msi** is also another choice! – xgqfrms Jan 01 '17 at 12:31
  • From the page you linked to: "This is a small tool made by Microsoft DX engineers". So saying "this is the official document" is maybe a bit misleading. It sounds like you're saying it's official from the node or npm folks. – jinglesthula Feb 21 '17 at 17:27
10

For what it's worth, I had to combine several answers...

  1. Uninstall Node.js in control panel Add/remove programs.
  2. Delete directories, both C:\Program Files (x86)\nodejs\ and C:\Program Files\nodejs\ if they exist.
  3. Install the latest version, http://nodejs.org/download/
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Tim
  • 3,136
  • 4
  • 36
  • 55
  • Can you remember anything specific _why_ you had to do this? I just tried it with downloading, installing and it worked instantly. – amenthes Aug 05 '14 at 12:22
  • No, But i think that the older version of node installed it in a different windows directory in the path. At least thats my assumption – Tim Aug 06 '14 at 13:18
9

How to Update Node.js:

  1. Uninstall Node.js. Click the Start menu, type "Change or Remove a Program", click on the item shown, find Node.js in the list and uninstall it.

  2. Delete directories, both C:\Program Files (x86)\nodejs\ and C:\Program Files\nodejs\ if they exist.

  3. Install the latest, https://nodejs.org/en/download

    The uninstall/delete/install seems unnecessary, but it often is and this will save your time.     These instructions come from Microsoft.

How to Update NPM:

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

    This is the official documentation for upgrading npm on windows.

All was tested and working on Windows 10 (2017).

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
whitneyland
  • 9,968
  • 8
  • 55
  • 65
7

this is best tool to maintain version of NODE.Js i NVM

Node Version Manager (nvm) for Windows but for Windows, with an installer. Download Now! This has always been a node version manager, not an io.js manager, so there is no back-support for io.js. However, node 4+ is supported. enter image description here

Adiii
  • 35,809
  • 6
  • 84
  • 87
5

For me, after totally uninstalling node. 10.29, and then installing node 4.2.2, there remained a 10.29 node.exe file in my c:\windows folder.

I found this by using the following command:

where.exe node

The command returned:

C:\Windows\node.exe
C:\Program Files\nodejs\node.exe

So even though I had successfully installed version 4.2.2 via the msi executable, the command "node -v" would continue to return 10.29.

I resolved this by deleting this file:

C:\Windows\node.exe
Lonnie Best
  • 6,765
  • 9
  • 44
  • 81
5

For NodeJS

Download required node version msi from here and install

for Npm

Run PowerShell as Administrator

Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install -g npm-windows-upgrade
npm-windows-upgrade
manish kumar
  • 3,629
  • 2
  • 30
  • 44
4

I followed @josh3737 and installed the latest MSI from the node.js homepage.

But I had the additional problem that I still had the old node and npm on the command line. The problem was caused by the new installation, that it was installed into

C:\Program Files (x86)\nodejs\

instead of the previous installation in

C:\Program Files\nodejs\

The new installation added the new directory into my path variable after the old one. So the old installation was still the active one in the path. After removing C:\Program Files\nodejs\ from system path and C:\Users\...\AppData\Roaming\npm from user path and restarting the command line the new installation was active.

Maybe the least path was a local problem that has nothing to do with the new installation, I had two links to AppData\Roaming\npm in it. And maybe this can also be fixed by first uninstalling node.js and installing the new version afterwards.

crackmigg
  • 4,576
  • 2
  • 26
  • 37
4

I was also facing similar issues. I followed below mentioned steps and it worked for me:

  • go to Windows > Start > Node.js

    • right click on Node.js command prompt
    • click on Run as administrator
  • ping registry.npmjs.org

  • npm view npm version

  • cd %ProgramFiles%\nodejs

  • npm install npm@latest

and npm updated successfully. Earlier I was trying for CMD and that was throwing error. may be some path issue that got resolved by running NodeJs Command Prompt. hope it'll work for you. try this.

cilerler
  • 7,774
  • 8
  • 51
  • 81
skakkar
  • 69
  • 1
4

This works fine for me

  1. Run Command Prompt as Administrator

  2. Navigate to the folder containing nodejs (eg. C:\Program Files\nodejs)
  3. Run Powershell -ExecutionPolicy Unrestricted

  4. Run npm-windows-upgrade

  5. This will show list of versions available to install. Just select your desired version by moving up/down key & Press Enter.

    This'll update your npm
  6. To check the current version of npm

    Run npm --version

Command Prompt Screenshot

4

OK guys, I read (tried on Windows) all the previous stuff and all of these answers have their own disadvantages.

For the best way to update Node.js (at least for me), go to https://nodejs.org/en/ Then download the last version and install it in same folder you installed the previous version in - 1 min and it's done. You don't need to remove any old files.

Then update npm typing in cmd: npm install --save latest-version

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Vasyl Gutnyk
  • 4,153
  • 2
  • 29
  • 35
4

To install the updates, just download the installer from the Nodejs.org site and run it again. The new version of Node.js and NPM will replace the older versions.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Suresh Sapkota
  • 139
  • 3
  • 7
4

The easiest way I found so far to update Node.js is using Chocolatey. Use Chocolatey to install or update the latest version of Node.js on Windows:

Step 1: First, ensure that you already have Chocolatey installed. If not, use an administrative shell to install chocolatey through cmd.exe or PowerShell.exe. For more information, visit: https://chocolatey.org/docs/installation

Step 2: Install with cmd.exe. Run the following command:

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

To install with PowerShell.exe, visit: https://chocolatey.org/docs/installation

Step 3: Install or Update with following commands on cmd.exe (on administrative mode)

To Install Node.js: cinst nodejs.install

To Update Node.js: cup nodejs.install

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Anjy
  • 81
  • 9
4

follow these steps for window 10 or window 8

  • press WIN + R and type cmd and enter
  • npm i -g npm@next
  • npm i -g npm@next OR npm i -g node@{version}
  • Remove environment path C:\Program Files\nodejs from envrionment variable PATH.
  • type refreshenv in cmd

Now you will have your new version which you installed.

Note: If you don't remove path. You will see the previous version of node.

Hafiz Shehbaz Ali
  • 2,306
  • 21
  • 20
2

Powershell does not execute npm directly, I suggest using

.\npm install -g npm-windows-upgrade
.\npm-windows-upgrade

and it failed with:

You wanted to install npm 6.1.0, but the installed version is 3.10.10.

A common reason is an attempted "npm install npm" or "npm upgrade npm". As of today, the only solution is to completely uninstall and then reinstall Node.js. For a small tutorial, please see http://aka.ms/fix-npm-upgrade.

Please consider reporting your trouble to http://aka.ms/npm-issues.

http://aka.ms/fix-npm-upgrade <-- this is a dead link

eyllanesc
  • 190,383
  • 15
  • 87
  • 142
Serge B
  • 31
  • 2
1

You can use these commands:

npm cache clean
npm update -g [package....]

If you are upgrading from a previous version of node, then you will want to update all existing global packages. You can also specify the package name to be updated.

Jitendra Pawar
  • 989
  • 12
  • 23
1

This might help someone. Neither "npm-windows-upgrade" nor the installer alone did it for me. Powershell was still using an older version of node and npm.

So this is what I did (worked for me): 1. Download the latest installer from nodejs.org. Install node. It will update your node; everywhere (Powershell, cmd etc.). 2. Install the npm-windows-upgrade package (npm install -g npm-windows-upgrade) and run npm-windows-upgrade.

I didn't uninstall anything and didn't set any paths.

robinhood9
  • 127
  • 1
  • 5
  • 1
    "Powershell was still using an older version of node and npm." You likely did some other update method in the past by modifying the path or running npm i -g npm. If you run into any issues in the future then you must do this: https://github.com/felixrieseberg/npm-windows-upgrade#fix-an-attempted-upgrade – Robert Baker Aug 31 '16 at 19:04
1

In my case, I discovered that I had two copies of Node.js installed. One under "C:\Program Files\nodejs" and another under "C:\Program Files (x86)\nodejs".

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Anthony
  • 4,965
  • 9
  • 45
  • 78
0

This is what worked for me.

  1. Open a local folder other than the one in which nodejs is installed.
  2. Install npm in that folder with command npm install npm
  3. Navigate to the folder containing node js. (C:\Program Files\nodejs\node_modules)
  4. Delete the npm folder and replace it with the npm and bin folders in the local folder.
  5. Run npm -v. Now you would get updated version for npm.

Note: I tried installing npm directly in "C:\Program Files\nodejs\node_modules" but it created errors.

Nithin Baby
  • 7,236
  • 4
  • 16
  • 24
0
  1. Start
  2. Search for windows powershell
  3. Right click and run as administrator
  4. Type: where.exe node (returns the path of node.exe in your system. Copy this)
  5. wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'PATH-OF-NODE.EXE_WHICH_YOU_COPIED_JUST_NOW'
  6. To check if it has worked, go to your Git bash/Normal command prompt and type: node -v
  7. Here you can find the current version of node: https://nodejs.org/en/blog/release/
Kshri
  • 218
  • 2
  • 13