简体   繁体   English

Ubuntu 易于获取 NPM 的未满足依赖项

[英]Ubuntu apt-get unmet dependencies for NPM

I am trying to install NPM.我正在尝试安装 NPM。 To do so, I ran:为此,我跑了:

sudo apt-get install nodejs

This worked successfully.这成功了。 I then ran:然后我跑了:

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.

Trying to install node-gyp leads down an endless path of "unmet dependencies".尝试安装 node-gyp 会导致“未满足的依赖项”的无尽路径。

I followed these instructions and have 0 not upgraded packages;我遵循了这些说明并且有 0 个未升级的软件包; https://askubuntu.com/questions/140246/how-do-i-resolve-unmet-dependencies-after-adding-a-ppa https://askubuntu.com/questions/140246/how-do-i-resolve-unmet-dependencies-after-adding-a-ppa

I disabled all Other Software Source and still have problems.我禁用了所有其他软件源,但仍然有问题。 I keep running into this issue for other packages (hhvm and mono).对于其他软件包(hhvm 和 mono),我一直遇到这个问题。 What can I do to resolve these issues?我能做些什么来解决这些问题?

I exactly had the same symptom and error message when installing npm. 安装npm时,我确实有相同的症状和错误消息。

Refer to Node Package Manager got corrupted 请参阅Node Package Manager损坏

You can do the following 您可以执行以下操作

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  

This works on my Ubuntu 16.04.2 这适用于我的Ubuntu 16.04.2

Do sudo apt-get clean or sudo apt-get -f install . sudo apt-get cleansudo apt-get -f install

clean clears the local cache of .deb files. clean清除.deb文件的本地缓存。

-f means "fix broken". -f表示“修复损坏”。

This happens because the nodejs is already installed in a newer version than the latest ubuntu, possible from a PPA. 发生这种情况是因为nodejs已经安装在比最新的ubuntu更新的版本中,可能来自PPA。 If you remove the current nodejs and install the one provided by ubuntu, then you can install npm. 如果删除当前的nodejs并安装ubuntu提供的那个,那么你可以安装npm。

You've to remove it with dpkg to avoid remove dependencies: 您必须使用dpkg删除它以避免删除依赖项:

sudo dpkg -r --force-depends nodejs

On Ubuntu 18.04 I had packages installed that prevented the installation of npm dependencies: 在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

So the problem was that I had these three packages installed: 所以问题是我安装了这三个软件包:

libcurl4-openssl-dev libneon27-dev libssl-dev

After removing them, I could install npm without problems. 删除它们后,我可以毫无问题地安装npm。

Before running npm install , performing the following steps may help: 在运行npm install之前,执行以下步骤可能会有所帮助:

remove node_modules using rm -rf node_modules/ run npm cache clean 使用rm -rf node_modules/ run npm cache clean删除node_modules

The error you're getting is because the npm package is tied to the built-in nodejs package.您收到的错误是因为npm package 与内置的nodejs package 相关联。

You do not need to install npm when installing nodejs from nodesource, as it already includes npm .从 nodesource安装npm时不需要安装nodejs ,因为它已经包含npm

Just do this:只需这样做:

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

It will install both node and npm .它将安装nodenpm

node -v
npm -v

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM