Create a gist now

Instantly share code, notes, and snippets.

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.


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 | 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
npm http 304
npm http GET
npm http 304
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 commented Apr 17, 2014

Thanks! πŸ‘

Outstanding! πŸ‘

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

Fredriks-MacBook-Pro% curl -L | 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
bsdtar 2.8.3 - libarchive 2.8.3
install npm@latest

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

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

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! 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.

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

Thanks this helped me fix my npm issues

Huge help. Thanks.

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

SO much this! Extremely helpful.

Thank you!

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 commented Nov 3, 2014

Thanks a ton!

cmezian commented Nov 10, 2014

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

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 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?

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.

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?

thanks your are the πŸ‘¨

Incredibly helpful. Thanks so much.

aljopro commented Dec 28, 2014

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

Thank you!

kaishin commented Dec 31, 2014

This worked great, thanks!

thank you!

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

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

Thanks for the gist!

phudekar commented Jan 6, 2015

Thanks. You saved my day

Serious thanks for this!

favorit commented Jan 20, 2015

Thank you! It works for me!

awesome, i'm back in business, thanks!


ghost commented Jan 24, 2015

Thankyou so much!

More thanks from me, too ;)


Thank you so very much!

fa3 commented Feb 3, 2015

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

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

Thank you so much!

guimap commented Feb 11, 2015

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

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

$ curl -L | 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: Permission denied rm: No such file or directory Failed to download script

mnlsn commented Feb 15, 2015

use curl -L | sh if you get the Permission Denied error when installing npm

rowild 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!!!

Worked like a charm!


jserrao commented Feb 23, 2015

FYI: 'curl -L | 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 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:

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?

Thanks so much.

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

πŸ‘ thank you!

Excelent ! (Y)

guoylyy commented Mar 27, 2015

Excelent! Thanks a lot.

Thanks πŸ‘

Thanks! Nothing's ever easy...

mitogh commented Apr 5, 2015

Thanks, works perfect. πŸ‘

arnelh commented Apr 15, 2015


Thank you!

Thanks so much!

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

Awesome, thanks!

zekitow commented Apr 24, 2015



buk commented Apr 27, 2015




SGD1953 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.

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

curl -L | 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
bsdtar 2.8.3 - libarchive 2.8.3
install npm@latest

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

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

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

Thank you very much! Works a treat!

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

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

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


0is1 commented May 18, 2015

Yes, thanks! This was really helpful :)

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.

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


ghost commented May 28, 2015

Thank you!!!

ser111 commented May 30, 2015

You're the man.

jonrh 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 commented Jun 8, 2015

thanks :)

adaam2 commented Jun 12, 2015

This is awesome! great work

jromeem commented Jun 14, 2015

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

bghill 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: 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.

This is awesome. Thank you.

Excellent. Thank you!

git clone 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


gbanis 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 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!

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.

Thanks, It worked 😊

Working like a glove!


ghost commented Jul 13, 2015

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

Thank you very much, it worked! ;)

Didn't work for me

Got the following error:

-bash: npm: command not found

My .bash_profile:

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

My .bashrc:

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 commented Jul 24, 2015

Worked like a charm. Thank you!

philals commented Jul 26, 2015


ljhan 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 commented Aug 2, 2015


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

nick$ curl -L | 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
bsdtar 2.8.3 - libarchive 2.8.3
install npm@latest
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?

@WeHateNick try $ curl -L | sudo sh

@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

THANKYOU @aliwatters this has been bugging me for days!

Cannot install, get error: " Permission denied" when attempting "curl -L | sh"

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.

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

Thanks a lot!

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

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 | 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

πŸ‘ all good here, thanks!

ilysm, thanks!

huijing commented Sep 25, 2015

Following the steps but when I run curl -L | sh I get the following errors:

scripts/ 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!     <>

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?

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

beastmike commented Sep 29, 2015

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

rcastag commented Oct 2, 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.
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.

Great! It Works fine for me!

skad21 commented Oct 11, 2015

Very helpfull tips...great, thanks !

@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.


ocaoimh commented Oct 17, 2015

Brilliant. Thanks!


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

Gusbenz commented Oct 21, 2015

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

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

njv commented Oct 29, 2015

Thank you!

mattsilv commented Nov 2, 2015

thank you. Worked well on OSX 10.10

Thanks πŸ‘

Thanks! πŸ‘

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

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 | 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.

You sir ROCK

I actually fixed my npm with this:

brew postinstall node

Thanks you!!

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:

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! :)

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 commented Dec 1, 2015


mesut commented Dec 5, 2015

Thanks a lot

Worked for me

thanks lot!

rgiaccio commented Dec 7, 2015

Many thanks!

Cheers! Thank you!

