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

  • 9
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当您在Linux系统中安装软件包时,可能会遇到“以下软件包存在未满足的依赖关系”的错误消息。这通常是由于软件包之间的依赖关系无法满足而导致的。以下是一些解决这个问题的常见方法: 1. 更新软件包列表:在终端中运行以下命令: ``` $ sudo apt-get update ``` 这将更新软件包列表,以确保您的系统可以找到最新的软件包。 2. 安装缺失的依赖项:在终端中运行以下命令: ``` $ sudo apt-get install -f ``` 这将自动安装缺失的依赖项。 3. 安装特定版本的软件包:有时,特定版本的软件包可以满足依赖关系。您可以使用以下命令安装特定版本的软件包: ``` $ sudo apt-get install <package-name>=<package-version> ``` 例如,要安装Python的2.7.17版本,您可以使用以下命令: ``` $ sudo apt-get install python2.7=2.7.17-1~18.04ubuntu1 ``` 4. 删除冲突的软件包:有时,其他软件包可能与您要安装的软件包发生冲突。您可以尝试使用以下命令删除冲突的软件包: ``` $ sudo apt-get remove <package-name> ``` 例如,要删除与Python 2.7.17发生冲突的Python 3.6软件包,您可以使用以下命令: ``` $ sudo apt-get remove python3.6 ``` 5. 清理未使用的软件包:在终端中运行以下命令: ``` $ sudo apt-get autoclean $ sudo apt-get autoremove ``` 这将清除系统中未使用的软件包和依赖项。 希望这些方法可以帮助您解决“以下软件包存在未满足的依赖关系”的错误消息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值