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

3

我想在Debian 9上安装npm。

我已经尝试过以下步骤:

apt-get install nodejs

已经完全安装并且 nodejs -v 的结果是: v4.8.2
但是当尝试运行npm时,会出现错误:

bash: npm: command not found

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

sudo apt-get install npm

结果:

E: Package 'npm' has no installation candidate

根据我之前尝试的一份指南:

wget https://npmjs.org/install.sh 
sudo chmod +x install.sh
sudo ./install.sh

结果:

npm cannot be installed without node.js.

当然,我已经安装了Node.js。我还尝试了这种方法:
curl --silent --location https://deb.nodesource.com/setup_0.12 | sudo bash -
sudo apt-get update
sudo apt-get install --yes nodejs

It says:

nodejs is already the newest version (4.8.2~dfsg-1).

我该怎么办?


Node.js自带npm,所以您应该已经安装了npm的版本。您可以尝试运行npm -v命令查看版本号。我相信它已经存在了,如果没有,请安装它。 - Mykola Borysyuk
我在我的问题中提到了它:bash: npm: 命令未找到。我没有删除它,我只是按照我描述的方式安装了nodejs。 - ehsan shirzadi
1个回答

12

移除旧版本

sudo apt-get purge nodejs

安装新版本:

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs

或者,对于 Node.js 9:

curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
sudo apt-get install -y nodejs

来源

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接