我如何解决`以下包有未满足的依赖关系`

时间:2014-10-26 08:52:59

标签: ubuntu npm

我使用此脚本安装基本软件,但由于网速较慢而不得不中断。 现在当我点击$ sudo apt-get install npm时,我收到以下错误

yask123@yaskslaptop:~$ sudo apt-get installed npm
E: Invalid operation installed
yask123@yaskslaptop:~$ 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.

12 个答案:

答案 0 :(得分:54)

如果sudo apt-get install -f <package-name>不起作用,请尝试 aptitude

sudo apt-get install aptitude
sudo aptitude install <package-name>

Aptitude会尝试解决问题。

举个例子,在我的情况下,我在尝试安装libcurl4-openssl-dev时仍然收到一些错误:

sudo apt-get install -f libcurl4-openssl-dev

所以我尝试了aptitude,结果发现我必须降级一些软件包。

The following actions will resolve these dependencies:

    Keep the following packages at their current version:
    1)     libyaml-dev [Not Installed]                        

Accept this solution? [Y/n/q/? (n)

The following actions will resolve these dependencies:

    Downgrade the following packages:                                
    1)     libyaml-0-2 [0.1.4-3ubuntu3.1 (now) -> 0.1.4-3ubuntu3 (trusty)]

Accept this solution? [Y/n/q/?] (Y)

答案 1 :(得分:22)

让Ubuntu修复未满足的依赖项和破坏的包的命令是

sudo apt-get install -f

来自手册页:

  

-f, - fix-broken              固定;尝试纠正具有破坏的依赖关系的系统。              此选项与install / remove一起使用时,可以省略任何包              允许APT推断可能的解决方案。如果是包              指定,这些必须完全纠正问题。选项              有时在第一次运行APT时是必要的;易于              本身不允许在a上存在破坏的包依赖关系              系统。系统的依赖结构可能是可能的              如此腐败,需要人工干预(这通常意味着              使用dselect(1)或dpkg - 删除一些              违规套餐)

运行命令时,Ubuntu会尝试自行修复。完成后,您可以通过再次运行命令来测试它是否有效,并且您应该收到类似于:

的输出
  

阅读包裹清单......完成   构建依赖树   阅读国家信息......完成   0升级,0新安装,0删除,2未升级。

答案 2 :(得分:16)

首先尝试这个

sudo apt-get update
sudo apt-get clean
sudo apt-get autoremove

如果错误仍然存​​在,请执行此操作

sudo apt --fix-broken install
sudo apt-get update && sudo apt-get upgrade
sudo dpkg --configure -a
sudo apt-get install -f

之后再试一次:

sudo apt-get install npm

但如果仍然无法解决问题,请使用sudo dpkg --configure -a检查依赖项,然后逐个删除它们。让我们说依赖关系是在npm然后去做,

sudo apt-get remove nodejs
sudo apt-get remove npm

然后转到/etc/apt/sources.list.d并删除任何节点列表(如果有)。然后做一个

sudo apt-get update

然后使用sudo dpkg --configure -a再次检查依赖项问题,如果一切都清楚,那么就完成了。 稍后再次使用此

安装npm
v=8   # set to 4, 5, 6, ... as needed
curl -sL https://deb.nodesource.com/setup_$v.x | sudo -E bash -

然后安装Node.js包。

sudo apt-get install -y nodejs

上面的答案也适用于一般情况(对于像django等其他软件包的依赖关系),就在前两个进程对你所依赖的软件包使用相同的进程之后。

答案 3 :(得分:12)

安装nodejs将安装npm ...所以只需删除nodejs然后重新安装它:     $ sudo apt-get remove nodejs

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

答案 4 :(得分:3)

我尝试了很多方法,但是下面的工作却像魅力一样。...

在此命令之后运行以下命令:-

curl -sL https://deb.nodesource.com/setup_14.x 565 | sudo -E bash -
sudo apt-get install -y nodejs

现在检查...

node -v
npm -v

答案 5 :(得分:1)

当我从最新的稳定版本安装node js时遇到了这种情况。

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -

似乎此版本已经预包装了NPM。因此,当我尝试再次安装NPM时,出现了此错误。如果有人以这种方式安装Node.js,则不需要单独安装NPM。

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.

答案 6 :(得分:1)

首先,运行

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

然后运行

sudo apt install npm

答案 7 :(得分:0)

我刚刚解决了这个问题。 问题出在版本冲突中。 npm安装了Nodejs 10。 因此,在安装nodejs之前-删除旧的npm。 或再次删除新节点->删除npm->安装节点。

这是唯一帮助我的方法。

答案 8 :(得分:0)

为我解决的是:

$ apt update
$ apt install nodejs

我从官方 Debian 存储库安装了 nodejs。这个是由unattended-upgrades安装的。在此之前,它是从 NodeSource 安装的。来自 NodeSource 的一个在 npm 包中有 nodejs

答案 9 :(得分:-1)

sudo apt install aptitude

然后

sudo aptitude install npm

来源:https://askubuntu.com/a/978353/458947

答案 10 :(得分:-1)

这是npm软件包中有关依赖项的错误: https://askubuntu.com/questions/1088662/npm-depends-node-gyp-0-10-9-but-it-is-not-going-to-be-installed

已报告错误。 根据您已安装的内容,以上内容可能无法正常工作,至少在最新的Ubuntu 18.04 LTS上对我而言不是。

我按照建议的依赖关系进行了安装,如上面的链接所示:

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

然后

sudo apt-get install npm

如果您受到影响,请订阅该错误:

bugs.launchpad.net/ubuntu/+source/npm/+bug/1517491
bugs.launchpad.net/ubuntu/+source/npm/+bug/1809828

答案 11 :(得分:-7)

Node安装了npm,因此你应该有一个npm版本。但是,npm比Node更频繁地更新,因此您需要确保它是最新版本。

尝试

sudo npm install npm -g