brew install npm “npm: command not found”

送分小仙女□ 提交于 2019-12-02 21:44:52

You need to make sure that your $NODE_PATH environment variable is set:

# Add this to your ~/.bash_profile file:
export NODE_PATH="/usr/local/lib/node_modules"

You can also try the following:

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

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

Kudus to: https://gist.github.com/DanHerbert/9520689

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.

Try the following:

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

the same problem with you, I fixed by:

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!