Ubuntu下面包依赖损坏的解决unmet dependencies

前端之家收集整理的这篇文章主要介绍了Ubuntu下面包依赖损坏的解决unmet dependencies前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

2017-1-4 更新

在原来的文章中提到过使用gzip压缩changelog得到changelog.debian.gz,然后覆盖掉原来的,从而达到欺骗系统认为的软件包的版本问题,但是这样的话需要自己手动定位找到并且压缩,像pulseaudio这样的软件有很多个changelog,还需要一个个找,找个一个最简单的方法:
1. 使用apt-get download下载对应版本的deb包
2. 使用gdebi-gtk图形化或者ark解压,直接提取里面的gz文件覆盖即可.

--------------------------------------------------------
以下为原内容
--------------------------------------------------------

出现dependencies的原因

在新版的Ubuntu下,例如Ubuntu 14.04或者16.04一般是不会出现broken dependencies,或者出现unmet dependencies,但是如果我们使用dpkg强制安装了某些deb包,或者在build-dep的是否手动更改了某些Packages的文件和版本时,那么在再次使用apt-get install或者build-dep来安装library和packages的时就很可能出现问题.


问题的定位

出现了dependencies的问题,那么一般会有提示,而且在log中也会有呈现,这个时候又分几种情况.

第一种是无法安装依赖问题

例如下面这个示例:

  1. $ sudo apt-get build-dep pulseaudio
  2. Reading package lists... Done
  3. Building dependency tree
  4. Reading state information... Done
  5. The following packages have unmet dependencies:
  6. libjack-dev : Depends: libjack0 (= 1:0.121.3+20120418git75e3e20b-2.1ubuntu1) but it is not going to be installed
  7. E: Build-dependencies for pulseaudio could not be satisfied.

这里面便是相互依赖无法满足的问题.

第二种是break dependencies的问题

例如对于前面的libjack问题,我们手动来安装一下它看看究竟是什么导致的无法满足:

  1. $ sudo apt-get install libjack0
  2. Reading package lists... Done
  3. Building dependency tree
  4. Reading state information... Done
  5. You might want to run 'apt-get -f install' to correct these:
  6. The following packages have unmet dependencies:
  7. libbluetooth-dev : Depends: libbluetooth3 (= 4.101-0ubuntu13.1) but 4.101.1-0indt2 is to be installed
  8. libjack-jackd2-0 : Conflicts: libjack-0.116
  9. Conflicts: libjack0 but 1:0.121.3+20120418git75e3e20b-2.1ubuntu1 is to be installed
  10. libjack-jackd2-0:i386 : Conflicts: libjack-0.116
  11. Conflicts: libjack0 but 1:0.121.3+20120418git75e3e20b-2.1ubuntu1 is to be installed
  12. libjack0 : Conflicts: libjack-0.116
  13. Conflicts: libjack-0.116:i386
  14. libpulse-dev : Depends: libpulse0 (= 1:4.0-0ubuntu11.1) but 1:4.0-0ubuntu11indt2 is to be installed
  15. libpulse0 : Breaks: libpulse0:i386 (!= 1:4.0-0ubuntu11indt2) but 1:4.0-0ubuntu11.1 is to be installed
  16. libpulse0:i386 : Breaks: libpulse0 (!= 1:4.0-0ubuntu11.1) but 1:4.0-0ubuntu11indt2 is to be installed
  17. pulseaudio : Depends: libpulse0 (= 1:4.0-0ubuntu11.1) but 1:4.0-0ubuntu11indt2 is to be installed
  18. E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

可以看到这个是版本的问题,因为版本的冲突,导致无法安装. 而且Ubuntu提示让我们使用apt-get -f install 去修复.


如何解决

自动修复

前面已经有提示让我们用apt-get -f install来修复,那么这个命令可以修复哪些情况的dependencies问题呢? 一般是没有更改packages的版本,但是依赖不正确,例如A依赖B,但是B没有安装,此时强制安装A,那么是可以修复的. 还有一种情况,例如安装B的过程中断电或者被Ctrl+C终止,那么也是可以通过这个命令来修复的.

手动修复

