Refusing to delete npm.cmd ERR in NVM for Windows
Error
When installing npm globally in NVM for Windows, theEEIXST error occurs.
C:\windows\system32>npm i -g npm@latest
npm ERR! code EEXIST
npm ERR! path C:\Program Files\nodejs\npm.cmd
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! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.
Solution
- Run CMD(Command Prompt) as administrator
- Uninstall and reinstall Node.js version using
nvm (un)install <version> - Open an explorer window and open
C:\Program Files\nodejsdirectory - Install specific version of npm (globally) using
npm i -g npm@<version> - After the installing process has started, delete or remove the following files
- C:\Program Files\nodejs\npm
- C:\Program Files\nodejs\npx
- C:\Program Files\nodejs\npm.cmd
- C:\Program Files\nodejs\npx.cmd
The following is an example of a successful installation (update).
C:\windows\system32>npm i -g npm@latest
C:\Program Files\nodejs\npm -> C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js
C:\Program Files\nodejs\npx -> C:\Program Files\nodejs\node_modules\npm\bin\npx-cli.js
+ [email protected]
added 57 packages from 18 contributors, removed 315 packages and updated 143 packages in 41.254s
