Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Instructions on how to fix npm if you've installed Node through Homebrew on Mac OS X or Linuxbrew

Fixing npm On Mac OS X for Homebrew Users

Installing node through Homebrew can cause problems with npm for globally installed packages. To fix it quickly, use the solution below. An explanation is also included at the end of this document.

Solution

This solution fixes the error caused by trying to run npm update npm -g. Once you're finished, you also won't need to use sudo to install npm modules globally.

Before you start, make a note of any globally installed npm packages. These instructions will have you remove all of those packages. After you're finished you'll need to re-install them.

Run the following commands to remove all existing global npm modules, uninstall node & npm, re-install node with the correct defaults, configure the location for global npm modules to be installed, and then install npm as its own pacakge.

rm -rf /usr/local/lib/node_modules
brew uninstall node
brew install node --without-npm
echo prefix=~/.npm-packages >> ~/.npmrc
curl -L https://www.npmjs.com/install.sh | sh

Node and npm should be correctly installed at this point. The final step is to add ~/.npm-packages/bin to your PATH so npm and global npm packages are usable. To do this, add the following line to your ~/.bash_profile:

export PATH="$HOME/.npm-packages/bin:$PATH"

Now you can re-install any global npm packages you need without any problems.

Explanation of the issue

If you're a Homebrew user and you installed node via Homebrew, there is a major philosophical issue with the way Homebrew and NPM work together. If you install node with Homebrew and then try to do npm update npm -g, you may see an error like this:

$ npm update npm -g
npm http GET https://registry.npmjs.org/npm
npm http 304 https://registry.npmjs.org/npm
npm http GET https://registry.npmjs.org/npm/1.4.4
npm http 304 https://registry.npmjs.org/npm/1.4.4
npm ERR! error rolling back Error: Refusing to delete: /usr/local/bin/npm not in /usr/local/lib/node_modules/npm
npm ERR! error rolling back     at clobberFail (/usr/local/Cellar/node/0.10.26/lib/node_modules/npm/lib/utils/gently-rm.js:57:12)
npm ERR! error rolling back     at next (/usr/local/Cellar/node/0.10.26/lib/node_modules/npm/lib/utils/gently-rm.js:43:14)
npm ERR! error rolling back     at /usr/local/Cellar/node/0.10.26/lib/node_modules/npm/lib/utils/gently-rm.js:52:12
npm ERR! error rolling back     at Object.oncomplete (fs.js:107:15)
npm ERR! error rolling back  npm@1.4.4 { [Error: Refusing to delete: /usr/local/bin/npm not in /usr/local/lib/node_modules/npm] code: 'EEXIST', path: '/usr/local/bin/npm' }
npm ERR! Refusing to delete: /usr/local/bin/npm not in /usr/local/lib/node_modules/npm
File exists: /usr/local/bin/npm
Move it away, and try again. 

npm ERR! System Darwin 13.1.0
npm ERR! command "/usr/local/Cellar/node/0.10.26/bin/node" "/usr/local/bin/npm" "update" "npm" "-g"
npm ERR! cwd /Users/dan/Google Drive/Projects/dotfiles
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! path /usr/local/bin/npm
npm ERR! code EEXIST
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/dan/Google Drive/Projects/dotfiles/npm-debug.log
npm ERR! not ok code 0

There's an NPM bug for this exact problem. The bug has been "fixed" by Homebrew installing npm in a way that allows it to manage itself once the install is complete. However, this is error-prone and still seems to cause problems for some people. The root of the the issue is really that npm is its own package manager and it is therefore better to have npm manage itself and its packages completely on its own instead of letting Homebrew do it.

Also, using the Homebrew installation of npm will require you to use sudo when installing global packages. Since one of the core ideas behind Homebrew is that apps can be installed without giving them root access, this is a bad idea.

@dbaq

This comment has been minimized.

Copy link

commented Apr 17, 2014

Thanks! ๐Ÿ‘

@martypitt

This comment has been minimized.

Copy link

commented Apr 20, 2014

Outstanding! ๐Ÿ‘

@semikolon

This comment has been minimized.

Copy link

commented Sep 19, 2014

I got these error messages, but it seems to have worked...

Fredriks-MacBook-Pro% curl -L https://www.npmjs.org/install.sh | sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 6711 100 6711 0 0 8838 0 --:--:-- --:--:-- --:--:-- 8830
tar=/usr/bin/tar
version:
bsdtar 2.8.3 - libarchive 2.8.3
install npm@latest
fetching: http://registry.npmjs.org/npm/-/npm-2.0.0.tgz

/private/var/folders/qs/8nmw36_11t727ckk5npwv81w0000gn/T/npm.29023/package/bin/read-package-json.js:18
val = val[f]
^
TypeError: Cannot read property 'node' of undefined
at /private/var/folders/qs/8nmw36_11t727ckk5npwv81w0000gn/T/npm.29023/package/bin/read-package-json.js:18:16
at Array.forEach (native)
at /private/var/folders/qs/8nmw36_11t727ckk5npwv81w0000gn/T/npm.29023/package/bin/read-package-json.js:17:11
at Array.forEach (native)
at /private/var/folders/qs/8nmw36_11t727ckk5npwv81w0000gn/T/npm.29023/package/bin/read-package-json.js:14:22
at /private/var/folders/qs/8nmw36_11t727ckk5npwv81w0000gn/T/npm.29023/package/node_modules/read-package-json/read-json.js:51:40
at final (/private/var/folders/qs/8nmw36_11t727ckk5npwv81w0000gn/T/npm.29023/package/node_modules/read-package-json/read-json.js:349:17)
at then (/private/var/folders/qs/8nmw36_11t727ckk5npwv81w0000gn/T/npm.29023/package/node_modules/read-package-json/read-json.js:126:33)
at /private/var/folders/qs/8nmw36_11t727ckk5npwv81w0000gn/T/npm.29023/package/node_modules/read-package-json/read-json.js:266:40
at evalmachine.:271:14
0.10.31

/private/var/folders/qs/8nmw36_11t727ckk5npwv81w0000gn/T/npm.29023/package/bin/read-package-json.js:18
val = val[f]
^
TypeError: Cannot read property 'node' of undefined
at /private/var/folders/qs/8nmw36_11t727ckk5npwv81w0000gn/T/npm.29023/package/bin/read-package-json.js:18:16
at Array.forEach (native)
at /private/var/folders/qs/8nmw36_11t727ckk5npwv81w0000gn/T/npm.29023/package/bin/read-package-json.js:17:11
at Array.forEach (native)
at /private/var/folders/qs/8nmw36_11t727ckk5npwv81w0000gn/T/npm.29023/package/bin/read-package-json.js:14:22
at /private/var/folders/qs/8nmw36_11t727ckk5npwv81w0000gn/T/npm.29023/package/node_modules/read-package-json/read-json.js:51:40
at final (/private/var/folders/qs/8nmw36_11t727ckk5npwv81w0000gn/T/npm.29023/package/node_modules/read-package-json/read-json.js:349:17)
at then (/private/var/folders/qs/8nmw36_11t727ckk5npwv81w0000gn/T/npm.29023/package/node_modules/read-package-json/read-json.js:126:33)
at /private/var/folders/qs/8nmw36_11t727ckk5npwv81w0000gn/T/npm.29023/package/node_modules/read-package-json/read-json.js:266:40
at evalmachine.:271:14

npm@2.0.0 prepublish /private/var/folders/qs/8nmw36_11t727ckk5npwv81w0000gn/T/npm.29023/package
node bin/npm-cli.js prune --prefix=. --no-global && rm -rf test///node_modules && make -j8 doc

