I recently had to update the NPM version on my laptop to a never version (because I wanted to use NPX – for avoiding globally installing and updating create-react-app).
I started by downloading the latest LTS version of Node (which at the time of writing includes NPM version 5.6.0). Ran the installer and found Node to have been updated – but not NPM. NPM was still at 3.10.5.
Stack Overflow to the rescue!
Google led me to this reply on Stack Overflow which describes the process as
- Launch PowerShell as an Administrator and run the following commands
- If you are not an Administrator, or if your administrative account is different from your normal user account, then see the notes regarding this below.
- Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
- npm install -g npm-windows-upgrade
- npm-windows-upgrade
Notes
If you would like to reset the ExecutionPolicy afterwards, then run Set-ExecutionPolicy Undefined -Scope CurrentUser -Force. Undefined is the default value for the CurrentUser scope.
This way of updating is the recommenced solution by Microsoft and the NPM Team.
Not an Administrator?
Use any account that has administrative rights to launch PowerShell as an administrator. Then run step 2 and 3 as described above. In step 4, define the location of the NPM to update by using the –npm-path argument. Example: npm-windows-upgrade –npm-path “C:\Users\XXXX\AppData\Roaming\npm”.