Ubuntu apt-get 未满足的 NPM 依赖项

Ubuntu apt-get unmet dependencies for NPM

我正在尝试安装 NPM。为此,我 运行:

sudo apt-get install nodejs

这成功了。然后我 运行:

sudo apt-get install npm

 Reading state information... Done
 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.

尝试安装 node-gyp 导致 "unmet dependencies" 的无尽路径。

我按照这些说明进行操作,但有 0 个未升级的软件包; https://askubuntu.com/questions/140246/how-do-i-resolve-unmet-dependencies-after-adding-a-ppa

我禁用了所有其他软件源,但问题仍然存在。对于其他软件包(hhvm 和 mono),我将 运行 保留在这个问题中。我能做些什么来解决这些问题?

执行 sudo apt-get cleansudo apt-get -f install

clean 清除 .deb 文件的本地缓存。

-f 表示 "fix broken".

发生这种情况是因为 nodejs 已经安装在比最新 ubuntu 更新的版本中,可能来自 PPA。如果把现在的nodejs去掉,安装ubuntu提供的那个,就可以安装npm了。

您必须使用 dpkg 将其删除以避免删除依赖项:

sudo dpkg -r --force-depends nodejs

我在安装 npm 时遇到了完全相同的症状和错误消息。

参考Node Package Manager got corrupted

您可以执行以下操作

sudo apt-get remove nodejs npm ## remove existing nodejs and npm packages
sudo apt-get install curl  
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs  

这适用于我的 Ubuntu 16.04.2

在 运行宁 npm install 之前,执行以下步骤可能会有所帮助:

使用 rm -rf node_modules/ 删除 node_modules 运行npm cache clean

在 Ubuntu 18.04 我安装了阻止安装 npm 依赖项的软件包:

# apt install npm
...
 npm : Hängt ab von: node-gyp (>= 0.10.9) soll aber nicht installiert werden

# apt install node-gyp
...
 node-gyp : Hängt ab von: nodejs-dev soll aber nicht installiert werden

# apt install node-gyp nodejs-dev
...
 nodejs-dev : Hängt ab von: libssl1.0-dev (>= 1.0.2) soll aber nicht installiert werden

# apt install node-gyp nodejs-dev libssl1.0-dev
...
Die folgenden Pakete werden ENTFERNT:
  libcurl4-openssl-dev libneon27-dev libssl-dev

所以问题是我安装了这三个软件包:

libcurl4-openssl-dev libneon27-dev libssl-dev

删除它们后,我可以毫无问题地安装 npm。