Huuuuuge thanks! 🀘

Outstanding! πŸ‘

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:

Thanks a lot! πŸ‘

Thanks πŸ˜„


great help guys, worked without any problems, thanks !

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,....................plz help me!!!! !important

Really helped me out. Thanks :)


iposton 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 commented Jan 7, 2016

Thank you it does helped me πŸ’ƒ

aldorr commented Jan 13, 2016



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

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.

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/
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/] Error 1
make[1]: *** [/private/tmp/node20160128-4235-1ux7s39/node-v5.5.0/out/Release/] Error 1
1 error generated.
make[1]: *** [/private/tmp/node20160128-4235-1ux7s39/node-v5.5.0/out/Release/] Error 1
make: *** [node] Error 2


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

thank you so much

paprende commented Feb 5, 2016

Works a charm. thanks


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

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

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)

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

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

larssn 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

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 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

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

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


curl -L | sh KEPT giving me errors... if anyone else runs into this... update your PATH first, then run the script.

elchingon 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 commented Apr 27, 2016

worked like a charm! Thank you!

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

hbhakhra 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 and that seems to be working great.

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

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

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 | 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 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 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
z$ npm install -g npm@latest
-bash: /usr/local/bin/npm: No such file or directory

@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.

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

bySabi commented Jul 4, 2016

Fix npm bash completion with:

echo 'source ~/.node/lib/node_modules/npm/lib/utils/' >> ~/.bash_profile
source ~/.bash_profile

dhcodes commented Jul 4, 2016


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

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.

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 | 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


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!

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

    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! 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 commented Aug 4, 2016


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 commented Aug 4, 2016

Hi @eno812,

I am having npm issues with the -g flag, and came across this npm documentation: 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.

For those still struggling to the point of giving up hope in node, try using

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!


numanayhan commented Aug 24, 2016

thank you my error is solved

Thanks! :)

al-apex 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"

dmolesUC3 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 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:
  4. Add export PATH=$PATH:/usr/local/bin to your .bash_profile or .bashrc
    Hope this helps.

fanky10 commented Sep 20, 2016


igor972 commented Sep 24, 2016

Thanks <3

lamass commented Sep 29, 2016

UR the Best!
Thanks a Million!

semihsezer 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 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!

rluberda commented Oct 6, 2016

Worked on my issue too. Thanks!

Great ! it fixed my issue

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 Already downloaded: /Library/Caches/Homebrew/node-5.2.0.tar.gz ==> Downloading 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...

Worked. Thanks

myjeeed commented Oct 19, 2016

Had the same problem, and got it fixed! Thanks

On OS 10.12. Worked perfectly. Thanks!

ferbass commented Oct 28, 2016

thank you fix my issues :)

georgir 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.

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

It Works. Thanks.

mraniki commented Nov 13, 2016


Thank you so much. After all day of trying, this worked for me. YOU'RE THE BEST.

Hi, tried this out and I'm getting this error...

ERR! Darwin 15.6.0
ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "watch"

npm ERR! node
npm ERR!
npm v3.10.8
npm ERR!
file sh
ERR! syscall spawn

Not sure what I did wrong. Any help is greatly appreciated. Thanks

Thank you! You're a saver!

using npm start will spin processor to 140%

great!! thanks!

This worked perfectly. Thank you for this excellent guide.

TangHui123 commented Dec 16, 2016

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

I have add this to .bash_profile. and source .bash_profile.

npm -v but still shows"zsh: command not found: npm"

but export PATH="$HOME/.npm-packages/bin:$PATH" add ~/.zshrc work well

Oimah commented Dec 17, 2016

Worked but i can no longer run npm from vs code.

Amazing. Thanks for posting this

worked for Bash on Ubuntu on Windows 10 !!

thanks @aliwatters that worked for me!

eaglerockdude commented Jan 7, 2017

I tried it but got stuck on the brew's make install.. it would not finish...I have 100G of space on my HD.

finally had to just download the installer.

The info on deleting was useful for me though.

jbwl commented Feb 8, 2017

It worked, but when I try to npm update -g, this error is shown:

npm ERR! addLocal Could not install /private/var/folders/j9/45xyj_0x0h598hhp47zbl5ph0000gn/T/npm.56653/package

It worked, thank you! I worked on this for 3 hours, I appreciate your help.

Thanks a ton!

FYI brew install node --without-npm took 13 minutes to complete on my machine.

I'd advise adding the -v flag to monitor progress so you aren't wondering if it's frozen.

@fjarrett Thanks for the recommendation of using -v, great idea!

ylem commented Apr 14, 2017

Fix my problem, thanks * 10!

thank you fix my issues πŸ‘ ^__^

Thanks! saved my day πŸ‘

dlopez commented Jun 16, 2017

Dude! You rock!

opichon commented Jun 20, 2017

This doesn't work for me on OSX El Capitan 10.11.6. The ~.npm-packages/lib/node_modules/npm link in invalid.

olivier at Oliviers-iMac in ~/.npm-packages/lib/node_modules
$ ls -al ~/.npm-packages/bin/
total 8
drwxr-xr-x  3 olivier  staff  102 Jun 20 11:18 .
drwxr-xr-x  6 olivier  staff  204 Jun 20 11:18 ..
lrwxr-xr-x  1 olivier  staff   38 Jun 20 11:18 npm -> ../lib/node_modules/npm/bin/npm-cli.js

olivier at Oliviers-iMac in ~/.npm-packages/lib/node_modules
$ ls -al
total 8
drwxr-xr-x  3 olivier  staff  102 Jun 20 11:18 .
drwxr-xr-x  3 olivier  staff  102 Jun 20 11:18 ..
lrwxr-xr-x  1 olivier  staff   88 Jun 20 11:18 npm -> ../../../../../private/var/folders/4t/5jpfcscj7qn1d3h3yf43477c0000gn/T/npm.96631/package

There are 2 things wrong with that link: There is a /private/var/folder/4t/5.../T/ directory, but the relative paht of the link is incorrect. Second, in that directory there are lots of npm-xxxxx-xxxxxxxx sub-dirs, but no npm.96631/.

colbygk commented Jun 21, 2017

For the reasons already stated, the instructions above have not aged well. If you are starting fresh on a more recent version of OS X, a better solution is:

$ brew install node
$ npm install npm --global

This will correctly allow you to do global npm installs and provides an up-to-date version of npm.

squidbe commented Jun 23, 2017

@colbygk, Thanks, I spent hours getting nowhere till I saw your comment.

mhumeSF commented Jun 25, 2017

@colbygk πŸ‘

@colbygk πŸ‘

note if you have previously used these instructions, but have updated OSX, and are now trying to use the instructions that @colbygk posted, don't forget to edit your .npmrc and remove the prefix line.

nickbouton commented Jul 20, 2017

@Bradleycorn @colbygk Thanks for this! πŸ‘ Needed to re-map the prefix to get things working globally as expected.

Instructions here in addition to @colbygk's steps above worked for me.

Please stop saying if a solution worked for you. Just add an emoji πŸ‘ This keeps issues focused on the solution.

murich commented Sep 5, 2017

Tried all above and keep receiving shit like this
Error: Cannot find module '/private/var/folders/5p/mqsyqy3n1gs0ktbt20s2z_6w0000gn/T/npm.39067/package/bin/read-package-json.js'

igr commented Sep 26, 2017

Same as @murich

igr commented Sep 26, 2017

Just uninstall/install the node again using brew.

supreets commented Sep 29, 2017

I get this error when i try installing node.

#brew install node --without-npm

==> Downloading
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/node/0.10.29 --without-npm
File "./configure", line 319
SyntaxError: Missing parentheses in call to 'print'


/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/open-uri.rb:353:in open_http': 422 Unprocessable Entity (GitHub::Error) from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/open-uri.rb:709:inbuffer_open'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/open-uri.rb:210:in block in open_loop' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/open-uri.rb:208:incatch'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/open-uri.rb:208:in open_loop' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/open-uri.rb:149:inopen_uri'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/open-uri.rb:689:in open' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/open-uri.rb:30:inopen'
from /usr/local/Library/Homebrew/utils.rb:318:in open' from /usr/local/Library/Homebrew/utils.rb:350:inissues_matching'
from /usr/local/Library/Homebrew/utils.rb:378:in issues_for_formula' from /usr/local/Library/Homebrew/exceptions.rb:171:infetch_issues'
from /usr/local/Library/Homebrew/exceptions.rb:167:in issues' from /usr/local/Library/Homebrew/exceptions.rb:207:indump'
from /usr/local/Library/brew.rb:158:in rescue in <main>' from /usr/local/Library/brew.rb:66:in

Same error as @murich. Just download the pkg from the Node website, and install it. Done!

Just download the pkg from the Node website, and install it. Done!

Except when I want to update Node, or npm. Which I do, frequently, so that I’m up-to-date with security fixes.

For everything that plays nicely, and is played with nicely by, Homebrew, I do this once a week:

$ brew doctor; brew update; brew upgrade;

Now, for Node or npm or both, I have do something extra? Well, hurray.

mailcz8 commented Oct 17, 2017

My Mac has "El Capitan", and after I installed brew, then did "brew install node", my "npm" does not work and return following error. I searched online for all solution, I did delete/clean out node and reinstall, nothing work. Please help!!!

70 chang:~$npm appium@1.6.5
throw err;