make: Nothing to be done for `doc'.
/Users/fredrikbranstrom/.node/bin/npm -> /Users/fredrikbranstrom/.node/lib/node_modules/npm/bin/npm-cli.js
npm@2.0.0 /Users/fredrikbranstrom/.node/lib/node_modules/npm
It worked
Fredriks-MacBook-Pro%

@SteveBenner

This comment has been minimized.

Copy link

commented Sep 23, 2014

This solution works for me, although it does make me sad that I canโ€™t use Homebrew. Iโ€™ve no idea whatโ€™s going on underneath the hood, as Iโ€™m primarily a Ruby guy. Two strange things jump out at me:

  1. Though ~/.node/bin is on my path, (and not being overridden) I cannot find any of the executables inside using the which -a commandโ€ฆ They nonetheless are fully functional.
  2. When I run npm update -g it appears to work as expected, but the following error message shows on completion:
npm ERR! Darwin 13.3.0
npm ERR! argv "node" "/Users/user/.node/bin/npm" "update" "-g"
npm ERR! node v0.10.32
npm ERR! npm  v2.0.0
npm ERR! code EPEERINVALID

npm ERR! peerinvalid The package npmconf does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer npm-registry-client@3.2.2 wants npmconf@^2.1.0

I surmised the problem may be npmconf, and perhaps itโ€™s related to this recently opened issue.

@Martinspire

This comment has been minimized.

Copy link

commented Oct 1, 2014

Isn't it better to just uninstall node via homebrew and use the installer from nodejs.org? Separating them also seems a bit odd

@paul-ylz

This comment has been minimized.

Copy link

commented Oct 12, 2014

Thanks this helped me fix my npm issues

@tomhanlon

This comment has been minimized.

Copy link

commented Oct 15, 2014

Huge help. Thanks.

@captDaylight

This comment has been minimized.

Copy link

commented Oct 16, 2014

Wow, been looking for this solution for a full day. Thanks for posting, great stuff.

@robbennet

This comment has been minimized.

Copy link

commented Oct 20, 2014

SO much this! Extremely helpful.

@tgrecojs

This comment has been minimized.

Copy link

commented Oct 24, 2014

Thank you!

@bingalls

This comment has been minimized.

Copy link

commented Oct 28, 2014

Please add this step, before deleting /usr/local/node_modules (to not lose all your work):
ls -1 /usr/local/node_modules > ~/node_modules.txt
at the end, do:
for i in cat ~/node_modules.txt;do npm install -g $i;done

Hopefully, it is not necessary to track module versions or the new private npm modules.

@espiler

This comment has been minimized.

Copy link

commented Nov 3, 2014

Thanks a ton!

@cmezian

This comment has been minimized.

Copy link

commented Nov 10, 2014

Worked like a charm for my older iMac, thank you!

@GrimmOutlook

This comment has been minimized.

Copy link

commented Nov 16, 2014

Until I typed in "npm install -g blah, blah, blah", everything worked. Once I tried to re-install some global node modules, I get: "bash: /usr/local/bin/npm: No such file or directory". Anyone else run into this? Any thoughts? Seems like it can be fixed by something simple. Thanks!

@gavstah

This comment has been minimized.

Copy link

commented Nov 25, 2014

This worked a treat for me. Up until now, I'd been struggling to get node & npm going on my mac.

@GrimmOutlook - judging by the output, it seems like npm's looking in the wrong place - did you add ~/.npm/bin to your path and then run:

source ~/.bash_profile

to load the path change?

@pelachile

This comment has been minimized.

Copy link

commented Nov 28, 2014

Hmm. Now none of my newly installed global commands are found. In fact a node_modules folder isn't created in my home directory. All modules are being installed into /usr/local/bin/ which is already in my path.

@unostella

This comment has been minimized.

Copy link

commented Nov 30, 2014

Thanks for this, it all worked great up to the point when I re-open terminal, just like @GrimmOutlook described.
So after restarting terminal it says -bash: npm: command not found
So I have to export PATH="$HOME/.node/bin:$PATH" each time I open it up.
Any idea how to fix that?

@merraysy

This comment has been minimized.

Copy link

commented Dec 15, 2014

thanks your are the ๐Ÿ‘จ

@brockthebear

This comment has been minimized.

Copy link

commented Dec 24, 2014

Incredibly helpful. Thanks so much.

@aljopro

This comment has been minimized.

Copy link

commented Dec 28, 2014

@unostella, I had to put the export ~/.profile instead of ~/.path

@johannyberg

This comment has been minimized.

Copy link

commented Dec 31, 2014

Thank you!

@kaishin

This comment has been minimized.

Copy link

commented Dec 31, 2014

This worked great, thanks!

@watsy0007

This comment has been minimized.

Copy link

commented Jan 3, 2015

thank you!

@chenrui333

This comment has been minimized.

Copy link

commented Jan 4, 2015

node 0.10.26 is still installed.
Remove them all with brew uninstall --force node.

@chenrui333

This comment has been minimized.

Copy link

commented Jan 4, 2015

Also, "npm cache clear" is good for testing the cmd as well.

Thanks for the gist!

@phudekar

This comment has been minimized.

Copy link

commented Jan 6, 2015

Thanks. You saved my day

@morganloehr

This comment has been minimized.

Copy link

commented Jan 9, 2015

Serious thanks for this!

@favorit

This comment has been minimized.

Copy link

commented Jan 20, 2015

Thank you! It works for me!

@philbritton

This comment has been minimized.

Copy link

commented Jan 20, 2015

awesome, i'm back in business, thanks!

@ghost

This comment has been minimized.

Copy link

commented Jan 24, 2015

Thankyou so much!

@dan-mckay

This comment has been minimized.

Copy link

commented Jan 26, 2015

More thanks from me, too ;)

@joshuakemp1

This comment has been minimized.

Copy link

commented Jan 27, 2015

THANKS!!

@prokizzle

This comment has been minimized.

Copy link

commented Feb 2, 2015

Thank you so very much!

@fa3

This comment has been minimized.

Copy link

commented Feb 3, 2015

What can i say instead Thank you? Ha, thank you very much!

@NandoSantana

This comment has been minimized.

Copy link

commented Feb 8, 2015

hi, printed error: /usr/local/bin/npm: No such file or directory , help me.

@pedrocatre

This comment has been minimized.

Copy link

commented Feb 9, 2015

Thank you so much!

@guimap

This comment has been minimized.

Copy link

commented Feb 11, 2015

Thanksss man, u save my life, thanks thanks....

@thechrisproject

This comment has been minimized.

Copy link

commented Feb 13, 2015

Dang, I tried these instructions and everything worked well until running the script:

$ curl -L https://www.npmjs.org/install.sh | sh % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 51 100 51 0 0 124 0 --:--:-- --:--:-- --:--:-- 124 100 6239 100 6239 0 0 8293 0 --:--:-- --:--:-- --:--:-- 23022 sh: line 21: npm-install-36841.sh: Permission denied rm: npm-install-36841.sh: No such file or directory Failed to download script

@mnlsn

This comment has been minimized.

Copy link

commented Feb 15, 2015

use curl -L https://www.npmjs.com/install.sh | sh if you get the Permission Denied error when installing npm

@rowild

This comment has been minimized.

Copy link

commented Feb 19, 2015

I got an error on Mac Maverick 10.9.5, because I use MAMP, which elivers its own libtool. I could solve this problem by creating a symlink from the MAMP version to the bin version

// create backup of MAMP libtool
mv /Applications/MAMP/bin/libtool /Applications/MAMP/bin/libtool_orig

// create symlink
ln -s /usr/bin/libtool /Applications/MAMP/bin/libtool

// then install node

Just in case somebody got the same error...

Thanks for your solution!!!

@yonatann

This comment has been minimized.

Copy link

commented Feb 20, 2015

Worked like a charm!

@jinyoungc

This comment has been minimized.

Copy link

commented Feb 21, 2015

OMG THANK YOU!!!!!!

@jserrao

This comment has been minimized.

Copy link

commented Feb 23, 2015

FYI: 'curl -L https://www.npmjs.org/install.sh | sh' returns a 404 for me. Just drop the https to http and things worked swimmingly. Thanks for digging into this issue. I've long had conflicts similar to those noted in your post and this resolved a great many of them.

@irealva

This comment has been minimized.

Copy link

commented Feb 24, 2015

Awesome, this helped a lot. I first ran:

$ brew doctor

and fixed all the node related warning. Then followed your instructions and it worked like a charm.

This page helped too: http://forums.webhook.com/t/cant-get-node-to-install-on-latest-osx-mavericks-resolved/109/5

@reesejohn69

This comment has been minimized.

Copy link

commented Mar 10, 2015

If I use brew install node --without-npm command to isntall node, what's gonna happen when node gets updated via homebrew? Will that install npm?

@benpolinsky

This comment has been minimized.

Copy link

commented Mar 10, 2015

Thanks so much.

@dnlserrano

This comment has been minimized.

Copy link

commented Mar 13, 2015

Thanks! You're the man! ๐Ÿ‘‘

@rebekahkwon

This comment has been minimized.

Copy link

commented Mar 13, 2015

๐Ÿ‘ thank you!

@reiaguilera

This comment has been minimized.

Copy link

commented Mar 19, 2015

Excelent ! (Y)

@guoylyy

This comment has been minimized.

Copy link

commented Mar 27, 2015

Excelent! Thanks a lot.

@mikeymco

This comment has been minimized.

Copy link

commented Mar 27, 2015

Thanks ๐Ÿ‘

@jklegseth

This comment has been minimized.

Copy link

commented Apr 4, 2015

Thanks! Nothing's ever easy...

@mitogh

This comment has been minimized.

Copy link

commented Apr 5, 2015

Thanks, works perfect. ๐Ÿ‘

@ahelja

This comment has been minimized.

Copy link

commented Apr 15, 2015

Thanks

@codykrainock

This comment has been minimized.

Copy link

commented Apr 19, 2015

Thank you!

@JonMasterson

This comment has been minimized.

Copy link

commented Apr 19, 2015

Thanks so much!

@thedamon

This comment has been minimized.

Copy link

commented Apr 19, 2015

Awesome to see this! But it's weird. I followed the instructions and added .npm and .node\bin to my zshrc, but I am still getting the access errors. Sumfin not quite right

@mariarivas

This comment has been minimized.

Copy link

commented Apr 20, 2015

Awesome, thanks!

@zekitow

This comment has been minimized.

Copy link

commented Apr 24, 2015

Thanks!!!

Cheeers!

@buk

This comment has been minimized.

Copy link

commented Apr 27, 2015

Thanks!

@limichange

This comment has been minimized.

Copy link

commented Apr 30, 2015

ThanksO(โˆฉ_โˆฉ)O๏ผ

@alphapilgrim

This comment has been minimized.

Copy link

commented May 2, 2015

Thanks!!

@SGD1953

This comment has been minimized.

Copy link

commented May 5, 2015

Thanks a lot, I got errors when installing npm, doing an additional sudo rm -rf ~/.npm did the trick for me.

@dillorscroft

This comment has been minimized.

Copy link

commented May 8, 2015

I get a strange warning/error but then it proceeds to say "It worked"

curl -L https://www.npmjs.com/install.sh | sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 6239 100 6239 0 0 6043 0 0:00:01 0:00:01 --:--:-- 6045
tar=/usr/bin/tar
version:
bsdtar 2.8.3 - libarchive 2.8.3
install npm@latest
fetching: http://registry.npmjs.org/npm/-/npm-2.9.1.tgz

npm@2.9.1 prepublish /private/var/folders/1m/f2btkb_j5ng6bzhmzmm73hc40000gn/T/npm.32190/package
node bin/npm-cli.js prune --prefix=. --no-global && rimraf test///node_modules && make -j4 doc

sh: rimraf: command not found

@k7n4n5t3w4rt

This comment has been minimized.

Copy link

commented May 10, 2015

Many thanks. Installing npm with Homebrew never seemed to work properly but I never knew why. Now I still don't but have them installed :)

I had to use SGD1953's tip and do "sudo rm -rf ~/.npm" before installing npm. Otherwise this happened.

npm ERR! Darwin 13.4.0
npm ERR! argv "/usr/local/bin/node" "/private/var/folders/_b/g8fdbnmx317_s0dlnp784pbr0000gn/T/npm.33170/package/cli.js" "install" "-gf"
npm ERR! node v0.12.2
npm ERR! npm v2.9.1

npm ERR! Attempt to unlock /Users/[MYUSER]/.node/lib/node_modules/npm, which hasn't been locked

@jovincroninwilesmith

This comment has been minimized.

Copy link

commented May 10, 2015

@unostella did you ever figure out a fix? I am still getting the same error.

@sebklaus

This comment has been minimized.

Copy link

commented May 13, 2015

Thank you very much! Works a treat!

@azonirunner

This comment has been minimized.

Copy link

commented May 13, 2015

Thank you. Works! Had to add the sudo rm -rf ~/.npm (tip from SGD1953)

@sudostack

This comment has been minimized.

Copy link

commented May 14, 2015

wow! thanks! resolved a totally different error message for me, but awesome! kudos!

@deepakmani

This comment has been minimized.

Copy link

commented May 15, 2015

This was very useful when I had to re-install npm .

@iainwatt

This comment has been minimized.

Copy link

commented May 18, 2015

Ledge!

@0is1

This comment has been minimized.

Copy link

commented May 18, 2015

Yes, thanks! This was really helpful :)

@aidansmyth

This comment has been minimized.

Copy link

commented May 22, 2015

Worked great except for one issue, after running brew install node --without-npm i kept getting
"Could not symlink lib/dtrace/node.d
/usr/local/lib/dtrace is not writable"

I had to run 'sudo chown -R whoami /usr/local' to be able to link brew to node.

@anthonybrown

This comment has been minimized.

Copy link

commented May 24, 2015

This is funny, I came about the same solution through trial and error and stack overflow.

@ghost

This comment has been minimized.

Copy link

commented May 28, 2015

Thank you!!!

@ser111

This comment has been minimized.

Copy link

commented May 30, 2015

You're the man.

@jonrh

This comment has been minimized.

Copy link

commented Jun 7, 2015

Awesome, thank you! Following the instructions I ran into some Homebrew issues. Running brew update and then following the instructions again worked.

@sagic

This comment has been minimized.

Copy link

commented Jun 8, 2015

thanks :)

@adaam2

This comment has been minimized.

Copy link

commented Jun 12, 2015

This is awesome! great work

@jromeem

This comment has been minimized.

Copy link

commented Jun 14, 2015

this is great!! thanks a butt ton! ๐Ÿ‘

@bghill

This comment has been minimized.

Copy link

commented Jun 15, 2015

At some point I must have installed node.js directly. Later I installed via brew. I suspect this is what led my version of node get screwed up file permissions. Out of curiosity, I wanted to see if a "clean" install of node from homebrew would still have the permissions issue. I followed this script: https://gist.github.com/nicerobot/2697848 for most of the uninstall. I also had to remove the ~/.npm and /usr/local/share/systemtap. I only removed the latter after verifying that there was nothing in it related to anything else on my system. With that done, I was able to execute brew install node and the permission issues seem to have disappeared. npm update npm -g now works fine, as does the build process that was giving me trouble.

Let me know if this works for anyone else. I'm curious if most folks just have a long forgotten collision between installs, and complete cleanup is the current solution.

@apzentral

This comment has been minimized.

Copy link

commented Jun 18, 2015

This is awesome. Thank you.

@BenLittle

This comment has been minimized.

Copy link

commented Jun 19, 2015

Excellent. Thank you!

@dcondrey

This comment has been minimized.

Copy link

commented Jun 22, 2015


git clone git://github.com/ry/node.git
(cd node && ./configure && make && sudo make install)
chown -R "$USER" /usr/local/{share/man,bin,lib/node,include/node};
npm update npm -g
node -v && npm -v
@JoeDuncko

This comment has been minimized.

Copy link

commented Jun 30, 2015

Thanks!

@gbanis

This comment has been minimized.

Copy link

commented Jul 1, 2015

Worked like a charm. Later I had to remove nvm as well and now everything is in tune. Thank you!

@aking13

This comment has been minimized.

Copy link

commented Jul 2, 2015

You have literally brought so much satisfaction to 3 hours of troubleshooting with so many nodejs, npm, brew problems. Thank you! Thank you!

@dannguyen

This comment has been minimized.

Copy link

commented Jul 4, 2015

The installation process works for me (i.e. it doesn't break) but after installing packages globally, I find that node apparently won't look at the default global path for npm packages. Installing packages locally works just fine.

@parsafatehi

This comment has been minimized.

Copy link

commented Jul 10, 2015

Thanks, It worked ๐Ÿ˜Š

@RoySegall

This comment has been minimized.

Copy link

commented Jul 11, 2015

Working like a glove!

@ghost

This comment has been minimized.

Copy link

commented Jul 13, 2015

Fantastic solution - it sorted my problem with installing react native :) Many thanks

@chitopolo

This comment has been minimized.

Copy link

commented Jul 14, 2015

Thank you very much, it worked! ;)

@gabrielribeiro

This comment has been minimized.

Copy link

commented Jul 16, 2015

Didn't work for me

Got the following error:

-bash: npm: command not found

My .bash_profile:

[[ -s ~/.bashrc ]] && source ~/.bashrc

My .bashrc:

source dnvm.sh
export MONO_MANAGED_WATCHER=disabled

My .path:

export PATH=/Users/GabrielRibeiro/.node/bin:/Users/GabrielRibeiro/.dnx/runtimes/dnx-mono.1.0.0-b$
export PATH="$HOME/.node/bin:$PATH"

What I did wrong?

@qqilihq

This comment has been minimized.

Copy link

commented Jul 24, 2015

Worked like a charm. Thank you!

@philals

This comment has been minimized.

Copy link

commented Jul 26, 2015

Thanks!

@ljhan

This comment has been minimized.

Copy link

commented Aug 2, 2015

Thank you so much for the help! I still have to export PATH="$HOME/.node/bin:$PATH" each time terminal is re-opened... Could there be a problem with the NODE_PATH?

@agostlg

This comment has been minimized.

Copy link

commented Aug 2, 2015

Thanks!

@WeHateNick

This comment has been minimized.

Copy link

commented Aug 5, 2015

I was able to install node without npm through brew but I get this error when running the curl command:

nick$ curl -L https://www.npmjs.com/install.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  6239  100  6239    0     0   8375      0 --:--:-- --:--:-- --:--:--  8374
tar=/usr/bin/tar
version:
bsdtar 2.8.3 - libarchive 2.8.3
install npm@latest
fetching: http://registry.npmjs.org/npm/-/npm-2.13.3.tgz
npm ERR! Darwin 14.3.0
npm ERR! argv "/usr/local/bin/node" "/private/var/folders/hq/2mf0j5sj0c160gl3x33btbmr0000gn/T/npm.4470/package/cli.js" "rm" "npm" "-gf"
npm ERR! node v0.12.7
npm ERR! npm  v2.13.3
npm ERR! path /Users/nick/.node/lib/node_modules/npm/node_modules
npm ERR! code EACCES
npm ERR! errno -13

npm ERR! Error: EACCES, rmdir '/Users/nick/.node/lib/node_modules/npm/node_modules'
npm ERR!     at Error (native)
npm ERR!  { [Error: EACCES, rmdir '/Users/nick/.node/lib/node_modules/npm/node_modules']
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/Users/nick/.node/lib/node_modules/npm/node_modules' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! Please include the following file with any support request:
npm ERR!     /private/var/folders/hq/2mf0j5sj0c160gl3x33btbmr0000gn/T/npm.4470/package/npm-debug.log

> npm@2.13.3 prepublish /private/var/folders/hq/2mf0j5sj0c160gl3x33btbmr0000gn/T/npm.4470/package
> node bin/npm-cli.js prune --prefix=. --no-global && rimraf test/*/*/node_modules && make -j4 doc

sh: rimraf: command not found
npm ERR! Darwin 14.3.0
npm ERR! argv "/usr/local/bin/node" "/private/var/folders/hq/2mf0j5sj0c160gl3x33btbmr0000gn/T/npm.4470/package/cli.js" "install" "-gf"
npm ERR! node v0.12.7
npm ERR! npm  v2.13.3
npm ERR! path /Users/nick/.node/lib/node_modules/npm/node_modules
npm ERR! code EACCES
npm ERR! errno -13

npm ERR! Error: EACCES, rmdir '/Users/nick/.node/lib/node_modules/npm/node_modules'
npm ERR!     at Error (native)
npm ERR!  { [Error: EACCES, rmdir '/Users/nick/.node/lib/node_modules/npm/node_modules']
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/Users/nick/.node/lib/node_modules/npm/node_modules' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.
npm ERR! error rolling back Error: EACCES, rmdir '/Users/nick/.node/lib/node_modules/npm/node_modules'
npm ERR! error rolling back     at Error (native)
npm ERR! error rolling back  { [Error: EACCES, rmdir '/Users/nick/.node/lib/node_modules/npm/node_modules']
npm ERR! error rolling back   errno: -13,
npm ERR! error rolling back   code: 'EACCES',
npm ERR! error rolling back   path: '/Users/nick/.node/lib/node_modules/npm/node_modules' }

npm ERR! Please include the following file with any support request:
npm ERR!     /private/var/folders/hq/2mf0j5sj0c160gl3x33btbmr0000gn/T/npm.4470/package/npm-debug.log
It failed

Any ideas?

@aliwatters

This comment has been minimized.

Copy link

commented Aug 5, 2015

@WeHateNick try $ curl -L https://www.npmjs.com/install.sh | sudo sh

@walterspieler

This comment has been minimized.

Copy link

commented Aug 7, 2015

@ljhan I had the same as you have.
I solved the problem by doing this :
$ touch .bash_profile
$ open .bash_profile
In .bash_profil i added this line
source ~/.bashrc

http://hathaway.cc/post/69201163472/how-to-edit-your-path-environment-variables-on-mac

@Adomeister

This comment has been minimized.

Copy link

commented Aug 12, 2015

THANKYOU @aliwatters this has been bugging me for days!

@grantpowell

This comment has been minimized.

Copy link

commented Aug 17, 2015

Cannot install, get error: "npm-install-34536.sh: Permission denied" when attempting "curl -L https://www.npmjs.com/install.sh | sh"

@ccheatham

This comment has been minimized.

Copy link

commented Aug 22, 2015

In accordance with what @walterspieler said above if you continue to see this error after you add the source ~/.bashrc it could be because you already have a .node directory in your home directory. I renamed my current .node directory (you could just delete it) then ran it again and it worked. Also you may already have a .profile in which case you can add the source ~/.bashrc to it instead.

@alexortiz201

This comment has been minimized.

Copy link

commented Aug 23, 2015

@ljhan you have to add export PATH="$HOME/.node/bin:$PATH" to your ~/.bash_profile or ~/.path file

@mitchstewart08

This comment has been minimized.

Copy link

commented Aug 24, 2015

Thanks a lot!

@jitendravyas

This comment has been minimized.

Copy link

commented Aug 26, 2015

@alexortiz201 - I use zsh and ohmyzsh. how to make it work for me

@mmizutani

This comment has been minimized.

Copy link

commented Aug 30, 2015

In a nutshell:

ls -1 /usr/local/lib/node_modules > ~/node_modules.txt
sed -e "s,/\+$,," -e "s,^/\+,," ~/node_modules.txt
rm -rf /usr/local/lib/node_modules
brew uninstall node --force node
brew install node --without-npm
echo prefix=~/.node >> ~/.npmrc
curl -L https://www.npmjs.com/install.sh | sh
echo 'export PATH="$HOME/.node/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
for i in `cat ~/node_modules.txt`;do npm install -g $i;done
rm ~/node_modules.txt
@jordilondoner

This comment has been minimized.

Copy link

commented Aug 30, 2015

๐Ÿ‘ all good here, thanks!

@sadethesage

This comment has been minimized.

Copy link

commented Sep 13, 2015

ilysm, thanks!

@huijing

This comment has been minimized.

Copy link

commented Sep 25, 2015

Following the steps but when I run curl -L https://www.npmjs.com/install.sh | sh I get the following errors:

scripts/installable.sh: line 4: semver: command not found
Packaging or installing npm@3.3.4 with npm@3.3.4 is impossible.
Please install npm@^3.0.0-0 from the registry and use that or run your command with
this version of npm with:
    /usr/local/Cellar/node/4.1.1/bin/node /var/folders/0g/9lxn9c8d3czfj0qvs_qjflxxrn5xph/T/npm.18926/package install -gf
npm ERR! Darwin 14.5.0
npm ERR! argv "/usr/local/Cellar/node/4.1.1/bin/node" "/private/var/folders/0g/9lxn9c8d3czfj0qvs_qjflxxrn5xph/T/npm.18926/package/cli.js" "install" "-gf"
npm ERR! node v4.1.1
npm ERR! npm  v3.3.4

npm ERR! Maximum call stack size exceeded
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /private/var/folders/0g/9lxn9c8d3czfj0qvs_qjflxxrn5xph/T/npm.18926/package/npm-debug.log
It failed

Does this have to do with the latest update to node?

@nabeel-ibrahim

This comment has been minimized.

Copy link

commented Sep 29, 2015

Im getting the same error as @huljing. @huljing did you resolve your issue?

@mikobiscante

This comment has been minimized.

Copy link

commented Sep 29, 2015

@jitendravyas - open ~/.zshrc, copy & paste export PATH="$HOME/.npm-packages/bin:$PATH" then save.

@rcastag

This comment has been minimized.

Copy link

commented Oct 2, 2015

Amazeballs!

@fabricioflores

This comment has been minimized.

Copy link

commented Oct 3, 2015

I have the same issue as @huijing and @nabeel-ibrahim. Did you find some solution? I thought it was an error of node v4 but I downgraded to v0.12.7 but the issue still persists.
Update
I have noticed that actually there is a version of npm installed. I followed this tutorial and I continued with the next steps after npm install and it works for me.

@slemarchand

This comment has been minimized.

Copy link

commented Oct 8, 2015

Great! It Works fine for me!

@skad21

This comment has been minimized.

Copy link

commented Oct 11, 2015

Very helpfull tips...great, thanks !

@imechemi

This comment has been minimized.

Copy link

commented Oct 12, 2015

@huijing first export PATH="$HOME/.node/bin:$PATH" and then cd into your project directory or any directory where package.json file exist. semver is a version tester so you can install it once you have package.json file.

@SmellyFish

This comment has been minimized.

Copy link

commented Oct 14, 2015

๐Ÿ‘

@ocaoimh

This comment has been minimized.

Copy link

commented Oct 17, 2015

Brilliant. Thanks!

@FredericChang

This comment has been minimized.

Copy link

commented Oct 17, 2015

helpful

@xinpan1992

This comment has been minimized.

Copy link

commented Oct 20, 2015

Thank you so much!!!!! Your solution helps me solve this problem perfectly!

@vexhack

This comment has been minimized.

Copy link

commented Oct 21, 2015

Thanks! This was helpful and useful! Again, thanks!

@UlisesGascon

This comment has been minimized.

Copy link

commented Oct 28, 2015

Thanks! This saved my day!! ๐Ÿ‘

@njv

This comment has been minimized.

Copy link

commented Oct 29, 2015

Thank you!

@mattsilv

This comment has been minimized.

Copy link

commented Nov 2, 2015

thank you. Worked well on OSX 10.10

@fwahlqvist

This comment has been minimized.

Copy link

commented Nov 2, 2015

Thanks ๐Ÿ‘

@obouchari

This comment has been minimized.

Copy link

commented Nov 3, 2015

Thanks! ๐Ÿ‘

@MikaelCarpenter

This comment has been minimized.

Copy link

commented Nov 4, 2015

getting -bash: /usr/local/bin/npm: No such file or directory any ideas?

@FullstackJack

This comment has been minimized.

Copy link

commented Nov 5, 2015

Thanks, but I had to do the following to get mine to install all the way:

cd ~
rm -rf /usr/local/lib/node_modules
brew uninstall node
brew install node --without-npm
echo prefix=~/.node >> ~/.npmrc
sudo chown -R $(whoami) /usr/local
brew link --overwrite  node
curl -L https://www.npmjs.com/install.sh | sh

Permission Denied will occur if calling curl from a directory you don't have write permissions. I didn't realize I was in the wrong directory at first and foolishly kept making that mistake while searching for solutions.

@opfertunes

This comment has been minimized.

Copy link

commented Nov 10, 2015

You sir ROCK

@jiyinyiyong

This comment has been minimized.

Copy link

commented Nov 11, 2015

I actually fixed my npm with this:

brew postinstall node

http://forums.webhook.com/t/bash-npm-command-not-found-resolved/66/7

@DavidJBarnes

This comment has been minimized.

Copy link

commented Nov 12, 2015

Thanks you!!

@backspaces

This comment has been minimized.

Copy link

commented Nov 12, 2015

Boy, this makes me feel uneasy. All my hacking uses node/npm daily. I currently have the install from their site, done using the npm trick of not using admin directories: https://github.com/sindresorhus/guides/blob/master/npm-global-without-sudo.md

Brew doctor gives me the list of 110 /usr/local/include/node header files. Sigh.

So you promise that if I remove the node/npm site's install, along with the global npm modules, then do as suggested to use homebrew for managing node/npm .. mainly npm .. I'll be able to update both node and npm via homebrew safely?

You mention also deleting all the global installs. What about the --save and --save-dev local developer npm package installs? Do I have to also delete them? I.e. when I update them, will they fail, or just work, only global packages are at risk?

How in the world did we get into this mess! Sorry to be grouchy, and thanks for the help. A LOT! :)

@alexortiz201

This comment has been minimized.

Copy link

commented Nov 27, 2015

Thought I'd make a note of this, as of right now:
node v5.1.0 && npm -v3.5.0

I just recently updated and I realized none of my global commands were working. Went through the lengthy process up top and ran into the issue with rif... something not working when curl'ing npm.

โ€ข Fixed this by running suggested tip up above -> rm -rf ~/.npm
โ€ข Then, curl'ed again which worked. Afterwards I would run npm outdated and kept seeing and npm ERR! addLocal ..../package....
โ€ข Fixed this by running npm install -g npm@latest
โ€ข Afterwards I was noticing failures when trying npm upgrade -g, even tried npm upgrade -g and it still didn't work
โ€ข Fixed this by npm uninstalling global packages that didn't upgrade with the npm upgrade -g and reinstalling the global package (in other words anything showing up when running npm outdated -g)

I think it might have to do with how deps are handled in the newer versions because something I noticed was that any packages' deprecated deps were getting updated, this didn't happen before. Well, not a node expert so I'll leave the diagnosis to the pros.

@neraliu

This comment has been minimized.

Copy link

commented Dec 1, 2015

super

@mesut

This comment has been minimized.

Copy link

commented Dec 5, 2015

Thanks a lot

@AshCoolman

This comment has been minimized.

Copy link

commented Dec 5, 2015

Worked for me

@wiktusser

This comment has been minimized.

Copy link

commented Dec 5, 2015

thanks lot!

@rgiaccio

This comment has been minimized.

Copy link

commented Dec 7, 2015

Many thanks!

@alphapilgrim

This comment has been minimized.

Copy link

commented Dec 9, 2015

Cheers! Thank you!

@luis-carvalho

This comment has been minimized.

Copy link

commented Dec 9, 2015

Huuuuuge thanks! ๐Ÿค˜

@alextrastero

This comment has been minimized.

Copy link

commented Dec 11, 2015

Outstanding! ๐Ÿ‘

@judahstevenson

This comment has been minimized.

Copy link

commented Dec 15, 2015

This worked for me. I just had to update the PATH in my .bash_profile as I did not have a .path file, and this walkthrough held my hand nicely as I did it: http://dandean.com/nodejs-npm-express-osx/

@bertelledani

This comment has been minimized.

Copy link

commented Dec 16, 2015

Thanks a lot! ๐Ÿ‘

@LukeMichaels

This comment has been minimized.

Copy link

commented Dec 17, 2015

Thanks ๐Ÿ˜„

@rowrodrigues

This comment has been minimized.

Copy link

commented Dec 21, 2015

Thanks!

@amiralimatin

This comment has been minimized.

Copy link

commented Dec 22, 2015

great help guys, worked without any problems, thanks !

@MayankGoel1991

This comment has been minimized.

Copy link

commented Dec 25, 2015

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'cache', 'clean' ]
2 info using npm@1.4.28
3 info using node@v0.10.37
4 verbose node symlink /usr/bin/node
5 error Error: EACCES, unlink '/home/trinisoft/.npm/accepts/1.2.13'
5 error { [Error: EACCES, unlink '/home/trinisoft/.npm/accepts/1.2.13']
5 error errno: 3,
5 error code: 'EACCES',
5 error path: '/home/trinisoft/.npm/accepts/1.2.13' }
6 error Please try running this command again as root/Administrator.
7 error System Linux 3.16.0-51-generic
8 error command "/usr/bin/node" "/usr/bin/npm" "cache" "clean"
9 error cwd /home/trinisoft/Desktop/mayankproject
10 error node -v v0.10.37
11 error npm -v 1.4.28
12 error path /home/trinisoft/.npm/accepts/1.2.13
13 error code EACCES
14 error errno 3
15 error stack Error: EACCES, unlink '/home/trinisoft/.npm/accepts/1.2.13'
16 verbose exit [ 3, true ]

hey can anyone help me immediately by adding query on my id themayankgoel.mg@gmail.com,....................plz help me!!!! !important

@edanedison

This comment has been minimized.

Copy link

commented Dec 29, 2015

Really helped me out. Thanks :)

@BahiHussein

This comment has been minimized.

Copy link

commented Jan 1, 2016

Thanks

@iposton

This comment has been minimized.

Copy link

commented Jan 2, 2016

This worked for me as well. I don't understand why npm install -g npm deleted my npm without using sudo in the first place. These directions fixed my npm, but now when I install something I get a full width progress bar. and the install process looks different. not that it's overly important but did this happen to anyone else and do you happen to know why npm install looks different? maybe because I reinstalled node and everything is new and up to date now.

@Red4x

This comment has been minimized.

Copy link

commented Jan 7, 2016

Thank you it does helped me ๐Ÿ’ƒ

@aldorr

This comment has been minimized.

Copy link

commented Jan 13, 2016

Perfect!

@rajankambaliya

This comment has been minimized.

Copy link

commented Jan 20, 2016

Thanks!

@djperezh

This comment has been minimized.

Copy link

commented Jan 21, 2016

Thx !!!... that solve my ploblem for "cannot find module 'asn1'" error when trying to run npm commands

@jamigibbs

This comment has been minimized.

Copy link

commented Jan 22, 2016

Thank you for this! For anyone else struggling with where to add export PATH="$HOME/.node/bin:$PATH", I had to put the export in ~/.bash_profile.

@freddiecabrera

This comment has been minimized.

Copy link

commented Jan 29, 2016

I get this when I do brew install node --without-npm

Last 15 lines from /Users/freddiecabrera/Library/Logs/Homebrew/node/02.make:
         ^
In file included from ../deps/gtest/src/gtest-death-test.cc:34:
In file included from ../deps/gtest/include/gtest/gtest-death-test.h:41:
In file included from ../deps/gtest/include/gtest/internal/gtest-death-test-internal.h:40:
In file included from ../deps/gtest/include/gtest/internal/gtest-internal.h:40:
../deps/gtest/include/gtest/internal/gtest-port.h:259:10: fatal error: 'ctype.h' file not found
#include <ctype.h>   // for isspace, etc
         ^
1 error generated.
1 error generated.
make[1]: *** [/private/tmp/node20160128-4235-1ux7s39/node-v5.5.0/out/Release/obj.target/gtest/deps/gtest/src/gtest-port.o] Error 1
make[1]: *** [/private/tmp/node20160128-4235-1ux7s39/node-v5.5.0/out/Release/obj.target/gtest/deps/gtest/src/gtest-filepath.o] Error 1
1 error generated.
make[1]: *** [/private/tmp/node20160128-4235-1ux7s39/node-v5.5.0/out/Release/obj.target/gtest/deps/gtest/src/gtest-death-test.o] Error 1
make: *** [node] Error 2

READ THIS: https://git.io/brew-troubleshooting
@thatstoast

This comment has been minimized.

Copy link

commented Jan 29, 2016

Thank you so much. I am a Grunt noob and thought I was doomed. You rule!

@suryateja-nerusu

This comment has been minimized.

Copy link

commented Jan 29, 2016

thank you so much

@paprende

This comment has been minimized.

Copy link

commented Feb 5, 2016

Works a charm. thanks

@tuhinkanti

This comment has been minimized.

Copy link

commented Feb 11, 2016

๐Ÿ‘

@jasonwr

This comment has been minimized.

@tjaensch

This comment has been minimized.

Copy link

commented Feb 13, 2016

Worked for me, thanks for the step by step guide!

@JoelChev

This comment has been minimized.

Copy link

commented Feb 16, 2016

This finally fixed issues I was dealing with with my node, brew and bower installs. Thank you so very much! :)

@mirontoli

This comment has been minimized.

Copy link

commented Feb 20, 2016

After the steps provided here, I added following

export PATH="$HOME/.npm-packages/bin:$PATH"

Otherwise npm pointed to the wrong location (set by npm installer)

@winnemucca

This comment has been minimized.

Copy link

commented Mar 4, 2016

I got permission denied when I removed the node_modules. Do I have to do this as sudo?

@letnotimitateothers

This comment has been minimized.

Copy link

commented Mar 10, 2016

The process of @mmizutani solved my issue (I was stuck with -- npm: command not found --)
I think it's recommended to do a clean un-installation of the previous node.
brew uninstall node --force node

@ricardokdz

This comment has been minimized.

Copy link

commented Mar 22, 2016

+1

@larssn

This comment has been minimized.

Copy link

commented Mar 23, 2016

This guide unfortunately results in npm being unable to update itself:
$> npm update npm -g
npm ERR! addLocal Could not install /private/var/folders/pm/8bjhd30n6glfm340_ff1ln3c0000gp/T/npm.65676/package

Check npm/npm#11385

@JustJenFelice

This comment has been minimized.

Copy link

commented Mar 31, 2016

Thank you so much, @mirontoli - your suggestion re: adding NPM to my dot files did the trick!

Also, for anybody who is struggling to update NPM, have you tried the latest suggestion from the NPM site:

Node comes with npm installed so you should have a version of npm. However, npm gets updated more frequently than Node does, so you'll want to make sure it's the latest version.
sudo npm install npm -g

I noticed that a number of people (most recently @larssn) were trying to update instead of install - might be worth a try.

@aaleksa

This comment has been minimized.

Copy link

commented Apr 4, 2016

As mentioned @mirontoli
don't forget add into ~/.bash_profile this path:

export PATH="$HOME/.npm-packages/bin:$PATH"
otherwise it will not fin npm

@lordKnighton

This comment has been minimized.

Copy link

commented Apr 10, 2016

Just a head up, brew install node --without-npm If it looks like it stuck, just wait a bit longer
mine took 15 mins to finish

@KalenAnson

This comment has been minimized.

Copy link

commented Apr 15, 2016

+1 and yeah, node took days to install this time around.

@luiscobits

This comment has been minimized.

Copy link

commented Apr 17, 2016

Thanks!

@rickgregory

This comment has been minimized.

Copy link

commented Apr 21, 2016

curl -L https://www.npmjs.com/install.sh | sh KEPT giving me errors... if anyone else runs into this... update your PATH first, then run the script.

@elchingon

This comment has been minimized.

Copy link

commented Apr 26, 2016

There were some libraries conflicting with my Homebrew install in my $PATH..
I uninstalled node completely, then ran brew doctor and resolved all the issues in brew.
I then reinstalled node with brew.
brew install node

brew link --overwrite --dry-run node

brew link --overwrite node
Finally I was able to install libraries with npm again... thanks for the support and sharing this.

@vfweber

This comment has been minimized.

Copy link

commented Apr 27, 2016

worked like a charm! Thank you!

@iwasdavid

This comment has been minimized.

Copy link

commented Apr 30, 2016

I wish I'd found this 20 hours ago! Thanks!

@hbhakhra

This comment has been minimized.

Copy link

commented May 8, 2016

I've been struggling to get these instructions to work because I need to LTS version so I just gave up and decided to try the package from npmjs.org and that seems to be working great.

@somecallmejosh

This comment has been minimized.

Copy link

commented May 26, 2016

@mmizutani - your method is the only one that worked for me! Thank you for sharing it!

@anthonygore

This comment has been minimized.

Copy link

commented Jun 7, 2016

The solution by @SacWebDeveloper worked for me. Good advice to do cd ~ before starting to ensure you don't need sudo.

@briangordon

This comment has been minimized.

Copy link

commented Jun 7, 2016

I used these steps to install node and npm from scratch on my new machine:

brew install node --without-npm
echo prefix=~/.node >> ~/.npmrc
curl -L https://www.npmjs.org/install.sh | sh
echo "export PATH=\"\$HOME/.node/bin:\$PATH\"" >> ~/.bash_profile
npm install -g npm@latest

Note that the last command comes from npm/npm#11385.

@ashecret

This comment has been minimized.

Copy link

commented Jun 8, 2016

JUNE 8, 2016

I didn't have to install npm separately like I had to do before.

brew uninstall node to unintsall node
Use brew doctor to find any issue(s) and fix them.
I had to use brew prune to remove broken symlinks

Now brew install node to install node
Verify node and npm with node --version and npm --version

@MarkEspinosa

This comment has been minimized.

Copy link

commented Jun 18, 2016

can someone please help me out here I tried doing the steps @briangordon provided but I'm getting

ms-M:~ z$ echo "export PATH="$HOME/.node/bin:$PATH"" >> /.bash_profile
ms-M:
z$ npm install -g npm@latest
-bash: /usr/local/bin/npm: No such file or directory

@terryjray

This comment has been minimized.

Copy link

commented Jun 19, 2016

@MarkEspinosa, did you source your .bash_profile after modifying your path?

source ~/.bash_profile

You should be able to run the env command (env | grep PATH) and see that you've got the ~/.node/bin directory in your path.

@Sanabria

This comment has been minimized.

Copy link

commented Jun 29, 2016

@mirontoli Thank you! The export PATH="$HOME/.npm-packages/bin:$PATH" resolved my -bash: npm: command not found issue!

@bySabi

This comment has been minimized.

Copy link

commented Jul 4, 2016

Fix npm bash completion with:

echo 'source ~/.node/lib/node_modules/npm/lib/utils/completion.sh' >> ~/.bash_profile
source ~/.bash_profile
@dhcodes

This comment has been minimized.

Copy link

commented Jul 4, 2016

Thanks!

@yqrashawn

This comment has been minimized.

Copy link

commented Jul 5, 2016

Why I got command not found in my zsh on my mac pro. This works fine on my Macbook.

@VirenMohindra

This comment has been minimized.

Copy link

commented Jul 8, 2016

thank you for this! Remember to curl in the home directory and not anywhere else otherwise you're npm installation will keep on failing.
From the above comments, adding export PATH="$HOME/.npm-packages/bin:$PATH" into your .bash_profile.

@emandino

This comment has been minimized.

Copy link

commented Jul 19, 2016

This is my 3rd attempt at completing this installation over the last year and I've been struggling with it over the last month (again). Finally, I found a viable solution. Thank you guys, where would I be without my own brewing company? Here is what I had to do to ultimatelly make it work:

Warning: Running OS X El Capitan v10.11.15 on Mac mini (Late 2014)

brew doctor
brew update
rm -rf /usr/local/lib/node_modules
brew uninstall node

*In response to the homebrew warning errors I ran:
brew doctor
sudo port uninstall node
sudo mv /opt/local ~/macports
brew prune
brew doctor

*Once brew doctor adviced everything was fine and dandy I proceeded:
brew install node --without-npm
brew link --overwrite node
echo prefix=~/.npm-packages >> ~/.npmrc
curl -L https://www.npmjs.com/install.sh | sudo sh
echo export PATH="$HOME/.node/bin:$PATH"
echo export PATH="$HOME/.npm-packages/bin:$PATH" >> ~/.bash_profile
source ~/.bash_profile
sudo npm install -g npm@latest

Success!

Once again, thank you for all your contributions. I know, I know! Apple threatened to launch an update to macOS in the fall and everything is going to go down the drain again. I will cross that river when I reach that shore, now I have to "ketchup" (;-D) with all the stuff I have fallen behind. Owe you a keg!

@Brycetastic

This comment has been minimized.

Copy link

commented Jul 21, 2016

I following the instructions, fixed npm i and npm i any dependencies. Now, I am having a similar problem with using webpack. Any one know what is going wrong?

> cars2@1.0.0 start /Users/bmarshall/cars2
> webpack-dev-server

module.js:442
    throw err;
    ^

Error: Cannot find module 'webpack-dev-middleware'
    at Function.Module._resolveFilename (module.js:440:15)
    at Function.Module._load (module.js:388:25)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/usr/local/lib/node_modules/webpack-dev-server/lib/Server.js:3:28)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)

npm ERR! Darwin 14.5.0
npm ERR! argv "/usr/local/bin/node" "/Users/bmarshall/.npm-packages/bin/npm" "start"
npm ERR! node v6.2.2
npm ERR! npm  v3.10.5
npm ERR! code ELIFECYCLE
npm ERR! cars2@1.0.0 start: `webpack-dev-server`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the cars2@1.0.0 start script 'webpack-dev-server'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the cars2 package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     webpack-dev-server
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs cars2
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls cars2
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/bmarshall/cars2/npm-debug.log
@eno812

This comment has been minimized.

Copy link

commented Aug 4, 2016

Hi,

I installed NPM ages ago and now I can't remember if I installed directly or via hombrew. When I run the command 'which npm' it returns this, /usr/local/bin/npm

Does that mean it was installed directly from npm or brew.

The command 'which node' returns this, /usr/local/bin/node

But I know that node is installed via brew also.

I think I need help to clean up my install of NPM. Any suggestions?

@interglobalmedia

This comment has been minimized.

Copy link

commented Aug 4, 2016

Hi @eno812,

I am having npm issues with the -g flag, and came across this npm documentation: https://docs.npmjs.com/getting-started/fixing-npm-permissions. However, it resulted in even more questions on my part re fixing permissions. Specifically about altering my .profile (which I can't alter). So opened an issue in which I am asking whether I can create another profile just naming it differently and then using that. Waiting for their answer. But it might help you generally with your problem. You can also reach out to them directly via their repo if you have any other questions that might not be answerable by Homebrew. And as you said, you might not have installed with it. I originally was not able to because if I remember correctly, I THINK I had an issue installing Node with Homebrew. But I can't swear upon it. It was so long ago.

@dreamyguy

This comment has been minimized.

Copy link

commented Aug 5, 2016

For those still struggling to the point of giving up hope in node, try using https://github.com/brock/node-reinstall.

It will reset your node environment and you will be able to go on with your life. โœจ

I tried using homebrew to install node before and will strongly advise against it. The node-reinstall I mentioned above will get rid of falty installs, do a clean install and from there on you can rely on nvm to manage node versions... Peace!

@aleehpandita

This comment has been minimized.

Copy link

commented Aug 13, 2016

Thanks!

@numanayhan

This comment has been minimized.

Copy link

commented Aug 24, 2016

thank you my error is solved

@Vintharas

This comment has been minimized.

Copy link

commented Aug 25, 2016

Thanks! :)

@al-apex

This comment has been minimized.

Copy link

commented Aug 25, 2016

In addition to the steps the author mentioned, I needed to modify my $PATH or my npm and my npm installed programs wouldn't run.

I added the following lines to my .bash_profile

export PATH="$HOME/.npm/bin:$PATH"
export PATH="$HOME/.npm-packages/bin:$PATH"

@dmolesUC

This comment has been minimized.

Copy link

commented Sep 7, 2016

I don't have either a ~/.node/bin or ~/.npm/bin directory. Not sure where npm actually installed itself, though I do have a ~/.npm directory full of things (none of which is an executable called npm).

@Monte9

This comment has been minimized.

Copy link

commented Sep 12, 2016

Worked for me too although I had to install node and npm from the node website directly. Here is what I did:

  1. rm -rf /usr/local/lib/node_modules
  2. brew uninstall node
  3. Download and install node from here: https://nodejs.org/en/download/current/
  4. Add export PATH=$PATH:/usr/local/bin to your .bash_profile or .bashrc
    Hope this helps.
@fanky10

This comment has been minimized.

Copy link

commented Sep 20, 2016

Thanks!

@igor972

This comment has been minimized.

Copy link

commented Sep 24, 2016

Thanks <3

@lamass

This comment has been minimized.

Copy link

commented Sep 29, 2016

UR the Best!
Thanks a Million!

@semihsezer

This comment has been minimized.

Copy link

commented Oct 2, 2016

make sure to run "source ~/.bash_profile" after adding export PATH=$PATH:/usr/local/bin to your .bash_profile or .bashrc. This should be stated in the last step explicitly for dummies like me :)

thanks for this!

@revelt

This comment has been minimized.

Copy link

commented Oct 6, 2016

"Before you start, make a note of any globally installed npm packages."

If you came here because your npm itself is broken, you won't be able to call npm commands to view globally installed packages.
Luckily, you can see all of them by checking the folder: /usr/local/lib/node_modules!

@gowebvision

This comment has been minimized.

Copy link

commented Oct 6, 2016

Worked on my issue too. Thanks!

@srkrkalyan

This comment has been minimized.

Copy link

commented Oct 14, 2016

Great ! it fixed my issue

@marctorresbcn

This comment has been minimized.

Copy link

commented Oct 17, 2016

I have a little bitt problem, when execute this command:

brew install node --without-npm

In the screen prints:

Warning: You are using OS X 10.12. We do not provide support for this pre-release version. You may encounter build failures or other breakages. ==> Downloading https://nodejs.org/dist/v5.2.0/node-v5.2.0.tar.gz Already downloaded: /Library/Caches/Homebrew/node-5.2.0.tar.gz ==> Downloading https://ssl.icu-project.org/files/icu4c/56.1/icu4c-56_1-src.tgz Already downloaded: /Library/Caches/Homebrew/node--icu4c-56.1.tgz ==> ./configure --prefix=/usr/local/Cellar/node/5.2.0 --without-npm --with-intl=small-icu ==> make install

And the system stopped on this step...

@christinlepson

This comment has been minimized.

Copy link

commented Oct 17, 2016

Worked. Thanks

@myjeeed

This comment has been minimized.

Copy link

commented Oct 19, 2016

Had the same problem, and got it fixed! Thanks

@akpersad

This comment has been minimized.

Copy link

commented Oct 24, 2016

On OS 10.12. Worked perfectly. Thanks!

@ferbass

This comment has been minimized.

Copy link

commented Oct 28, 2016

thank you fix my issues :)

@georgir

This comment has been minimized.

Copy link

commented Nov 8, 2016

This is completely negleting use-cases with multiple users on the system. This just leaves other users without npm, unless they also install it for themselves, which is a very bad approach in my opinion.
EDIT: At the very least, the guide may be improved by clearly distinguishing the system-wide one-time steps from the steps that each user must take before being able to use npm. It might also not be a terrible idea to create a bogus npm executable in the system path that displays a message informing the users of those steps.

@shankariyerr

This comment has been minimized.

Copy link

commented Nov 10, 2016

Was struggling for almost a day and then I found this.

It Works. Thanks.

@mraniki

This comment has been minimized.

Copy link

commented Nov 13, 2016

Thanks!

@davidjhodge

This comment has been minimized.