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中也會有呈現, 這個時候又分幾種情況.

第一種是無法安裝依賴問題

例如下面這個示例:

$ 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, 0 newly installed, 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, 0 newly installed, 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 newly installed, 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去編譯,並安裝解決問題.

發佈了133 篇原創文章 · 獲贊 78 · 訪問量 63萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章