CTS_AE
CTS_AE

Reputation: 14903

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.

Upvotes: 48

Views: 183450

Answers (10)

Lionel G
Lionel G

Reputation: 557

For Linux user:

  • Delete the ~/.npm directory (rm -r /home/{user}/.npm)
  • run in a terminal "nvm install node"

That's all, Enjoy !

Upvotes: 1

Brandons404
Brandons404

Reputation: 149

None of the solutions here worked for me. I was able to fix it by doing the following:

1: in file explorer, go to %appdata%, open the nodejs folder, and delete the npm folder.

2: find the node installer (type "add or remove program" in start menu and search "node" in the settings window), open it, and click "repair"

or (get a clean install of both node and npm)

1: in file explorer, go to %appdata%, open the nodejs folder, and delete the npm folder.

2: find the node installer (type "add or remove program" in start menu and search "node" in the settings window), open it, and click "uninstall"

3: download the latest node installer and install normally. This will update node and npm to the latest versions

Upvotes: 2

shubham giri
shubham giri

Reputation: 11

While creating a new react app using create-react-app

npm suggested the following:

Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR!
npm ERR! To permanently fix this problem, please run:

And it worked for me:

sudo chown -R 506:20 "/Users/${username}/.npm"

Upvotes: 1

J Boon
J Boon

Reputation: 39

  1. Navigate to and delete %AppData%\npm\node_modules\npm

  2. Use npm cli repo's curl script to automatically clean previous npm install and re-install the latest version:

curl -qL https://www.npmjs.com/install.sh | sh

repo: npm github repo

Upvotes: 1

Vicky Dev
Vicky Dev

Reputation: 2193

Since I am all about one-liners, let me make this very damn easy for you.

Open your GitBash or Cygwin(I think both GitBash and Cygwin stores the Windows pre-defined Environment Variables and paths in their storage, so this becomes way easy), on any path, and run this one-liner from there:

rm -rf $APPDATA/npm; npm install -g npm@latest; npm list -g;

rm -rf $APPDATA/npm; - this will purge the old global npm folder completely.

npm install -g npm@latest; - this will install the latest version of NPM available(so no need to install minor versions after this ;)).

npm list -g; - this will show you details of your NPM global profile.

If anyone insists on doing this in PowerShell then here's the way:

$env:Path += ";C:\Program Files\nodejs\"
cmd /c 'del /s /q /f %APPDATA%\npm && rd /s /q %APPDATA%\npm'; npm install -g npm@latest; npm list -g;

$env:Path += ";C:\Program Files\nodejs\" - Ensures that Nodejs is added to Path for atleast running PowerShell session. (Caution: Run this only once, as long as no errors.).

cmd /c 'del /s /q /f %APPDATA%\npm && rd /s /q %APPDATA%\npm'; - Ensures that the necessary step of fully purging the %APPDATA%\npm folder is done with measure.

Upvotes: 3

Zander
Zander

Reputation: 2684

Somehow I had a broken installation of npm so reinstalling it with itself (e.g. npm install -g npm or similar) would not work.

The npm readme actually defines a very simple way to install npm again using this curl command:

curl -qL https://www.npmjs.com/install.sh | sudo sh

This installation script actually removes any existing npm installations, then installs the latest version for you.

Upvotes: 24

Azaria Gebremichael
Azaria Gebremichael

Reputation: 772

Try this command to reinstall npm

npm install -g npm-reinstall

If you are using a linux distribution add sudo

sudo npm install -g npm-reinstall

Upvotes: 6

Gediminas
Gediminas

Reputation: 124

For me even deleting npm folder or reinstalling Node didn't help. After updating Nodejs and npm to latest version (Node 10.19, npm 6.14.3) of my CentOS 6, I've got constant libs error with npm while Node was fine.

What's worked - n Node version manager. With this command I could reverse my npm version: n -p 6.13 link

Upvotes: 0

CTS_AE
CTS_AE

Reputation: 14903

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.

Upvotes: 55

Willem van der Veen
Willem van der Veen

Reputation: 36660

Try this:

npm install npm@latest -g

More info here.

Upvotes: 10

Related Questions