Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to update npm on macOS

Tags:

npm

macos

For reasons unknown to me, I haven't been able to update to the latest version of npm on macOS (it works fine on Windows). It displays no error, only 'updated 1 package'.

Using Node.js 8.11.1

node -v v8.11.1 

What version of npm do I have?

$ npm -v 5.6.0 

I tried this...

$ npm i -g npm + [email protected] updated 1 package in 7.37s 

And it fails to update.

$ npm -v 5.6.0 

Where is npm?

$ which npm /usr/local/bin/npm 

So I try brew...

brew install npm 

And it fails...

$ npm -v 5.6.0 

*And then I tried this... *

npm install npm@latest -g + [email protected] updated 1 package in 7.618s 

And it fails...

npm -v 5.6.0 

With sudo:

sudo npm i -g npm + [email protected] updated 1 package in 7.794s 

And it fails...

npm -v 5.6.0 

This also fails...

sudo npm install npm@latest -g 

I followed the directions found on this Q&A, completely removing npm and node from my system and reinstalling them from scratch, and it also fails to update.


Screenshot, per request:

enter image description here


Close the terminal, and then re-open the terminal and running:

$ npm -v 5.6.0 

sudo twice:

$ sudo npm i -g npm + [email protected] updated 1 package in 7.478s $ sudo npm i -g npm + [email protected] updated 1 package in 7.434s 

Also fails:

$ npm -v  5.6.0 

What did I miss? What's going on here?

like image 986
NonCreature0714 Avatar asked Apr 04 '18 22:04

NonCreature0714


People also ask

How do I update npm on Mac?

Go into %ProgramFiles%\nodejs\node_modules\npm and copy the file named npmrc in the new npm folder, which should be %appdata%\npm\node_modules\npm . This will tell the new npm where the global installed packages are.

How do I update npm to latest version?

Run npm-upgrade <command> --help to see usage help for corresponding command. check is the default command and can be omitted so running npm-upgrade [filter] is the same as npm-upgrade check [filter] .

How do I check my npm version on Mac?

To see if NPM is installed, type npm -v in Terminal. This should print the version number so you'll see something like this 1.4.


1 Answers

This works on my mac.

Based on docs https://docs.npmjs.com/troubleshooting/try-the-latest-stable-version-of-npm :

npm install -g npm@latest 

There is a note stated on the docs that depends on your installation method, you might addd some sudo.

Upgrading on *nix (OSX, Linux, etc.)

(You may need to prefix these commands with sudo, especially on Linux, or OS X if you installed Node using its default installer.)

like image 187
marlo Avatar answered Sep 22 '22 23:09

marlo