Updating npm when using nvm-windows

Peter T. picture Peter T. · Feb 12, 2019 · Viewed 10.6k times · Source

I'm using nvm-windows version 1.1.7.

I just installed node 11.9.0.

nvm installs npm version 6.5.0 together with this node version. However, there's npm version 6.7.0 available already.

When I now do npm i -g npm I get:

npm ERR! path C:\Program Files\nodejs\npm.cmd
npm ERR! code EEXIST
npm ERR! Refusing to delete C:\Program Files\nodejs\npm.cmd: is outside C:\Program Files\nodejs\node_modules\npm and not a link
npm ERR! File exists: C:\Program Files\nodejs\npm.cmd
npm ERR! Move it away, and try again.

I found no way to avoid this.

Answer

Ryan Shillington picture Ryan Shillington · Mar 10, 2019

This is a duplicate from my answer here: https://stackoverflow.com/a/50955293/491553

Here is how I upgrade npm when running nvm-windows:

cd %APPDATA%\nvm\v8.10.0           # or whatever version you're using
mv npm npm-old
mv npm.cmd npm-old.cmd
cd node_modules\
mv npm npm-old
cd npm-old\bin
node npm-cli.js i -g npm@latest

And boom, upgraded.