Peter Pik
Peter Pik

Reputation: 11193

brew install npm "npm: command not found"

I've installed node using brew install node and when I use the node -v I get following v5.0.0. However when I try to run the npm command I get npm: command not found.

I've tried to run brew install npm, however I just got following response node-5.0.0 already installed.

It happened with node also returning command not found, but that I fixed by running brew link node, however npm still does not seem to work.

How can I resolve this problem?

Upvotes: 70

Views: 77979

Answers (7)

dexbyte
dexbyte

Reputation: 305

I fixed it by running brew link node@18, remember to use @ if you installed a specific version from the brew, otherwise brew link node should work.

If you are not sure what version you install, you can go to the folder /opt/homebrew/Cellar/ to check what version of node you have installed.

Upvotes: 6

Andreas Louv
Andreas Louv

Reputation: 47099

Try running

$ brew postinstall node

If you ever ran sudo npm / sudo yarn, then you might need to change the owner of your global node_modules folder:

$ sudo chown -R "$(id -un)" "${NODE_PATH:-/usr/local/lib/node_modules}"

Upvotes: 56

dian.in
dian.in

Reputation: 541

Try the following:

$ brew update
$ brew uninstall node
$ brew install node
$ sudo chown -R YourLocalUserName /usr/local/lib/node_modules/
$ brew postinstall node

Upvotes: 54

Pianisimo
Pianisimo

Reputation: 109

running: echo 'export PATH="/opt/homebrew/opt/node@16/bin:$PATH"' >> ~/.zshrc should work, change node@16 to just node or which ever version you just installed.

Upvotes: 2

zhulinpinyu
zhulinpinyu

Reputation: 629

the same problem with you, I fixed by:

/usr/local/lib/node_modules/npm/bin/npm-cli.js i -g npm

Upvotes: 3

ttt
ttt

Reputation: 6809

I used cyrillic (non-latin) characters in my hostname/computername on mac. And that was the problem. After i changed this and reinstalled node/npm with Homebrew everything worked like normal. No utf8 in 2017? :/

Upvotes: 0

mpavel
mpavel

Reputation: 1181

I encountered the same issue. After searching and reading different things online, what worked for me was:

$ brew postinstall node

However, first please do execute:

$ brew doctor

and follow the instructions there first, like the comment in your question mentions.

Upvotes: 95

Related Questions