I'm trying to install nodejs on mac using homebrew, but when I run the command:

brew install node

I get the following error:

Beginning with 0.8.0, this recipe now comes with npm.
It appears you already have npm installed at /usr/local/lib/node_modules/npm.
To use the npm that comes with this recipe, first uninstall npm with
`npm uninstall npm -g`, then run this command again.

If you would like to keep your installation of npm instead of
using the one provided with homebrew, install the formula with
the `--without-npm` option.

but when I run:

sudo npm uninstall npm -g

I get:

sudo: npm: command not found

When I run the command npm, I get:

-bash: /usr/local/bin/npm: No such file or directory

so I'm not sure whether it's actually installed or not.

My node version is 0.8.22 (I have no idea where it came from). How should I update it to the latest version?

  • If you use homebrew just use it and nothing else. I would try to uninstall using brew first. Also did yiu install node via home-brew?
    – mmmmmm
    Jun 14, 2013 at 13:22

3 Answers 3


Is /usr/local/bin/npm a broken symlink? That would make sudo npm print an error like command not found and npm print an error like No such file or directory.

You could try creating a new symlink for node:

$ rm /usr/local/bin/npm; brew unlink node; brew link node
Unlinking /usr/local/Cellar/node/0.10.5... 4 links removed
Linking /usr/local/Cellar/node/0.10.5... 5 symlinks created
$ sudo /usr/local/bin/npm uninstall npm -g

Or use /usr/local/opt/node/bin/npm:

$ ls -l `brew --prefix node`
lrwxr-xr-x  1 lauri  admin  21 Jun 14 18:27 /usr/local/opt/node -> ../Cellar/node/0.10.5
$ sudo /usr/local/opt/node/bin/npm uninstall npm -g

I realize this is years old, but after dealing with these sorts of file permission and package manager problems myself for many years, a buddy of mine and I created a rather simple solution that works without sudo, and without relying on brew or other package managers.

Install with webi

On Mac or Linux:

curl -s https://webinstall.dev/node@stable | bash

Or, on Windows 10 (which now includes curl.exe - so no msysgit or cygwin needed):

curl.exe -sA "MS" https://webinstall.dev/node@stable | powershell

More info at https://webinstall.dev/node (also has a link to the source for the bash and powershell)

Upgrade / Switch Versions

And then you can switch versions (upgrade, downgrade, etc) like this:

webi node     # 'stable' is the default tag
webi node@lts # long-term support
webi node@v10 # specifically the latest of v10

Doing the same by hand

webi is just a small helper / bootstrap script in bash (or powershell on Windows 10), and you could do the same by hand:

  • Check the node.js releases API: https://nodejs.org/dist/index.tab
  • Get the desired version: https://nodejs.org/dist/latest/
  • Unpack to $HOME/.local/opt/node
  • Add $HOME/.local/opt/node/bin to your PATH
    • (in .zshrc, .bashrc, .profile, the Windows Registry, or with pathman)
  • On macOS 10.14+ you may need to use
    • xattr -r -d com.apple.quarantine ~/.local/opt/node/bin/node

Then when you need to update versions, remove the node directory (rm -rf ~/.local/opt/node) and then repeat the above steps with the new version.

Note: This requires re-installing any global tools, such as jshint or prettier.

  • If you keep getting downvotes you may consider removing the parts expalining how to apply to solution to Windows and Linux systems.
    – nohillside
    Jul 11, 2020 at 8:58
  • I don't mind downvotes. Haters gonna hate. I believe it's valuable to know that this particular solution also works on Windows and Linux and I stand by that.
    – coolaj86
    Jul 11, 2020 at 9:28
  • P.S. Thank you for your concern and your suggestion. If you personally find it distracting from the solution I'd like to better understand that thought process and it may drive me to change the answer.
    – coolaj86
    Jul 11, 2020 at 9:29
  • 2
    Personally I don’t mind. But AD is focused on Apple products, and answers tend to attract downvoted if they specifically are tailored for other environments as well
    – nohillside
    Jul 11, 2020 at 9:42
  • 1
    Well, I suppose we can't all be tolerant and inclusive all of the time. ;-)
    – coolaj86
    Jul 11, 2020 at 20:00

For me, NVM solved all my problems with complexity in nodejs, like "node version", "npm version", "yarn version". Installing anything in nodejs is super simple using nvm.

You can install via Homebrew using this formula

brew install nvm

then update it with the install version you want by writing:

$ nvm use 16
Now using node v16.9.1 (npm v7.21.1)
$ node -v
$ nvm use 14
Now using node v14.18.0 (npm v6.14.15)
$ node -v
$ nvm install 12
Now using node v12.22.6 (npm v6.14.5)
$ node -v

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .