如何解决dpkg依赖问题?

administrator@zlounes:~$ sudo apt-get dist-upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
You might want to run 'apt-get -f install' to correct these.
The following packages have unmet dependencies:
 linux-server : Depends: linux-headers-server (= 3.2.0.37.44) but 3.2.0.37.45 is installed
E: Unmet dependencies. Try using -f.
administrator@zlounes:~$ sudo apt-get -f install
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following extra packages will be installed:
  linux-image-server linux-server
The following packages will be upgraded:
  linux-image-server linux-server
2 upgraded, 0 newly installed, 0 to remove and 9 not upgraded.
4 not fully installed or removed.
Need to get 0 B/4,458 B of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue [Y/n]? y
Traceback (most recent call last):
  File "/usr/bin/apt-listchanges", line 237, in <module>
    main()
  File "/usr/bin/apt-listchanges", line 48, in main
    debs = apt_listchanges.read_apt_pipeline(config)
  File "/usr/share/apt-listchanges/apt_listchanges.py", line 83, in read_apt_pipeline
    return map(lambda pkg: filenames[pkg], order)
  File "/usr/share/apt-listchanges/apt_listchanges.py", line 83, in <lambda>
    return map(lambda pkg: filenames[pkg], order)
KeyError: 'linux-image-server'
Setting up initramfs-tools (0.99ubuntu13.1) ...
update-initramfs: deferring update (trigger activated)
Setting up linux-image-3.2.0-37-generic (3.2.0-37.58) ...
Running depmod.
update-initramfs: deferring update (hook will be called later)
The link /initrd.img is a dangling linkto /boot/initrd.img-3.2.0-37-generic
Examining /etc/kernel/postinst.d.
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.2.0-37-generic /boot/vmlinuz-3.2.0-37-generic
update-initramfs: Generating /boot/initrd.img-3.2.0-37-generic

gzip: stdout: No space left on device
E: mkinitramfs failure cpio 141 gzip 1
update-initramfs: failed for /boot/initrd.img-3.2.0-37-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
Failed to process /etc/kernel/postinst.d at /var/lib/dpkg/info/linux-image-3.2.0-37-generic.postinst line 1010.
dpkg: error processing linux-image-3.2.0-37-generic (--configure):
 subprocess installed post-installation script returned error exit status 2
dpkg: dependency problems prevent configuration of linux-image-server:
 linux-image-server depends on linux-image-3.2.0-37-generic; however:
  Package linux-image-3.2.0-37-generic is not configured yet.
dpkg: error processing linux-image-server (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of linux-server:
 linux-server depends on linux-image-server (= 3.2.0.37.44); however:
  Package linux-image-server is not configured yet.
 linux-server depends on linux-headers-server (= 3.2.0.37.44); however:
  Version of linux-headers-server on system is 3.2.0.37.45.
dpkg: error processing linux-server (--configure):
 dependency problems - leaving unconfigured
Processing triggers for initramfs-tools ...
update-initramfs: Generating /boot/initrd.img-3.2.0-36-generic
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          No apport report written because the error message indicates its a followup error from a previous failure.

gzip: stdout: No space left on device
E: mkinitramfs failure cpio 141 gzip 1
update-initramfs: failed for /boot/initrd.img-3.2.0-36-generic with 1.
dpkg: error processing initramfs-tools (--configure):
 subprocess installed post-installation script returned error exit status 1
No apport report written because MaxReports is reached already
                                                              Errors were encountered while processing:
 linux-image-3.2.0-37-generic
 linux-image-server
 linux-server
 initramfs-tools
E: Sub-process /usr/bin/dpkg returned an error code (1)

我试了很多次都不行。我想可能是我中断了一个安装过程,结果把一切都搞砸了。我已经谷歌了并尝试了各种修复方法。
编辑(清理了我的/boot文件夹后):
administrator@zlounes:/boot$ sudo apt-get -f install
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following extra packages will be installed:
  linux-server
The following packages will be upgraded:
  linux-server
1 upgraded, 0 newly installed, 0 to remove and 9 not upgraded.
1 not fully installed or removed.
Need to get 0 B/1,734 B of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue [Y/n]? y
Traceback (most recent call last):
  File "/usr/bin/apt-listchanges", line 237, in <module>
    main()
  File "/usr/bin/apt-listchanges", line 48, in main
    debs = apt_listchanges.read_apt_pipeline(config)
  File "/usr/share/apt-listchanges/apt_listchanges.py", line 83, in read_apt_pipeline
    return map(lambda pkg: filenames[pkg], order)
  File "/usr/share/apt-listchanges/apt_listchanges.py", line 83, in <lambda>
    return map(lambda pkg: filenames[pkg], order)
KeyError: 'linux-server'
dpkg: dependency problems prevent configuration of linux-server:
 linux-server depends on linux-image-server (= 3.2.0.37.44); however:
  Version of linux-image-server on system is 3.2.0.37.45.
 linux-server depends on linux-headers-server (= 3.2.0.37.44); however:
  Version of linux-headers-server on system is 3.2.0.37.45.
dpkg: error processing linux-server (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          E: Sub-process /usr/bin/dpkg returned an error code (1)
administrator@zlounes:/boot$

2为什么你认为包依赖有问题,而错误信息却显示“gzip: stdout: No space left on device”?在我看来,这似乎是因为你没有足够的空间来安装软件,导致依赖项未能安装。 - Rinzwind
请在df的结果中添加。我猜你的/boot分区已满。 - Rinzwind
谢谢:)我已经清理了我的/boot文件夹,但是我又遇到了相同的错误(我在我的第一篇帖子中编辑了错误代码)。非常感谢您,并对我的英语表达不好表示抱歉。 - zlounes
通过“清理我的引导文件夹”,你是指删除了该文件夹中的文件吗?你可能不会喜欢这样做的结果。 - colboynik
不,没事,我已经选择了文件 ;) - zlounes
5个回答

