brew install npm" npm:command not found"

时间:2015-11-06 20:19:39

标签: node.js bash 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似乎仍然不起作用。

如何解决此问题?

5 个答案:

答案 0 :(得分:41)

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

$ brew postinstall node

但是,首先请执行:

$ brew doctor

并首先按照说明进行操作,例如您提问中的评论。

答案 1 :(得分:19)

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

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

您还可以尝试以下操作:

  

运行以下命令以删除所有现有的全局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

答案 2 :(得分:9)

尝试以下方法:

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

答案 3 :(得分:1)

与你同样的问题,我修正了:

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

答案 4 :(得分:0)

我在mac上的hostname / computername中使用了西里尔语(非拉丁语)字符。这就是问题所在。在我改变了这个并重新安装了node / npm与Homebrew后,一切正常。 2017年没有utf8? :/