Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Reinstall Broken npm

I just installed node v9.11.1 when I try to use npm I keep getting the following error:

npm WARN npm npm does not support Node.js v9.11.1 npm WARN npm You should probably upgrade to a newer version of node as we npm WARN npm can't make any promises that npm will work with this version. npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8. npm WARN npm You can find the latest version at https://nodejs.org/ 

I tried to do npm i -g npm but it couldn't update itself, it just kept throwing the same error above.

When I run npm -v it says 5.5.1 it seems the latest version is currently 5.8.0.

I tried deleting the folder and running the repair function on the node.js installer, but it didn't replace the module.

like image 782
CTS_AE Avatar asked Apr 10 '18 07:04

CTS_AE


People also ask

How can I reinstall npm?

Using the official Node installer is the easiest way to reinstall Node. js and npm on your Windows environment. To use this option, you can go to the Node. js download page and reinstall the latest Node.

How do I uninstall and reinstall npm?

To completely uninstall node + npm is to do the following: go to /usr/local/lib and delete any node and node_modules. go to /usr/local/include and delete any node and node_modules directory. if you installed with brew install node, then run brew uninstall node in your terminal.

Does npm do a clean install?

The npm clean-install command (or npm ci for short) is an in-place replacement for npm install with two major differences: It does a clean install: if the node_modules folder exists, npm deletes it and installs a fresh one. It checks for consistency: if package-lock.


1 Answers

Delete the Global NPM Folder

https://stackoverflow.com/a/5926706/349659

npm list -g 

For Windows this will most likely be:

%AppData%\npm\node_modules

You can paste that into a folder's address bar and it will take you there.

Once there delete the folder named npm.

Download the Latest Release of NPM

https://github.com/npm/cli/releases/latest

Grab the zip and unzip it to your node_modules folder that you just deleted the npm folder from.

Rename the folder you extracted from the zip to npm

If you get any warnings about the file path or name being too long skip the warnings.

Update for Good Luck

Now you should be able to run npm i -g npm to update/reinstall npm without any warnings.

I find this step especially important if you had errors in Windows about the path or file name being too long.

You may get the following errors. If you do go and delete or move the files it has listed and you should be able to run npm i -g npm successfully.

npm ERR! Refusing to delete C:\Program Files\nodejs\npx.cmd: is outside C:\Program Files\nodejs\node_modules\npm and not a link npm ERR! File exists: C:\Program Files\nodejs\npx.cmd npm ERR! Move it away, and try again.  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. 
like image 182
CTS_AE Avatar answered Sep 25 '22 17:09

CTS_AE