我使用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仍然似乎不起作用。
我该如何解决这个问题?
您需要确保设置了$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
我遇到了同样的问题。在网上搜索和阅读不同的东西后,对我有用的是:
$ brew postinstall node
但是,首先请执行:
$ brew doctor
并按照那里的说明进行操作,就像您提问中的评论一样。
请尝试以下方法:
$ brew update
$ brew uninstall node
$ brew install node
$ sudo chown -R YouComputerName /usr/local/lib/node_modules/
$ brew postinstall node
和你一样的问题,我修正了:
/usr/local/lib/node_modules/npm/bin/npm-cli.js i -g npm
我在mac上的hostname / computername中使用了西里尔语(非拉丁语)字符。这就是问题所在。在我改变了这个并重新安装了node / npm与Homebrew后,一切正常。 2017年没有utf8? :/