Ubuntu包依赖损坏的解决unmet dependencies

如何解决apt-get中Unmet dependencies问题

2017年09月30日 21:35:22 Jinguang Liu 阅读数 16686

 版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010096900/article/details/78145423

简介

新安装的Ubuntu 16.04 TLS系统,由于apt-get upgrade过程中断,导致依赖损坏;安装新的包时,提示Unmet dependencies问题。本文记录了问题的排查方法及解决方案

问题描述

系统由于未知原因,在系统重启后,发现安装包时提示了Unmet dependencies提示,无法正常安装。

 

hadoop@hadoop-virtualbox:~$ sudo apt-get install openjdk-8-jdk
Reading package lists... Done
Building dependency tree
Reading state information... Done
openjdk-8-jdk is already the newest version (8u131-b11-2ubuntu1.16.04.3).
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
 linux-image-extra-4.10.0-35-generic : Depends: linux-image-4.10.0-35-generic but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

根据问题提示信息,是由于所依赖的包linux-image-4.10.0-35-generic并没有被正确安装导致。linux-image-x.x.x是内核文件,从提示信息上看,应该是升级过程中断导致的问题。查看内核当前版本信息发现当前运行的版本为4.10.0-28-generic。确实与提示的内核信息不一致,确认了问题所在。

 

 

hadoop@hadoop-virtualbox:~$ uname -r
4.10.0-28-generic

 

解决方案

根据提示信息,运行apt-get -f install来修复问题,详细的-f选项的意义可以查看manual手册。这里列出了选项的具体含义:

-f, --fix-broken
Fix; attempt to correct a system with broken dependencies in place. This option, when used with install/remove, 
can omit any packages to permit APT to deduce a likely solution. If packages are specified, these have to 
completely correct the problem. The option is sometimes necessary when running APT for the first time; 
APT itself does not allow broken package dependencies to exist on a system. It is possible that a system's 
dependency structure can be so corrupt as to require manual intervention (which usually means using dpkg --remove 
to eliminate some of the offending packages). Use of this option together with -m may produce an error in some 
situations. Configuration Item: APT::Get::Fix-Broken.

接下来我们执行修复命令,并重新执行更新和升级,确保完整修复问题。

sudo apt --fix-broken install
sudo apt-get update
sudo apt-get upgrade

 

Ubuntu包依赖损坏的解决unmet dependencies

2017年01月03日 10:30:21 TonyHo 阅读数 32415 标签: Ubuntuapt-get 更多

个人分类: Software

版权声明:转载请注明出处: http://blog.csdn.net/sy373466062 作者: TonyHo https://blog.csdn.net/sy373466062/article/details/53991413

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去编译,并安装解决问题.

 

 

你可能感兴趣的:(Ubuntu包依赖损坏的解决unmet dependencies)