Ubuntu apt-get未满足的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会导致"未满足的依赖项"。

我遵循这些指示,没有升级的软件包;https://askubuntu.com/questions/140246/how-do-i-resolve-unmet-dependencies-after-adding-a-ppa

我禁用了所有其他软件源,但仍然有问题。对于其他包(hhvm和mono),我一直遇到这个问题。我能做什么来解决这些问题?

我在安装npm时也有同样的症状和错误信息。

参考Node Package Manager got corrupte

您可以执行以下操作

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

sudo apt-get cleansudo apt-get -f install

clean清空。deb文件的本地缓存

-f表示"fix broken"

发生这种情况是因为nodejs已经安装在比最新版本的ubuntu更新的版本中,可能来自PPA。如果你删除当前的nodejs并安装ubuntu提供的nodejs,那么你可以安装npm。

您必须使用dpkg删除它以避免删除依赖:

sudo dpkg -r --force-depends nodejs

在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 install之前,执行以下步骤可能会有所帮助:

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

您得到的错误是因为npm包绑定到内置的nodejs包。

当从nodesource安装nodejs时,不需要安装npm ,因为它已经包含了npm

就这样做:

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install nodejs

将同时安装nodenpm

node -v
npm -v

最新更新