NPM Command Not Found After Installing Node

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-29 20:41:11

问题


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:

When I type npm I get 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:$PATH to my .zshrc file. Still get the same error when typing npm

I can confirm it is in the path echo $PATH yields /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 -v yields v0.12.2

Any ideas? I'm stumped


回答1:


Not an answer, but maybe a solution...

Uninstall Node via brew: brew uninstall node

Then download Node from https://nodejs.org/en/download/ and install.

npm should then "just work".




回答2:


I came across to this thread with the same problem but finally below is what worked for me which is without 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



回答3:


Ok this is what worked for me:

$ brew update
$ brew uninstall node
$ brew install node
$ sudo brew postinstall node #This what the important step



回答4:


In case this never got solved, this is what worked for me:

  1. brew uninstall node
  2. brew install node
  3. brew doctor and 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). So brew prune didn'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:

  4. Delete those directories

  5. brew postinstall node

Hope it helps.




回答5:


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

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.

sudo chown -R myusername:myusergroup /usr/local/lib/node_modules
brew postinstall node



回答6:


Anyone on the LTS release use the following command instead:

brew postinstall node@6


来源:https://stackoverflow.com/questions/32749549/npm-command-not-found-after-installing-node

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!