brew install npm“npm:command not found”

问题描述 投票:31回答:5

我使用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.js bash npm osx-elcapitan
5个回答
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

圣洁:https://gist.github.com/DanHerbert/9520689


41
投票

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

$ brew postinstall node

但是,首先请执行:

$ brew doctor

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


9
投票

请尝试以下方法:

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


1
投票

和你一样的问题,我修正了:

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


0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.