2017-1-4 更新
出现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中也会有呈现,这个时候又分几种情况.
第一种是无法安装依赖问题
例如下面这个示例:
$ sudo apt-get build-dep pulseaudio Reading package lists... Done Building dependency tree Reading state information... Done The following packages have unmet dependencies: libjack-dev : Depends: libjack0 (= 1:0.121.3+20120418git75e3e20b-2.1ubuntu1) but it is not going to be installed E: Build-dependencies for pulseaudio could not be satisfied.
这里面便是相互依赖无法满足的问题.
第二种是break dependencies的问题
例如对于前面的libjack问题,我们手动来安装一下它看看究竟是什么导致的无法满足:
$ sudo apt-get install libjack0 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: libbluetooth-dev : Depends: libbluetooth3 (= 4.101-0ubuntu13.1) but 4.101.1-0indt2 is to be installed libjack-jackd2-0 : Conflicts: libjack-0.116 Conflicts: libjack0 but 1:0.121.3+20120418git75e3e20b-2.1ubuntu1 is to be installed libjack-jackd2-0:i386 : Conflicts: libjack-0.116 Conflicts: libjack0 but 1:0.121.3+20120418git75e3e20b-2.1ubuntu1 is to be installed libjack0 : Conflicts: libjack-0.116 Conflicts: libjack-0.116:i386 libpulse-dev : Depends: libpulse0 (= 1:4.0-0ubuntu11.1) but 1:4.0-0ubuntu11indt2 is to be installed libpulse0 : Breaks: libpulse0:i386 (!= 1:4.0-0ubuntu11indt2) but 1:4.0-0ubuntu11.1 is to be installed libpulse0:i386 : Breaks: libpulse0 (!= 1:4.0-0ubuntu11.1) but 1:4.0-0ubuntu11indt2 is to be installed pulseaudio : Depends: libpulse0 (= 1:4.0-0ubuntu11.1) but 1:4.0-0ubuntu11indt2 is to be installed 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终止,那么也是可以通过这个命令来修复的.
手动修复
但是前面示例的这种版本的问题是无法通过这个命令来修复的. 例如:
$ sudo apt-get -f install Reading package lists... Done Building dependency tree Reading state information... Done Correcting dependencies... Done The following packages were automatically installed and are no longer required: libkutils4 libswresample0 linux-image-4.4.0-45-generic linux-image-extra-4.4.0-45-generic Use 'apt-get autoremove' to remove them. The following extra packages will be installed: libpulse0 The following packages will be REMOVED: libbluetooth-dev The following packages will be upgraded: libpulse0 1 upgraded,0 newly installed,1 to remove and 8 not upgraded. 4 not fully installed or removed. Need to get 0 B/225 kB of archives. After this operation,409 kB disk space will be freed. Do you want to continue? [Y/n] (Reading database ... 737309 files and directories currently installed.) Preparing to unpack .../libpulse0_1%3a4.0-0ubuntu11.1_amd64.deb ... Unpacking libpulse0:amd64 (1:4.0-0ubuntu11.1) over (1:4.0-0ubuntu11indt2) ... dpkg: error processing archive /var/cache/apt/archives/libpulse0_1%3a4.0-0ubuntu11.1_amd64.deb (--unpack): trying to overwrite shared '/usr/share/doc/libpulse0/changelog.Debian.gz',which is different from other instances of package libpulse0:amd64 Errors were encountered while processing: /var/cache/apt/archives/libpulse0_1%3a4.0-0ubuntu11.1_amd64.deb E: Sub-process /usr/bin/dpkg returned an error code (1)
可以看到根据提示是我们的changelog不同,所以无法覆盖,因此我们需要手动来解决. 根据提示,我们来看看两者的版本,究竟有什么不同:
$ zcat /usr/share/doc/libpulse0/changelog.Debian.gz | head pulseaudio (1:4.0-0ubuntu11indt2) unstable; urgency=medium
然后看看想要安装的,或者说Ubuntu默认的是什么版本
第一步需要先下载package的source code,因为这里面含有changelog:
$ apt-get source libpulse0 Reading package lists... Done Building dependency tree Reading state information... Done Picking 'pulseaudio' as source package instead of 'libpulse0' NOTICE: 'pulseaudio' packaging is maintained in the 'Bzr' version control system at: http://bazaar.launchpad.net/~ubuntu-audio-dev/pulseaudio/ubuntu Please use: bzr branch http://bazaar.launchpad.net/~ubuntu-audio-dev/pulseaudio/ubuntu to retrieve the latest (possibly unreleased) updates to the package. Need to get 1,470 kB of source archives. Get:1 http://mirrors.aliyun.com/ubuntu/ trusty-updates/main pulseaudio 1:4.0-0ubuntu11.1 (dsc) [4,851 B] Get:2 http://mirrors.aliyun.com/ubuntu/ trusty-updates/main pulseaudio 1:4.0-0ubuntu11.1 (tar) [1,392 kB] Get:3 http://mirrors.aliyun.com/ubuntu/ trusty-updates/main pulseaudio 1:4.0-0ubuntu11.1 (diff) [72.6 kB] Fetched 1,470 kB in 6s (232 kB/s) gpgv: Signature made Thu 29 Jan 2015 02:29:24 AM CST using RSA key ID B16223A3 gpgv: Can't check signature: public key not found dpkg-source: warning: Failed to verify signature on ./pulseaudio_4.0-0ubuntu11.1.dsc dpkg-source: info: extracting pulseaudio in pulseaudio-4.0 dpkg-source: info: unpacking pulseaudio_4.0.orig.tar.xz dpkg-source: info: unpacking pulseaudio_4.0-0ubuntu11.1.debian.tar.xz dpkg-source: info: applying 0003-esd-honour-system-pulseaudio.patch dpkg-source: info: applying 0005-dont-load-cork-music-on-phone.patch dpkg-source: info: applying 0006-load-module-x11-bell.patch dpkg-source: info: applying 0016-nodisplay-autostart.patch dpkg-source: info: applying 0020-stream-Return-error-in-case-a-client-peeks-to-early.patch dpkg-source: info: applying 0022-inotify-wrapper-Quit-daemon-if-pid-file-is-removed.patch dpkg-source: info: applying 0023-fixing_snd_mixer_poll_descriptors_count_when_zero.patch dpkg-source: info: applying 0101-alsa-ucm-Make-combination-ports-have-lower-priority.patch dpkg-source: info: applying 0102-combine-Fix-crash-in-output-freeing.patch dpkg-source: info: applying 0103-resampler-Fix-peaks-resampler-s-channel-handling.patch dpkg-source: info: applying 0104-default-system.pa-Do-not-load-module-dbus-protocol.patch dpkg-source: info: applying 0105-sink-source-Initialize-port-before-fixate-hook-fixes.patch dpkg-source: info: applying 0106-module-switch-on-port-available-Don-t-switch-profile.patch dpkg-source: info: applying 0107-sink-source-Fix-restore-of-volume-on-devices-without.patch dpkg-source: info: applying 0201-ALSA-Add-extcon-Android-switch-jack-detection.patch dpkg-source: info: applying 0202-dont-probe-ucm.patch dpkg-source: info: applying 0203-card-Add-hook-before-profile-changes.patch dpkg-source: info: applying 0204-Add-module-to-talk-to-the-Android-audio-hal-to-set-u.patch dpkg-source: info: applying 0205-suspend-on-idle-ensure-we-still-time-out-if-a-stream-remains-corked.patch
然后查看对比:
$ head debian/changelog pulseaudio (1:4.0-0ubuntu11.1) trusty; urgency=medium
可见两者的版本确实不一样,因此我们要解决这个问题,那么将现在安装了的改成original的即可.
$ gzip debian/changelog $ file debian/changelog.gz debian/changelog.gz: gzip compressed data,was "changelog",from Unix,last modified: Thu Jan 29 02:29:16 2015
然后在覆盖一下:
sudo cp debian/changelog.gz /usr/share/doc/libpulse0/changelog.Debian.gz
再次使用 -f install来修复:
Unpacking libpulse0:amd64 (1:4.0-0ubuntu11.1) over (1:4.0-0ubuntu11indt2) ... dpkg: error processing archive /var/cache/apt/archives/libpulse0_1%3a4.0-0ubuntu11.1_amd64.deb (--unpack): trying to overwrite shared '/usr/share/doc/libpulse0/changelog.Debian.gz',which is different from other instances of package libpulse0:amd64 Errors were encountered while processing: /var/cache/apt/archives/libpulse0_1%3a4.0-0ubuntu11.1_amd64.deb E: Sub-process /usr/bin/dpkg returned an error code (1)
为此可以知道,这个版本信息不仅仅存在于那个changelog文件中,在packages database中也存在,因此我们只能手动强制安装并覆盖这个libpulse包到Ubuntu原来的版本了
先获取
apt-get download libpulse0 Get:1 http://mirrors.aliyun.com/ubuntu/ trusty-updates/main libpulse0 amd64 1:4.0-0ubuntu11.1 [225 kB] Fetched 225 kB in 2s (87.6 kB/s)然后强制安装
sudo dpkg -i libpulse*.deb
最后再自动修复
$ sudo apt-get -f install Reading package lists... Done Building dependency tree Reading state information... Done Correcting dependencies... Done The following packages were automatically installed and are no longer required: libkutils4 libswresample0 linux-image-4.4.0-45-generic linux-image-extra-4.4.0-45-generic Use 'apt-get autoremove' to remove them. The following packages will be REMOVED: libbluetooth-dev 0 upgraded,1 to remove and 8 not upgraded. 3 not fully installed or removed. After this operation,409 kB disk space will be freed. Do you want to continue? [Y/n] (Reading database ... 737308 files and directories currently installed.) Removing libbluetooth-dev (4.101-0ubuntu13.1) ... Setting up libpulse0:i386 (1:4.0-0ubuntu11.1) ... Setting up pulseaudio (1:4.0-0ubuntu11.1) ... Setting up pulseaudio-module-nvs (1:4.0-0ubuntu11indt2) ... Processing triggers for libc-bin (2.19-0ubuntu6.9) ...
这个时候我们就可以安装依赖了.
$ sudo apt-get build-dep pulseaudio Reading package lists... Done Building dependency tree Reading state information... Done The following packages have unmet dependencies: libbluetooth-dev : Depends: libbluetooth3 (= 4.101-0ubuntu13.1) but 4.101.1-0indt2 is to be installed libjack-dev : Depends: libjack0 (= 1:0.121.3+20120418git75e3e20b-2.1ubuntu1) but it is not going to be installed E: Build-dependencies for pulseaudio could not be satisfied.
因此我们还是得解决这个问题:
$ sudo dpkg -i libbluetooth-dev_4.101-0ubuntu13.1_amd64.deb Selecting prevIoUsly unselected package libbluetooth-dev. (Reading database ... 737260 files and directories currently installed.) Preparing to unpack libbluetooth-dev_4.101-0ubuntu13.1_amd64.deb ... Unpacking libbluetooth-dev (4.101-0ubuntu13.1) ... dpkg: dependency problems prevent configuration of libbluetooth-dev: libbluetooth-dev depends on libbluetooth3 (= 4.101-0ubuntu13.1); however: Version of libbluetooth3:amd64 on system is 4.101.1-0indt2. dpkg: error processing package libbluetooth-dev (--install): dependency problems - leaving unconfigured Errors were encountered while processing: libbluetooth-dev
那好我们重复前面的方法,手动来安装正确的libbluetooth-dev,再次之前可以先卸装掉版本不对的:
$ sudo apt-get build-dep bluez Reading package lists... Done Building dependency tree Reading state information... Done The following packages will be REMOVED: libbluetooth-dev 0 upgraded,1 to remove and 8 not upgraded. 1 not fully installed or removed. After this operation,409 kB disk space will be freed. Do you want to continue? [Y/n] (Reading database ... 737284 files and directories currently installed.) Removing libbluetooth-dev (4.101-0ubuntu13.1) ...
然后再次查看一下:
$ sudo apt-get build-dep pulseaudio Reading package lists... Done Building dependency tree Reading state information... Done The following packages have unmet dependencies: libbluetooth-dev : Depends: libbluetooth3 (= 4.101-0ubuntu13.1) but 4.101.1-0indt2 is to be installed E: Build-dependencies for pulseaudio could not be satisfied.
这个变成了libbluetooth3,因此我们还需要卸装这个,安装会原来的下面这个版本:
4.101-0ubuntu13.1直接remove:
$ sudo apt-get remove libbluetooth-dev Reading package lists... Done Building dependency tree Reading state information... Done Package 'libbluetooth-dev' is not installed,so not removed The following packages were automatically installed and are no longer required: libkutils4 libsamplerate0:i386 libspeexdsp1:i386 libswresample0 linux-image-4.4.0-45-generic linux-image-extra-4.4.0-45-generic Use 'apt-get autoremove' to remove them. 0 upgraded,0 to remove and 8 not upgraded.再次安装pulseaudio的依赖即可成功了:
$ sudo apt-get build-dep pulseaudio Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: libasyncns-dev libatomic-ops-dev libbluetooth-dev libfftw3-bin libfftw3-dev libfftw3-long3 libfftw3-quad3 libgconf2-dev libjack-dev liblircclient-dev liborc-0.4-dev libsbc-dev libspeex-dev libspeexdsp-dev libsystemd-daemon-dev libsystemd-login-dev libtdb-dev libwrap0-dev libxtst-dev x11proto-record-dev 0 upgraded,20 newly installed,0 to remove and 8 not upgraded. Need to get 4,055 kB of archives. After this operation,26.6 MB of additional disk space will be used. 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去编译,并安装解决问题.