node.js 须藤:npm:找不到命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31472755/
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
sudo: npm: command not found
提问by Mark
I'm trying to upgrade to the latest version of node. I'm following the instructions at http://davidwalsh.name/upgrade-nodejs
我正在尝试升级到最新版本的节点。我正在按照http://davidwalsh.name/upgrade-nodejs 上的说明进行操作
But when I do:
但是当我这样做时:
sudo npm install -g n
I get the error:
我收到错误:
sudo: npm: command not found
npm works without sudo. When I do:
npm 无需 sudo 即可工作。当我做:
whereis node
I see:
我懂了:
node: /usr/bin/node /usr/lib/node /usr/bin/X11/node /usr/local/node
Running:
跑步:
which npm
Shows:
节目:
/usr/local/node/bin/npm
I tried the solution at https://stackoverflow.com/a/5062718/1246159
我在https://stackoverflow.com/a/5062718/1246159尝试了解决方案
But I'm still getting the same error. I also looked at the /etc/sudoers file and the relevant line is:
但我仍然遇到同样的错误。我还查看了 /etc/sudoers 文件,相关行是:
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
This looks fine to me. How can I possibly get NPM working with sudo command?
这对我来说看起来不错。我怎样才能让 NPM 使用 sudo 命令?
采纳答案by inga
回答by Velocibadgery
I had to do
我必须做
sudo apt-get install npm
that worked for me.
这对我有用。
回答by Gao
For MAC users, the follow steps worked for me.
对于 MAC 用户,以下步骤对我有用。
$ brew update
$ brew uninstall node
$ brew install node
$ brew postinstall
回答by Vasanth Umapathy
I had the same problem; here are the commands to fix it:
我有同样的问题; 以下是修复它的命令:
sudo ln -s /usr/local/bin/node /usr/bin/nodesudo ln -s /usr/local/lib/node /usr/lib/nodesudo ln -s /usr/local/bin/npm /usr/bin/npmsudo ln -s /usr/local/bin/node-waf /usr/bin/node-waf
sudo ln -s /usr/local/bin/node /usr/bin/nodesudo ln -s /usr/local/lib/node /usr/lib/nodesudo ln -s /usr/local/bin/npm /usr/bin/npmsudo ln -s /usr/local/bin/node-waf /usr/bin/node-waf
回答by Hymansonkr
WARNING (edit)
警告(编辑)
Doing a chmod 777is a fairly radical solution. Try these first, one at a time, and stop when one works:
做 achmod 777是一个相当激进的解决方案。首先尝试这些,一次一个,并在一个有效时停止:
$ sudo chmod -R 777 /usr/local/lib/node_modules/npm$ sudo chmod -R 777 /usr/local/lib/node_modules$ sudo chmod g+w /usr/local/lib$ sudo chmod g+rwx /usr/local/lib
$ sudo chmod -R 777 /usr/local/lib/node_modules/npm$ sudo chmod -R 777 /usr/local/lib/node_modules$ sudo chmod g+w /usr/local/lib$ sudo chmod g+rwx /usr/local/lib
$ brew postinstall nodeis the only install part where I would get a problem
$ brew postinstall node是唯一会出现问题的安装部分
Permission denied - /usr/local/lib/node_modules/npm/.github
So I
所以我
// !! READ EDIT ABOVE BEFORE RUNNING THIS CODE !!
$ sudo chmod -R 777 /usr/local/lib
$ brew postinstall node
and viola, npm is now linked
和中提琴,npm 现在已链接
$ npm -v
3.10.10
Extra
额外的
If you used -R 777on libmy recommendation would be to set nested files and directories to a default setting:
如果您-R 777在lib 上使用,我的建议是将嵌套文件和目录设置为默认设置:
- $
find /usr/local/lib -type f -print -exec chmod 644 {} \; - $
find /usr/local/lib -type d -print -exec chmod 755 {} \; - $
chmod /usr/local/lib 755
- $
find /usr/local/lib -type f -print -exec chmod 644 {} \; - $
find /usr/local/lib -type d -print -exec chmod 755 {} \; - $
chmod /usr/local/lib 755
回答by maudulus
I had to do the following:
我必须执行以下操作:
brew updatebrew uninstall node- Visit https://nodejs.org/en/download the file
- Install the downloaded file
brew updatebrew uninstall node- 访问https://nodejs.org/en/下载文件
- 安装下载的文件
回答by u5985526
For CentOS users, this works for me:
对于 CentOS 用户,这对我有用:
sudo yum install npm
回答by Prakash Ramasamy
In order to install npm packages globally with sudo permission, /usr/bin/npmshould be available. If npmexists on some other directory, create a soft link like:
为了使用 sudo 权限全局安装 npm 包,/usr/bin/npm应该可用。如果npm存在于其他目录中,请创建一个软链接,如:
sudo ln -s /usr/local/bin/npm /usr/bin/npm
It works on Fedora 25, node8.0.0 and npm5.0.0
它适用于 Fedora 25、node8.0.0 和 npm5.0.0
回答by friederbluemle
On macOS, this worked for me:
在 macOS 上,这对我有用:
brew reinstall node
回答by Shaharyar Zafar
For debian after installing node enter
对于安装节点后的 debian 输入
curl -k -O -L https://npmjs.org/install.sh
ln -s /usr/bin/nodejs /usr/bin/node
sh install.sh

