说在前面

比较常用的是方案二和方案三,实际上方案一比较少用到,基本解决不了问题,但是不方便删了,因为评论区大家都用方案二和方案三来讨论,删了或者调换位置会导致沟通困难

方案一

sudo dpkg –configure -a
sudo apt-get install -f
sudo apt-get clean && sudo apt-get update
sudo apt-get upgrade

如果报错 “some packages have been held back” ,输入

sudo apt-get dist-upgrade
sudo apt-get upgrade 

最后就可以尝试安装你想安装的包: sudo apt-get install <package-name>

方案二(修改过/etc/apt/sources.list或修改过软件源相关设置)

方案一来自 这个博客 这篇还讲了可以使用Synaptic软件,但是我没有尝试。

最后我选择了重装,然后就好了。再后来,我再次遇到这个问题,但是这次是在一个刚装好的ubuntu上,我只进行过几个操作,其中最可疑的就是到系统设置中关闭了系统更新。如下图。

在这里插入图片描述

在这里插入图片描述我取消了上图的几个勾选框,然后系统提示了一个需要更新软件的窗口,然后我选择了同意,如下图。
在这里插入图片描述
左右弹动的进度条完成之后,我再到shell中使用sudo apt install,就出现了题中的问题。

解决办法是修改系统的更新设置,勾选第二张图中的几个框(可能需要sudo密码)。

方案三(使用aptitude而不是apt-get)

又遇到了这个报错,这次是在安装libdb-dev时遇到的报错,完整报错是:

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:
 libdb-dev : Depends: libdb5.3-dev but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

解决方案来自 这个帖子

即使用下面命令来安装想安装的包:

sudo aptitude install <package-name>

如果提示 sudo: aptitude: command not found,则先安装 aptitude,即输入:

sudo apt-get install aptitude

再重新尝试使用aptitude安装。aptitude会尝试解决问题,并给出解决方案,询问你是否接受。在我的情况中,它给出的第一个方案是这样的:

(base) xiepengyu@c03:~/ROUGE/DB_File-1.835$ sudo aptitude install libdb-dev
The following NEW packages will be installed:
  libdb-dev libdb5.3-dev{ab}
The following packages will be REMOVED:
  libxatracker2{u} libxvmc1{u} x11-apps{u} x11-session-utils{u} xinit{u}
0 packages upgraded, 2 newly installed, 5 to remove and 39 not upgraded.
Need to get 743 kB of archives. After unpacking 2,772 kB will be freed.
The following packages have unmet dependencies:
 libdb5.3-dev : Depends: libdb5.3 (= 5.3.28-11) but 5.3.28-11ubuntu0.1 is installed.
The following actions will resolve these dependencies:

     Keep the following packages at their current version:
1)     libdb-dev [Not Installed]
2)     libdb5.3-dev [Not Installed]



Accept this solution? [Y/n/q/?] Y
The following packages will be REMOVED:
  libxatracker2{u} libxvmc1{u} x11-apps{u} x11-session-utils{u} xinit{u}
0 packages upgraded, 0 newly installed, 5 to remove and 39 not upgraded.
Need to get 0 B of archives. After unpacking 5,840 kB will be freed.
Do you want to continue? [Y/n/?] Y
(Reading database ... 423630 files and directories currently installed.)
Removing libxatracker2:amd64 (11.2.0-1ubuntu2) ...
Removing libxvmc1:amd64 (2:1.0.9-1ubuntu1) ...
Removing x11-apps (7.7+5+nmu1ubuntu1) ...
Removing x11-session-utils (7.7+2) ...
Removing xinit (1.3.4-3ubuntu0.1) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...
Processing triggers for man-db (2.7.5-1) ...

但是成功执行后,经过其他地方的使用发现我想安装的包还是没有被正确安装。我感觉第一个方案可能不一定最好,又尝试了第二个方案,也就是在询问是否接受第一个方案时选择否,即输入 n,第二个方案再输入Y,如下:

(base) xiepengyu@c03:~/ROUGE/DB_File-1.835$ sudo aptitude install libdb-dev
The following NEW packages will be installed:
  libdb-dev libdb5.3-dev{ab}
0 packages upgraded, 2 newly installed, 0 to remove and 39 not upgraded.
Need to get 743 kB of archives. After unpacking 3,068 kB will be used.
The following packages have unmet dependencies:
 libdb5.3-dev : Depends: libdb5.3 (= 5.3.28-11) but 5.3.28-11ubuntu0.1 is installed.
The following actions will resolve these dependencies:

     Keep the following packages at their current version:
1)     libdb-dev [Not Installed]
2)     libdb5.3-dev [Not Installed]



Accept this solution? [Y/n/q/?] n
The following actions will resolve these dependencies:

     Downgrade the following packages:
1)     libdb5.3 [5.3.28-11ubuntu0.1 (now) -> 5.3.28-11 (xenial)]



Accept this solution? [Y/n/q/?] Y
The following packages will be DOWNGRADED:
  libdb5.3
The following NEW packages will be installed:
  libdb-dev libdb5.3-dev{a}
0 packages upgraded, 2 newly installed, 1 downgraded, 0 to remove and 39 not upgraded.
Need to get 1,413 kB of archives. After unpacking 3,069 kB will be used.
Do you want to continue? [Y/n/?] Y
Get: 1 http://mirrors.ustc.edu.cn/ubuntu xenial/main amd64 libdb5.3 amd64 5.3.28-11 [670 kB]
Get: 2 http://mirrors.ustc.edu.cn/ubuntu xenial/main amd64 libdb5.3-dev amd64 5.3.28-11 [741 kB]
Get: 3 http://mirrors.ustc.edu.cn/ubuntu xenial/main amd64 libdb-dev amd64 1:5.3.21~exp1ubuntu2 [2,294 B]
Fetched 1,413 kB in 2s (473 kB/s)
dpkg: warning: downgrading libdb5.3:amd64 from 5.3.28-11ubuntu0.1 to 5.3.28-11
(Reading database ... 423471 files and directories currently installed.)
Preparing to unpack .../libdb5.3_5.3.28-11_amd64.deb ...
Unpacking libdb5.3:amd64 (5.3.28-11) over (5.3.28-11ubuntu0.1) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...
Setting up libdb5.3:amd64 (5.3.28-11) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...
Selecting previously unselected package libdb5.3-dev.
(Reading database ... 423471 files and directories currently installed.)
Preparing to unpack .../libdb5.3-dev_5.3.28-11_amd64.deb ...
Unpacking libdb5.3-dev (5.3.28-11) ...
Selecting previously unselected package libdb-dev:amd64.
Preparing to unpack .../libdb-dev_1%3a5.3.21~exp1ubuntu2_amd64.deb ...
Unpacking libdb-dev:amd64 (1:5.3.21~exp1ubuntu2) ...
Setting up libdb5.3-dev (5.3.28-11) ...
Setting up libdb-dev:amd64 (1:5.3.21~exp1ubuntu2) ...

然后之后发现已经成功安装想安装的包。

其他方案

参考下面这个英文帖子,总结了非常全面的原因以及方案,建议看原文尝试一下:

How do I resolve unmet dependencies after adding a PPA?

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