如何解决“下列包有未满足的依赖项”

我用这个脚本安装基本的软件,但不得不中断,因为缓慢的互联网速度。 现在,当我按 $ 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.
366123 次浏览

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

sudo apt-get install -f

来自手册页:

- F-修好了-坏了 修正; 尝试修正具有破碎依赖项的系统。 这个选项在安装/删除时可以省略任何包 允许 APT 推断出可能的解决方案 指定,这些必须完全纠正问题。选项 有时在第一次运行 APT 时是必需的; itself does not allow broken package dependencies to exist on a 一个系统的依赖结构可能是 so corrupt as to require manual intervention (which usually means 使用 dselect (1)或 dpkg —— delete 消除一些 违例包裹)

Ubuntu will try to fix itself when you run the command. When it completes, you can test if it worked by running the command again, and you should receive output similar to:

看包裹清单... 搞定 构建依赖关系树 读取状态信息... 完成 0升级,0新安装,0删除和2没有升级。

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

试试看

sudo npm install npm -g

如果 sudo apt-get install -f <package-name>不起作用,试试 才能:

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

Aptitude will try to resolve the problem.

例如,在我的例子中,在尝试安装 libcurl4-openssl-dev时仍然会收到一些错误:

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

所以我试了试天资,结果我不得不降级一些包裹。

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)

安装 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

首先试试这个

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

The answer above will work for general cases also(for dependencies on other packages like django ,etc) just after first two processes use the same process for the package you are facing dependency with.

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

Curl-sL https://deb.nodesource.com/setup_10.x | sudo-e bash-

这个版本似乎已经提供了一个预先打包的 NPM。所以当我再次尝试安装 NPM 时,我得到了这个错误。如果有人以这种方式安装 Nodejs,则不需要单独安装 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.


I just solved this issue. 问题在于版本冲突。 安装了 npm 的 Nodejs 10。 因此,在安装 nodejs 之前,请删除旧的 npm。 或者删除 new node-> 删除 npm-> 再次安装 node。

这是唯一能帮到我的方法。

sudo apt install aptitude

然后

sudo aptitude install npm

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

这是 npm 包中关于依赖性的一个 bug: 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

如果你受到影响,请订阅 bug:

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

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

在这个命令之后运行以下命令:-

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

Now check…

node -v
npm -v

首先,跑

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

那就跑吧

sudo apt install npm

对我来说,解决问题的办法是:

$ apt update
$ apt install nodejs

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

我在 Pop OS 上就是这么做的:

强制覆盖 Node 包(使用您的版本更改 nodejs _ 16.9.0-deb-1nodesource1 _ amd64.deb) :

sudo dpkg -i --force-overwrite /var/cache/apt/archives/nodejs_16.9.0-deb-1nodesource1_amd64.deb

修复其余的安装问题:

sudo apt -f install

确保系统的其他部分正确更新:

sudo apt update
sudo apt dist-upgrade

归功于 Matigo: https://askubuntu.com/questions/1362719/error-upgrading-nodejs

Ubuntu 22.04已经将 libssl1升级为 libssl3,因此您需要添加 Ubuntu 21.10源代码并强制安装 libssl1。

在终端上试试这个:

echo "deb http://security.ubuntu.com/ubuntu impish-security main" | sudo tee /etc/apt/sources.list.d/impish-security.list


sudo apt-get update
sudo apt-get install libssl1.1

sudo apt install apt帮我解决了这个问题