确保您的系统状态良好且没有中断安装问题的一个不错的尝试是调用该命令。
  dpkg --configure -a 

确保软件包列表已更新,并且没有显示任何问题的情况下:
 apt-get update

可选,您可以在更新之前删除所有旧数据。
 find /var/lib/apt/lists -type f  |xargs rm -f >/dev/null \

解决问题的下一步是暂时移除linux-server软件包。 这样做是因为它没有实际内容,只引入了一个依赖关系:

该软件包将始终依赖于可用的最新完整Linux内核, 适用于服务器设备。

 dpkg --remove linux-server

检查所有当前的依赖项是否已安装完成。
apt-get install -f

如果一切正常,你现在可以再次安装linux-server
apt-get install linux-server

附言

linux-server 已在 12.04 版本中停止使用。对于服务器设备,将使用通用内核。请参阅apt-cache show linux-image-server

软件包:linux-image-server...

部分: 元包

....

依赖项:linux-image-3.2.0-23-generic,linux-firmware


非常感谢。我以为我要花一整天重新安装服务器。。 - uncletall
不对。这个“答案”根本没有任何作用。我遇到了完全相同的问题,只不过问题出在python3这个包上。按照这些步骤,用python3代替linux-server,结果除了一路上不断出现原始错误之外,什么也没有改变,只有那个“可选”命令回应了一个>符号。 - undefined

我经常需要清理我的机器的 /boot 目录,通常由于空间不足而导致更新失败 - 不确定最终的解决方案是什么,但我使用的过程似乎有效:
首先使用 sudo su 命令获取管理员权限,
然后进入 /boot 目录并执行 ls -lSrh 命令 - 底部的文件是最大的 - 删除足够多的旧文件以释放足够的空间。
然后尝试以下步骤(从上面摘录出来):
1. sudo apt-get remove linux-server 2. dpkg --configure -a 3. apt-get update 4. apt-get install -f 5. apt-get autoremove 6. dpkg --get-selections|grep 'linux-image*'|awk '{print $1}'|egrep -v "linux-image-$(uname -r)|linux-image-generic" |while read n;done 7. apt-get install linux-image-server linux-server 8. 重新启动计算机。
如果有任何问题,请在这里留下评论,我会看看可能出了什么问题。
我曾经见过在使用pitti PPA时,对于postgresql-9.1软件包的问题可以解决。
有一次运行该过程时,我遇到了grub的问题。执行apt-get install --reinstall grub命令解决了它。
感谢http://ubuntuforums.org/showpost.php?p=12180959&postcount=7提供的一行代码。
祝好运!

第六步似乎被截断了:dpkg --get-selections|grep 'linux-image*'|awk '{print $1}'|egrep -v "linux-image-$(uname -r)|linux-image-generic" |while read n;do apt-get -y remove $n;done - Tom Swifty

当我使用dpkg时,我遇到了类似的问题。
dpkg: dependency problems prevent configuration of rpi-imager:
 rpi-imager depends on qml-module-qtquick2; however:
 Package qml-module-qtquick2 is not installed.

解决方法是运行sudo apt --fix-broken install命令。

gzip: stdout: 设备上没有剩余空间
看起来你的空间已经用完了。清理一些空间并通过以下方式修复软件包问题:
sudo apt-get purge
sudo apt-get clean
sudo apt-get check
sudo apt-get install -f
sudo dpkg --configure -a 

然后再次安装软件包。
来源:Thread: Dpkg: 依赖问题 - 未配置

TL;DR 使用 dpkg --ignore-depends=...
我尝试安装Pulse-Secure VPN客户端。
dpkg: regarding .../ps-pulse-ubuntu-debian.deb containing pulsesecure, pre-dependency problem:
 pulsesecure pre-depends on libcurl4
  libcurl4 is not installed.

dpkg: warning: ignoring pre-dependency problem!
(Reading database ... 208790 files and directories currently installed.)
Preparing to unpack .../ps-pulse-ubuntu-debian.deb ...

使用标志--ignore-depends=...解决了。
sudo dpkg --ignore-depends=libcurl4 -i /valo/pulse-secure-ubuntu-debian.deb