Reputation: 3315
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.
Upvotes: 74
Views: 45242
Reputation: 25088
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\v14.20.0 # or whatever node version you're using
move npm npm-old
move npm.cmd npm-old.cmd
move npx npx-old
move npx.cmd npx-old.cmd
cd node_modules\
move npm npm-old
cd npm-old\bin
node npm-cli.js i -g npm@latest --force
And boom, upgraded.
Upvotes: 88
Reputation: 1098
I tried the script and other solutions, this by far is the easiest way:
cd C:\Users\yourUser\AppData\Roaming\nvm\vxx.xx.x
)npm2 install -g npm@your-version
Upvotes: 4
Reputation: 109
I faced this problem today, the way i solved it was installing latest node with nvm then copying the npm files from latest to the version i am on.
nvm install latest
cd AppData/Roaming/nvm/LATEST
xcopy npm.cmd ../LTS && xcopy npm ../LTS && xcopy node_modules/npm ../LTS
I then confirmed it working by trying to compile my code that breaks on latest.
Upvotes: 1
Reputation: 1813
For me I only get the problem when updating npm with npm v6.
So using a newer version of npm via npx to run the upgrade works for me.
For the very newest version
npx npm install -g npm
Or use a specific version
npx npm@7 install -g npm@7
Upvotes: 3
Reputation: 2814
Several workarounds are available in this Issue on the nvm-windows
github repo:
https://github.com/coreybutler/nvm-windows/issues/300
There are examples using DOS, PowerShell, bash, and batch scripts.
Upvotes: 22
Reputation: 91
I had to force it :-/
When it came to
node npm-cli.js i -g npm@latest
I'd rather had to use
node npm-cli.js i -g npm@latest --force
probably to overcome a permission error involved in overwriting the "C:\Program Files\nodejs" link.
Upvotes: 7
Reputation: 430
I also found it necessary to install windows-nvm
to c:\nvm
and c:\nodejs
to prevent issues with unsupported paths with spaces.
rm C:\nodejs\npm*
rm C:\nodejs\npx*
mv C:\nodejs\node_modules\npm C:\nodejs\node_modules\npm-old
node C:\nodejs\node_modules\npm-old\bin\npm-cli.js i -g npm@next
Upvotes: 2
Reputation: 1024
This worked for me:
curl -L https://npmjs.org/install.sh | sh
If you already have git bash installed, use it there.
Upvotes: -2
Reputation: 7383
updateNpm.bat latest
Upvotes: 7
Reputation: 623
I have windows 10 operating system.
I installed in following way.
cd %APPDATA%\nvm\v8.11.3
move npm 5.6.0
move npm.cmd 5.6.0.cmd
cd node_modules\
move npm 5.6.0
cd 5.6.0\bin
node npm-cli.js i -g npm@latest
Upvotes: 12