但是前面示例的这种版本的问题是无法通过这个命令来修复的. 例如:

  1. $ sudo apt-get -f install
  2. Reading package lists... Done
  3. Building dependency tree
  4. Reading state information... Done
  5. Correcting dependencies... Done
  6. The following packages were automatically installed and are no longer required:
  7. libkutils4 libswresample0 linux-image-4.4.0-45-generic
  8. linux-image-extra-4.4.0-45-generic
  9. Use 'apt-get autoremove' to remove them.
  10. The following extra packages will be installed:
  11. libpulse0
  12. The following packages will be REMOVED:
  13. libbluetooth-dev
  14. The following packages will be upgraded:
  15. libpulse0
  16. 1 upgraded,0 newly installed,1 to remove and 8 not upgraded.
  17. 4 not fully installed or removed.
  18. Need to get 0 B/225 kB of archives.
  19. After this operation,409 kB disk space will be freed.
  20. Do you want to continue? [Y/n]
  21. (Reading database ... 737309 files and directories currently installed.)
  22. Preparing to unpack .../libpulse0_1%3a4.0-0ubuntu11.1_amd64.deb ...
  23. Unpacking libpulse0:amd64 (1:4.0-0ubuntu11.1) over (1:4.0-0ubuntu11indt2) ...
  24. dpkg: error processing archive /var/cache/apt/archives/libpulse0_1%3a4.0-0ubuntu11.1_amd64.deb (--unpack):
  25. trying to overwrite shared '/usr/share/doc/libpulse0/changelog.Debian.gz',which is different from other instances of package libpulse0:amd64
  26. Errors were encountered while processing:
  27. /var/cache/apt/archives/libpulse0_1%3a4.0-0ubuntu11.1_amd64.deb
  28. E: Sub-process /usr/bin/dpkg returned an error code (1)

可以看到根据提示是我们的changelog不同,所以无法覆盖,因此我们需要手动来解决. 根据提示,我们来看看两者的版本,究竟有什么不同:

  1. $ zcat /usr/share/doc/libpulse0/changelog.Debian.gz | head
  2. pulseaudio (1:4.0-0ubuntu11indt2) unstable; urgency=medium

然后看看想要安装的,或者说Ubuntu默认的是什么版本

第一步需要先下载package的source code,因为这里面含有changelog:

  1. $ apt-get source libpulse0
  2. Reading package lists... Done
  3. Building dependency tree
  4. Reading state information... Done
  5. Picking 'pulseaudio' as source package instead of 'libpulse0'
  6. NOTICE: 'pulseaudio' packaging is maintained in the 'Bzr' version control system at:
  7. http://bazaar.launchpad.net/~ubuntu-audio-dev/pulseaudio/ubuntu
  8. Please use:
  9. bzr branch http://bazaar.launchpad.net/~ubuntu-audio-dev/pulseaudio/ubuntu
  10. to retrieve the latest (possibly unreleased) updates to the package.
  11. Need to get 1,470 kB of source archives.
  12. Get:1 http://mirrors.aliyun.com/ubuntu/ trusty-updates/main pulseaudio 1:4.0-0ubuntu11.1 (dsc) [4,851 B]
  13. Get:2 http://mirrors.aliyun.com/ubuntu/ trusty-updates/main pulseaudio 1:4.0-0ubuntu11.1 (tar) [1,392 kB]
  14. Get:3 http://mirrors.aliyun.com/ubuntu/ trusty-updates/main pulseaudio 1:4.0-0ubuntu11.1 (diff) [72.6 kB]
  15. Fetched 1,470 kB in 6s (232 kB/s)
  16. gpgv: Signature made Thu 29 Jan 2015 02:29:24 AM CST using RSA key ID B16223A3
  17. gpgv: Can't check signature: public key not found
  18. dpkg-source: warning: Failed to verify signature on ./pulseaudio_4.0-0ubuntu11.1.dsc
  19. dpkg-source: info: extracting pulseaudio in pulseaudio-4.0
  20. dpkg-source: info: unpacking pulseaudio_4.0.orig.tar.xz
  21. dpkg-source: info: unpacking pulseaudio_4.0-0ubuntu11.1.debian.tar.xz
  22. dpkg-source: info: applying 0003-esd-honour-system-pulseaudio.patch
  23. dpkg-source: info: applying 0005-dont-load-cork-music-on-phone.patch
  24. dpkg-source: info: applying 0006-load-module-x11-bell.patch
  25. dpkg-source: info: applying 0016-nodisplay-autostart.patch
  26. dpkg-source: info: applying 0020-stream-Return-error-in-case-a-client-peeks-to-early.patch
  27. dpkg-source: info: applying 0022-inotify-wrapper-Quit-daemon-if-pid-file-is-removed.patch
  28. dpkg-source: info: applying 0023-fixing_snd_mixer_poll_descriptors_count_when_zero.patch
  29. dpkg-source: info: applying 0101-alsa-ucm-Make-combination-ports-have-lower-priority.patch
  30. dpkg-source: info: applying 0102-combine-Fix-crash-in-output-freeing.patch
  31. dpkg-source: info: applying 0103-resampler-Fix-peaks-resampler-s-channel-handling.patch
  32. dpkg-source: info: applying 0104-default-system.pa-Do-not-load-module-dbus-protocol.patch
  33. dpkg-source: info: applying 0105-sink-source-Initialize-port-before-fixate-hook-fixes.patch
  34. dpkg-source: info: applying 0106-module-switch-on-port-available-Don-t-switch-profile.patch
  35. dpkg-source: info: applying 0107-sink-source-Fix-restore-of-volume-on-devices-without.patch
  36. dpkg-source: info: applying 0201-ALSA-Add-extcon-Android-switch-jack-detection.patch
  37. dpkg-source: info: applying 0202-dont-probe-ucm.patch
  38. dpkg-source: info: applying 0203-card-Add-hook-before-profile-changes.patch
  39. dpkg-source: info: applying 0204-Add-module-to-talk-to-the-Android-audio-hal-to-set-u.patch
  40. dpkg-source: info: applying 0205-suspend-on-idle-ensure-we-still-time-out-if-a-stream-remains-corked.patch

