node.js 安装节点后找不到 NPM 命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32749549/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NPM Command Not Found After Installing Node
提问by Nicholas Haley
I am having a very hard time getting the npm command to work, and unfortunately my knowledge of unix isn't good enough to solve this on my own. All I've done is brew install node, and I get the following errors:
我很难让 npm 命令正常工作,不幸的是,我对 unix 的了解不足以自己解决这个问题。我所做的就是brew install node,我收到以下错误:
When I type npmI get zsh: command not found: npm
当我输入时,npm我得到zsh: command not found: npm
Looking into this issue more I found this stack overflow answer:
深入研究这个问题,我发现了这个堆栈溢出答案:
Command not found after npm install in zsh
Following its advice I tried adding export PATH=/usr/local/share/npm/bin:$PATHto my .zshrc file. Still get the same error when typing npm
按照它的建议,我尝试添加export PATH=/usr/local/share/npm/bin:$PATH到我的 .zshrc 文件中。输入时仍然出现相同的错误npm
I can confirm it is in the path echo $PATHyields /Users/nicholashaley/.rbenv/shims:/Users/nicholashaley/.rbenv/bin:/Applications/Postgres.app/Contents/Versions/9.3/bin:/usr/local/heroku/bin:/usr/local/share/npm/bin:/usr/local/bin:/Applications/Postgres.app/Contents/Versions/9.3/bin:/usr/local/heroku/bin:/Users/nicholashaley/.rbenv/shims:/usr/local/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
我可以证实它是在路径echo $PATH产量/Users/nicholashaley/.rbenv/shims:/Users/nicholashaley/.rbenv/bin:/Applications/Postgres.app/Contents/Versions/9.3/bin:/usr/local/heroku/bin:/usr/local/share/npm/bin:/usr/local/bin:/Applications/Postgres.app/Contents/Versions/9.3/bin:/usr/local/heroku/bin:/Users/nicholashaley/.rbenv/shims:/usr/local/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
I can also confirm that node has been installed node -vyields v0.12.2
我还可以确认节点已安装node -v产量v0.12.2
Any ideas? I'm stumped
有任何想法吗?我难住了
回答by Adrian Lynch
Not an answer, but maybe a solution...
不是答案,但也许是解决方案......
Uninstall Node via brew: brew uninstall node
通过 brew 卸载 Node: brew uninstall node
Then download Node from https://nodejs.org/en/download/and install.
然后从https://nodejs.org/en/download/下载 Node并安装。
npmshould then "just work".
npm那么应该“正常工作”。
回答by Venkat.R
I came across to this thread with the same problem but finally below is what worked for me which is without sudo
我遇到了同样的问题,但最后下面是对我有用的没有 sudo
$ brew update
$ brew uninstall node
$ brew install node
$ chown -R YourUserName /usr/local/lib/node_modules/
$ brew postinstall node #This what the important step
回答by Nicholas Haley
Ok this is what worked for me:
好的,这对我有用:
$ brew update
$ brew uninstall node
$ brew install node
$ sudo brew postinstall node #This what the important step
回答by keaglin
In case this never got solved, this is what worked for me:
如果这从未得到解决,这对我有用:
brew uninstall nodebrew install nodebrew doctorand see what needs to be pruned. My problem was there was a non-brew place where I had changed my install location for npm packages because I was trying to get an npm package to install for me. That was a mistake (having forgotten I initially installed node and npm through brew but now brew could no longer reach the npm install directory nor could it change or delete it). Sobrew prunedidn't work even though the symlinks were supposedly deleted but it reminded me that I had changed the npm install location. And that brings us to:Delete those directories
brew postinstall node
brew uninstall nodebrew install nodebrew doctor并查看需要修剪的内容。我的问题是有一个非 brew 的地方我已经更改了 npm 包的安装位置,因为我试图为我安装一个 npm 包。这是一个错误(忘记了我最初通过 brew 安装了 node 和 npm,但现在 brew 无法再访问 npm install 目录,也无法更改或删除它)。所以brew prune即使符号链接被删除也不起作用,但它提醒我我已经更改了 npm 安装位置。这让我们想到:删除那些目录
brew postinstall node
Hope it helps.
希望能帮助到你。
回答by Vaibhav Rathore
I found this article helpful with step-by-step details:
https://www.dyclassroom.com/howto-mac/how-to-install-nodejs-and-npm-on-mac-using-homebrew
我发现这篇文章对分步细节很有帮助:https:
//www.dyclassroom.com/howto-mac/how-to-install-nodejs-and-npm-on-mac-using-homebrew
Additionally, after all the steps in above article, node was working but my machine was still giving "command not found: npm". I then ran the following two commands and npm was working.
此外,在上述文章中的所有步骤之后,节点正在工作,但我的机器仍然给出“找不到命令:npm”。然后我运行了以下两个命令,npm 正在工作。
sudo chown -R myusername:myusergroup /usr/local/lib/node_modules
brew postinstall node
回答by mils
Anyone on the LTS release use the following command instead:
LTS 版本中的任何人都使用以下命令:
brew postinstall node@6

