sudo apt-get install npm没有安装

时间:2017-09-20 07:27:47

标签: node.js ubuntu npm npm-install

我试过运行sudo apt-get install npm它会在下面返回此对话框。我该如何解决这个问题?

Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
npm : Depends: node-gyp (>= 0.10.9) but it is not going to be 
installed
E: Unable to correct problems, you have held broken packages.

2 个答案:

答案 0 :(得分:4)

npm与nodejs一起安装。如果您安装了节点,那么您也有npm。

运行node -v检查节点是否已安装,然后运行npm -v为npm执行相同操作。

如果未安装nodejs,请在此处查看安装说明: https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions

6.x是当前的稳定分支。

通常,要运行擦除现有节点/ npm安装并从头开始安装,请运行:

sudo apt remove --purge nodejs node npm
sudo apt clean
sudo apt autoclean
sudo apt install -f
sudo apt autoremove

答案 1 :(得分:0)

安装node和npm的最佳和最简单的方法是通过nvm(节点版本管理器)。

  1. 运行以下代码以安装nvm

    curl -o- enter image description here | bash的

  2. 2.然后运行

    nvm install node
    

    npm将与节点

    一起安装

    此方法将是npm和节点安装的最简单,最安全的方法。

    要安装特定节点和npm,您可以像下面这样执行:

    nvm install v6.11.3
    

    希望这有帮助。