然后查看对比:

  1. $ head debian/changelog
  2. pulseaudio (1:4.0-0ubuntu11.1) trusty; urgency=medium

可见两者的版本确实不一样,因此我们要解决这个问题,那么将现在安装了的改成original的即可.

  1. $ gzip debian/changelog
  2. $ file debian/changelog.gz
  3. debian/changelog.gz: gzip compressed data,was "changelog",from Unix,last modified: Thu Jan 29 02:29:16 2015

然后在覆盖一下:

  1. sudo cp debian/changelog.gz /usr/share/doc/libpulse0/changelog.Debian.gz

再次使用 -f install来修复:

  1. Unpacking libpulse0:amd64 (1:4.0-0ubuntu11.1) over (1:4.0-0ubuntu11indt2) ...
  2. dpkg: error processing archive /var/cache/apt/archives/libpulse0_1%3a4.0-0ubuntu11.1_amd64.deb (--unpack):
  3. trying to overwrite shared '/usr/share/doc/libpulse0/changelog.Debian.gz',which is different from other instances of package libpulse0:amd64
  4. Errors were encountered while processing:
  5. /var/cache/apt/archives/libpulse0_1%3a4.0-0ubuntu11.1_amd64.deb
  6. E: Sub-process /usr/bin/dpkg returned an error code (1)

为此可以知道,这个版本信息不仅仅存在于那个changelog文件中,在packages database中也存在,因此我们只能手动强制安装并覆盖这个libpulse包到Ubuntu原来的版本了

获取

  1. apt-get download libpulse0
  2. Get:1 http://mirrors.aliyun.com/ubuntu/ trusty-updates/main libpulse0 amd64 1:4.0-0ubuntu11.1 [225 kB]
  3. Fetched 225 kB in 2s (87.6 kB/s)
然后强制安装

  1. sudo dpkg -i libpulse*.deb

最后再自动修复

  1. $ sudo apt-get -f install
  2. Reading package lists... Done
  3. Building dependency tree
  4. Reading state information... Done
  5. Correcting dependencies... Done
  6. The following packages were automatically installed and are no longer required:
  7. libkutils4 libswresample0 linux-image-4.4.0-45-generic
  8. linux-image-extra-4.4.0-45-generic
  9. Use 'apt-get autoremove' to remove them.
  10. The following packages will be REMOVED:
  11. libbluetooth-dev
  12. 0 upgraded,1 to remove and 8 not upgraded.
  13. 3 not fully installed or removed.
  14. After this operation,409 kB disk space will be freed.
  15. Do you want to continue? [Y/n]
  16. (Reading database ... 737308 files and directories currently installed.)
  17. Removing libbluetooth-dev (4.101-0ubuntu13.1) ...
  18. Setting up libpulse0:i386 (1:4.0-0ubuntu11.1) ...
  19. Setting up pulseaudio (1:4.0-0ubuntu11.1) ...
  20. Setting up pulseaudio-module-nvs (1:4.0-0ubuntu11indt2) ...
  21. Processing triggers for libc-bin (2.19-0ubuntu6.9) ...

这个时候我们就可以安装依赖了.

  1. $ sudo apt-get build-dep pulseaudio
  2. Reading package lists... Done
  3. Building dependency tree
  4. Reading state information... Done
  5. The following packages have unmet dependencies:
  6. libbluetooth-dev : Depends: libbluetooth3 (= 4.101-0ubuntu13.1) but 4.101.1-0indt2 is to be installed
  7. libjack-dev : Depends: libjack0 (= 1:0.121.3+20120418git75e3e20b-2.1ubuntu1) but it is not going to be installed
  8. E: Build-dependencies for pulseaudio could not be satisfied.


