无法安装npm-无法解决问题,您持有损坏的包装?


27

我正在尝试将nodejs升级到7.6,但失败了。现在,在重新安装节点6.10之后,我遇到了一个新问题:

$ sudo apt-get purge nodejs npm
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package 'npm' is not installed, so not removed
The following packages were automatically installed and are no longer required:
  linux-headers-4.8.0-40 linux-headers-4.8.0-40-generic linux-image-4.8.0-40-generic linux-image-extra-4.8.0-40-generic
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED
  nodejs*
0 to upgrade, 0 to newly install, 1 to remove and 53 not to upgrade.
After this operation, 51.7 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 278133 files and directories currently installed.)
Removing nodejs (6.9.5-1nodesource1~yakkety1) ...
Processing triggers for man-db (2.7.5-1) ...
(Reading database ... 274476 files and directories currently installed.)
Removing nodejs (6.9.5-1nodesource1~yakkety1) ...
Purging configuration files for nodejs (6.9.5-1nodesource1~yakkety1) ...
dpkg: warning: while removing nodejs, directory '/usr/lib/node_modules' not empty so not removed

为什么这么说Package 'npm' is not installed, so not removed?我一直在使用npm为我的项目安装许多节点软件包!

我忽略该错误并继续安装节点7.6:

$ curl -sL https://deb.nodesource.com/setup_7.6 | sudo -E bash - 
bash: line 1: html: No such file or directory
bash: line 2: syntax error near unexpected token `<'
'ash: line 2: `<head><title>404 Not Found</title></head>

所以我回到了节点6.x。但是我不能再安装npm了:

$ sudo apt-get install npm
Reading package lists... Done
Building dependency tree       
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: nodejs but it is not going to be installed
       Depends: node-abbrev (>= 1.0.4) but it is not going to be installed
       Depends: node-ansi (>= 0.3.0-2) but it is not going to be installed
       Depends: node-ansi-color-table but it is not going to be installed
       Depends: node-archy but it is not going to be installed
       Depends: node-block-stream but it is not going to be installed
       Depends: node-fstream (>= 0.1.22) but it is not going to be installed
       Depends: node-fstream-ignore but it is not going to be installed
       Depends: node-github-url-from-git but it is not going to be installed
       Depends: node-glob (>= 3.1.21) but it is not going to be installed
       Depends: node-graceful-fs (>= 2.0.0) but it is not going to be installed
       Depends: node-inherits but it is not going to be installed
       Depends: node-ini (>= 1.1.0) but it is not going to be installed
       Depends: node-lockfile but it is not going to be installed
       Depends: node-lru-cache (>= 2.3.0) but it is not going to be installed
       Depends: node-minimatch (>= 0.2.11) but it is not going to be installed
       Depends: node-mkdirp (>= 0.3.3) but it is not going to be installed
       Depends: node-gyp (>= 0.10.9) but it is not going to be installed
       Depends: node-nopt (>= 3.0.1) but it is not going to be installed
       Depends: node-npmlog but it is not going to be installed
       Depends: node-once but it is not going to be installed
       Depends: node-osenv but it is not going to be installed
       Depends: node-read but it is not going to be installed
       Depends: node-read-package-json (>= 1.1.0) but it is not going to be installed
       Depends: node-request (>= 2.25.0) but it is not going to be installed
       Depends: node-retry but it is not going to be installed
       Depends: node-rimraf (>= 2.2.2) but it is not going to be installed
       Depends: node-semver (>= 2.1.0) but it is not going to be installed
       Depends: node-sha but it is not going to be installed
       Depends: node-slide but it is not going to be installed
       Depends: node-tar (>= 0.1.18) but it is not going to be installed
       Depends: node-underscore but it is not going to be installed
       Depends: node-which but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

有任何想法吗?


2
请尝试此操作sudo apt install -f,然后尝试重新安装!
乔治·乌德森

Answers:


41

我在使用npm时遇到了同样的问题,必须按顺序安装以下软件包:

sudo apt install libssl1.0-dev
sudo apt install nodejs-dev
sudo apt install node-gyp
sudo apt install npm

希望这可以帮助


1
我已经为此苦苦挣扎了两个小时,并且这种工作就像一种魅力。谢谢!
desveladisimo

(在Kubuntu 18.04上)我以前安装过libssl-dev,事实证明它对应于libssl1.1,但是npm显然需要1.0。我必须删除libssl-dev并将其替换为libssl1.0-dev,然后一切正常。适当的错误对于确定错误所在没有用,因此您的答案是挽救生命。
理查德·胡松

是! 谢谢!(Ubuntu 18.04.3 LTS)
Toni Homedes i Saun

非常感谢,这对我有帮助
Muthusamy

34

我对npm有同样的问题。

我建议您安装aptitude,它可以帮助您解决冲突

sudo apt install aptitude

然后以合适的方式安装您的软件包

sudo aptitude install npm

1
最佳解决方案必须尝试,如果遇到未满足的依赖关系错误
Rj_Innocent_Coder

真的很棒。这解决了问题
Jerrychayan

我有一个依赖问题。我只能找到解决方案。谢谢。
karjedavpalaa
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.