我正在尝试升级到最新版本的节点。我在http://davidwalsh.name/upgrade-nodejs上按照说明操作

但当我这样做的时候:

sudo npm install -g n

我得到了错误:

sudo: npm: command not found

NPM没有sudo也能工作。当我这样做的时候:

whereis node

我明白了:

node: /usr/bin/node /usr/lib/node /usr/bin/X11/node /usr/local/node

运行:

which npm

显示:

/usr/local/node/bin/npm

我在https://stackoverflow.com/a/5062718/1246159上尝试了解决方案

但还是得到相同的错误。我还查看了/etc/sudoers文件,相关行是:

Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

在我看来这很好。我怎么可能得到NPM工作与sudo命令?


当前回答

所以,对于那些使用:

NVM和自制

请务必设置节点版本号。对我来说,我的节点版本已不再设置。所以,我检查了我使用的版本

nvm劳拉·舒尔茨

这列出了v16.13.1,所以我设置它使用这个

NVM使用16

一旦我的节点版本设置好,NPM命令又可以工作了

其他回答

I had the same issue,the reason for it was npm package manager was not installed while installing node. This was caused because of the following mistake: In the installation process there is a step called "Custom Setup", here you have the option to choose one of the following: 1) Node.js runtime (This is selected by default). 2) npm package manager 3) Online documentation shortcuts. 4) Add to Path. If you proceed as it is npm package manager will not be installed and hence you will get the error.

解决方案: 当你得到这些选项时,选择npm包管理器。 这对我很管用。

用于debian安装后的节点 输入

curl -k -O -L https://npmjs.org/install.sh    
ln -s /usr/bin/nodejs /usr/bin/node  
sh install.sh

简单地重新安装。

在RHEL、CentOS和Fedora上

sudo yum remove nodejs npm
sudo dnf remove nodejs npm   [On Fedora 22+ versions]

then

yum -y install nodejs npm
dnf -y install nodejs npm   [On Fedora 22+ versions]

简单! . . node和NPM现在都很好用!

我用……解决了这个问题

apt-get install npm2deb

npm文件应该在/usr/local/bin/npm.如果没有,请在他们的网站上重新安装node.js。这对我来说很管用。