因此我们还是得解决这个问题:

  1. $ sudo dpkg -i libbluetooth-dev_4.101-0ubuntu13.1_amd64.deb
  2. Selecting prevIoUsly unselected package libbluetooth-dev.
  3. (Reading database ... 737260 files and directories currently installed.)
  4. Preparing to unpack libbluetooth-dev_4.101-0ubuntu13.1_amd64.deb ...
  5. Unpacking libbluetooth-dev (4.101-0ubuntu13.1) ...
  6. dpkg: dependency problems prevent configuration of libbluetooth-dev:
  7. libbluetooth-dev depends on libbluetooth3 (= 4.101-0ubuntu13.1); however:
  8. Version of libbluetooth3:amd64 on system is 4.101.1-0indt2.
  9.  
  10. dpkg: error processing package libbluetooth-dev (--install):
  11. dependency problems - leaving unconfigured
  12. Errors were encountered while processing:
  13. libbluetooth-dev

那好我们重复前面的方法,手动来安装正确的libbluetooth-dev,再次之前可以先卸装掉版本不对的:

  1. $ sudo apt-get build-dep bluez
  2. Reading package lists... Done
  3. Building dependency tree
  4. Reading state information... Done
  5. The following packages will be REMOVED:
  6. libbluetooth-dev
  7. 0 upgraded,1 to remove and 8 not upgraded.
  8. 1 not fully installed or removed.
  9. After this operation,409 kB disk space will be freed.
  10. Do you want to continue? [Y/n]
  11. (Reading database ... 737284 files and directories currently installed.)
  12. Removing libbluetooth-dev (4.101-0ubuntu13.1) ...

然后再次查看一下:

  1. $ sudo apt-get build-dep pulseaudio
  2. Reading package lists... Done
  3. Building dependency tree
  4. Reading state information... Done
  5. The following packages have unmet dependencies:
  6. libbluetooth-dev : Depends: libbluetooth3 (= 4.101-0ubuntu13.1) but 4.101.1-0indt2 is to be installed
  7. E: Build-dependencies for pulseaudio could not be satisfied.

这个变成了libbluetooth3,因此我们还需要卸装这个,安装会原来的下面这个版本: @H_301_225@4.101-0ubuntu13.1直接remove:

  1. $ sudo apt-get remove libbluetooth-dev
  2. Reading package lists... Done
  3. Building dependency tree
  4. Reading state information... Done
  5. Package 'libbluetooth-dev' is not installed,so not removed
  6. The following packages were automatically installed and are no longer required:
  7. libkutils4 libsamplerate0:i386 libspeexdsp1:i386 libswresample0
  8. linux-image-4.4.0-45-generic linux-image-extra-4.4.0-45-generic
  9. Use 'apt-get autoremove' to remove them.
  10. 0 upgraded,0 to remove and 8 not upgraded.
再次安装pulseaudio的依赖即可成功了:

  1. $ sudo apt-get build-dep pulseaudio
  2. Reading package lists... Done
  3. Building dependency tree
  4. Reading state information... Done
  5. The following NEW packages will be installed:
  6. libasyncns-dev libatomic-ops-dev libbluetooth-dev libfftw3-bin libfftw3-dev
  7. libfftw3-long3 libfftw3-quad3 libgconf2-dev libjack-dev liblircclient-dev
  8. liborc-0.4-dev libsbc-dev libspeex-dev libspeexdsp-dev libsystemd-daemon-dev
  9. libsystemd-login-dev libtdb-dev libwrap0-dev libxtst-dev x11proto-record-dev
  10. 0 upgraded,20 newly installed,0 to remove and 8 not upgraded.
  11. Need to get 4,055 kB of archives.
  12. After this operation,26.6 MB of additional disk space will be used.
  13. Do you want to continue? [Y/n]

总结

当我们遇到依赖问题的时候,最好先尝试自动解决,然后根据提示,一层层的找到相关的依赖是哪个出现了问题,然后再根据下面顺序手动的解决问题:

1. 卸装最末尾被依赖的(apt-get remove)

2. 安装原版的Ubuntu自带的版本Package (apt-get source ...,dpkg -i XXX)

3. 重复执行上面的1与2步骤

4. 如果无法获取,或者只需要更改某部分,那么自己使用build-dep与dpkg-buildpackage -uc -us -rfakeroot -b去编译,并安装解决问题.

猜你在找的Ubuntu相关文章