brew install npm"npm:command not found"

Pet*_*Pik 38 bash node.js npm osx-elcapitan

我已经安装了节点使用brew install node,当我使用时,node -v我得到了以下内容v5.0.0.但是,当我尝试运行npm命令时,我得到了npm: command not found.

我试图跑brew install npm,但我得到了以下回应node-5.0.0 already installed.

它发生在节点也返回命令未找到,但我通过运行修复brew link node,但是npm仍然似乎不起作用.

我该如何解决这个问题?

小智 49

我遇到了同样的问题.在网上搜索和阅读不同的东西之后,对我有用的是:

$ brew postinstall node
Run Code Online (Sandbox Code Playgroud)

但是,首先请执行:

$ brew doctor
Run Code Online (Sandbox Code Playgroud)

并按照那里的说明进行操作,就像您提问中的评论一样.

  • 对我来说,这是由于运行`brew install node`时的链接问题.成功运行`brew link node`后,我还需要运行`brew postinstall node`来添加`npm`. (5认同)
  • 更新:尽管这确实可行,但运行`brew remove --force yarn && brew remove --force node`然后运行`brew install node` fixed npm,这样我就不再需要调用`brew postinstall node`了。然后我叫“ brew install yarn”。因此,我认为部分问题是安装了多个版本的yarn和/或node。 (2认同)

and*_*lrc 23

您需要确保设置了您的$NODE_PATH环境变量:

# Add this to your ~/.bash_profile file:
export NODE_PATH="/usr/local/lib/node_modules"
Run Code Online (Sandbox Code Playgroud)

您还可以尝试以下方法:

运行以下命令以删除所有现有的全局npm模块,卸载node&npm,使用正确的默认值重新安装节点,将npm安装为自己的pacakge,并配置要安装的全局npm模块的位置.

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:https://gist.github.com/DanHerbert/9520689

  • --without-npm选项不再有效 (3认同)

小智 13

请尝试以下方法:

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

  • 对于 mac 用户来说,这是一个正确的工作答案。第4步是问题的解决方案 (3认同)