Error: Cannot find module '/usr/local/lib/node_modules/npm/bin/node_modules/npm/bin/npm-cli.js'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:383:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:496:3

Same error as @murich

jace45 commented Oct 20, 2017

So I did everything, but then I started to get:
bash: usr/local/bin/npm no such file or directory

So then I made sure I had: export PATH="$HOME/.npm-packages/bin:$PATH" in my ~/.bash_profile (/.zshrc in my case)

Well that didn't work either so I added export PATH="$HOME/.node/bin:$PATH" why?? Cause that was a popular suggestion on this thread. Still no progress.

After more exploring and trying to get my npm to be found in the correct path...I said screw it. And did brew uninstall node --force node and then just reinstalled node the regular way...through the website: (mac) this was simple and it installed npm along with it...exactly in the location I wanted it to be as well.

I hope this saves someone some time.

Okay, guys. I found this because I had serious issues with my (brew-provided) npm.

In actuality, this guide just gave me the same error as @murich got, and I'm actually glad, because as it turns out, homebrew has been playing nice for quite a while here.

My problem was due to having hacked in a version of node@5 on top of the latest node after node@5 was actually discontinued by brew β€” it seems mostly because of exactly problems with npm β€” which fucked everything up royally.

My new setup, having removed any explicit prefix in ~/.npmrc, and just using the npm that comes along with the latest brewed node, works just perfectly. Remember that this fix is four years old, and stuff has changed since then.

On my setup, node and npm by brew work just perfectly, globally installed modules linked into $HOMEBREW_PREFIX/bin, man pages working, etc.

It may be better for me because I've chosen to install brew to ~/Library/Homebrew, but I can't be sure. For the record, though, I've used brew forever outside of /usr/local, and it's never ever not worked.

Here I have found one problem while applying this article. I was trying to install NPM separately not work in my case I have installed with node itself.

smit26 commented Nov 14, 2017

@jace45 - that worked very well! Thanks

webia1 commented Nov 16, 2017

If you use a node package manager (whatever it is), you should remove all installed versions like

brew uninstall --force node


ehwest commented Nov 17, 2017

Followed exactly; got this.

Error: No such file or directory @ rb_sysopen

vesper8 commented Dec 6, 2017

thanks for this.. maybe by 2020 we'll be able to use brew to install npm again

clondon commented Dec 8, 2017

Thanks for this Dan,
npm was driving me mad with all the little bits that need special attention. The problem with using this system is that there are some many dependencies interlinked in ways that a newbie (well me) just can't grasp at first, and that you couldn't even ask for help easily.
I'd ask why gulp watch-bs is not found in some theme, for instance, then be told do exactly what you said "npm update npm -g" to fix everything, which didn't work then you'd be digitally f#*'ed for the next week repeating the same old steps.
As we all know, doing the same again and expecting different results is a form of insanity.
Finally, a man who understood and offered a solution.

Many thanks.

OMG thank-you!!!

If you are still having issues with npm after this, there is an issue where NPM is failing in the script. Go to the following link and follow the directions and it should work. It fixed my issue.

webuxr commented Jan 3, 2018

For what it's worth, the link listed in @lancecmarks comment^ is the very page you're looking at:

EDIT: There's a lot of history in this (@DanHerbert 's) post. However, @lancecmarks has a bad link to @rcugut 's gist (which itself is a fork of @DanHerbert work)...

In other words, if you are still dealing with fixing "...npm if you've installed Node through Homebrew on Mac OS X or Linuxbrew" ... continue reading @rcugut 's post:

edmcl commented Jan 19, 2018

Thank you for sharing!

vpilot commented Jan 23, 2018

Here is a simple fix for those who installed node via Homebrew but struggled with npm installation.

Remove npm if any
rm -rf ~/.npm-packages/lib/node_modules/npm

Download and unpack the latest version of npm.
curl -L | tar xz

Move unpacked package into node_modules folder
mv ~/package ~/.npm-packages/lib/node_modules/npm

Make sure to have following variables set in your ~/.bash_profile

export NPM_PACKAGES="$HOME/.npm-packages"
export NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"

Source the file
source ~/.bash_profile

suvajit commented Jan 24, 2018

If you fail to install npm as described above then refer to this link :

please update your gist or at least put in @colbygk comment in the text. could save someone an hour

wow. i had the usr folder when starting this, but, for some reason, did not have it when finished. tried to install npm on my project after completing this process and it told me: /usr/local/bin/npm: No such file or directory . I tried looking for the usr folder, which I had open in the Finder before doing this whole process, but now all I see is that ghost. If I try to find it in another Finder window, it is gone gone gone. Very sad.

jace45 your post saved me!

Thank you @jace45 ! Saved me too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment