软件包“ npm”没有候选安装

ehs*_*adi 0 ubuntu debian node.js npm npm-install

我想在Debian 9中安装npm。

apt-get install nodejs
Run Code Online (Sandbox Code Playgroud)

完全安装和nodejs -v结果:v4.8.2
但是,当尝试运行npm时,错误提示:

bash: npm: command not found
Run Code Online (Sandbox Code Playgroud)

根据搜索,我尝试了其他方法:根据此指南:https : //www.godaddy.com/help/install-nodejs-ubuntu-17395我尝试了:

sudo apt-get install npm
Run Code Online (Sandbox Code Playgroud)

结果:

E: Package 'npm' has no installation candidate
Run Code Online (Sandbox Code Playgroud)

根据我尝试过的另一指南:

wget https://npmjs.org/install.sh 
sudo chmod +x install.sh
sudo ./install.sh
Run Code Online (Sandbox Code Playgroud)

结果:

npm cannot be installed without node.js.
Run Code Online (Sandbox Code Playgroud)

当然,我已经安装了nodejs。我也尝试过这种方式:

curl --silent --location https://deb.nodesource.com/setup_0.12 | sudo bash -
sudo apt-get update
sudo apt-get install --yes nodejs
Run Code Online (Sandbox Code Playgroud)

它说:

nodejs is already the newest version (4.8.2~dfsg-1).
Run Code Online (Sandbox Code Playgroud)

我该怎么办?

har*_*tap 6

删除旧版本

sudo apt-get purge nodejs
Run Code Online (Sandbox Code Playgroud)

安装新版本:

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
Run Code Online (Sandbox Code Playgroud)

或者,对于Node.js 9:

curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
sudo apt-get install -y nodejs
Run Code Online (Sandbox Code Playgroud)

资源

它可能告诉您缺少gnupg2软件包,只需安装它即可。