这个问题类似于我如何才能知道安装某个包的原因?,但就我而言我想知道前实际安装一个包时,为什么它会安装特定的依赖项。
例如我可能会运行
sudo apt-get install superfoo
输出内容如下:
The following extra packages will be installed:
foo bar baz ... libderp libjunk
这可能是一个很长的列表。在某些情况下,我会看到一些要安装的东西,但对于我所安装的东西来说,它们对我来说真的没有意义,所以我想知道为什么该特定依赖项将被安装。
在上面的例子中,假设我想了解为什么要安装。我知道和libderp
之间存在依赖关系链,但要安装的软件包列表很长,很难看出这个依赖链是什么。superfoo
libderp
一旦我知道了依赖链,我就可以决定是否真的要安装原始软件包,以及/或者我是否应该与该软件包的维护者联系,看看他们是否真的需要有那些依赖项。
答案1
apt-rdepends
做这个,没有安装 50 多个类似的垃圾库ubuntu-dev-tools
。
durr@scraper:~$ apt-rdepends mercurial
Reading package lists... Done
Building dependency tree
Reading state information... Done
mercurial
Depends: libc6 (>= 2.14)
Depends: mercurial-common (= 2.8.2-1ubuntu1)
Depends: python (<< 2.8)
Depends: ucf (>= 2.0020)
libc6
Depends: libgcc1
libgcc1
Depends: gcc-4.9-base (= 4.9-20140406-0ubuntu1)
Depends: libc6 (>= 2.14)
PreDepends: multiarch-support
gcc-4.9-base
multiarch-support
Depends: libc6 (>= 2.3.6-2)
mercurial-common
Depends: python (<< 2.8)
Depends: python:any (>= 2.7.1-0ubuntu2)
python
Depends: libpython-stdlib (= 2.7.5-5ubuntu3)
Depends: python-minimal (= 2.7.5-5ubuntu3)
Depends: python2.7 (>= 2.7.5-1~)
libpython-stdlib
Depends: libpython2.7-stdlib (>= 2.7.5-1~)
libpython2.7-stdlib
Depends: libbz2-1.0
Depends: libc6 (>= 2.15)
Depends: libdb5.3
Depends: libexpat1 (>= 2.1~beta3)
Depends: libffi6 (>= 3.0.4)
Depends: libncursesw5 (>= 5.6+20070908)
Depends: libpython2.7-minimal (= 2.7.6-8)
Depends: libreadline6 (>= 6.0)
Depends: libsqlite3-0 (>= 3.5.9)
Depends: libssl1.0.0 (>= 1.0.0)
Depends: libtinfo5
Depends: mime-support
libbz2-1.0
Depends: libc6 (>= 2.4)
PreDepends: multiarch-support
libdb5.3
Depends: libc6 (>= 2.17)
PreDepends: multiarch-support
libexpat1
Depends: libc6 (>= 2.14)
PreDepends: multiarch-support
libffi6
Depends: libc6 (>= 2.14)
PreDepends: multiarch-support
libncursesw5
Depends: libc6 (>= 2.15)
Depends: libtinfo5 (= 5.9+20140118-1ubuntu1)
PreDepends: multiarch-support
libtinfo5
Depends: libc6 (>= 2.15)
PreDepends: multiarch-support
libpython2.7-minimal
libreadline6
Depends: libc6 (>= 2.15)
Depends: libtinfo5
Depends: readline-common
PreDepends: multiarch-support
readline-common
Depends: dpkg (>= 1.15.4)
Depends: install-info
dpkg
PreDepends: libbz2-1.0
PreDepends: libc6 (>= 2.14)
PreDepends: liblzma5 (>= 5.1.1alpha+20120614)
PreDepends: libselinux1 (>= 2.1.0)
PreDepends: tar (>= 1.23)
PreDepends: zlib1g (>= 1:1.1.4)
liblzma5
Depends: libc6 (>= 2.14)
PreDepends: multiarch-support
libselinux1
Depends: libc6 (>= 2.14)
Depends: libpcre3
PreDepends: multiarch-support
libpcre3
Depends: libc6 (>= 2.14)
PreDepends: multiarch-support
tar
PreDepends: libacl1 (>= 2.2.51-8)
PreDepends: libc6 (>= 2.17)
PreDepends: libselinux1 (>= 1.32)
libacl1
Depends: libattr1 (>= 1:2.4.46-8)
Depends: libc6 (>= 2.14)
PreDepends: multiarch-support
libattr1
Depends: libc6 (>= 2.4)
PreDepends: multiarch-support
zlib1g
Depends: libc6 (>= 2.14)
PreDepends: multiarch-support
install-info
Depends: libc6 (>= 2.14)
PreDepends: dpkg (>= 1.16.1)
libsqlite3-0
Depends: libc6 (>= 2.14)
PreDepends: multiarch-support
libssl1.0.0
Depends: debconf (>= 0.5)
Depends: debconf-2.0
Depends: libc6 (>= 2.14)
PreDepends: multiarch-support
debconf
PreDepends: perl-base (>= 5.6.1-4)
perl-base
PreDepends: dpkg (>= 1.14.20)
PreDepends: libc6 (>= 2.14)
debconf-2.0
mime-support
python-minimal
Depends: dpkg (>= 1.13.20)
Depends: python2.7-minimal (>= 2.7.5-1~)
python2.7-minimal
Depends: libpython2.7-minimal (= 2.7.6-8)
Depends: zlib1g (>= 1:1.2.0)
PreDepends: libc6 (>= 2.15)
python2.7
Depends: libpython2.7-stdlib (= 2.7.6-8)
Depends: mime-support
Depends: python2.7-minimal (= 2.7.6-8)
python:any
ucf
Depends: coreutils (>= 5.91)
Depends: debconf (>= 1.5.19)
coreutils
PreDepends: libacl1 (>= 2.2.51-8)
PreDepends: libattr1 (>= 1:2.4.46-8)
PreDepends: libc6 (>= 2.17)
PreDepends: libselinux1 (>= 1.32)
在我干净的 ubuntu 服务器安装上,apt-rdepends
只需要libapt-pkg-perl
安装。它比 轻得多ubuntu-dev-tools
,但仍然是递归的,所以你会得到全部依赖关系,而不仅仅是一阶依赖关系,例如apt-cache depends
返回。
答案2
你真正想问的是“我如何绘制依赖关系图?”这样你就可以看到哪些包引入了哪些依赖关系。
apt-cache
您可以从命令(包含在 apt 包中,是默认安装的一部分)中获取文本和图表依赖项。
以下是 apt-cache 以文本格式列出 'hello' 软件包依赖项的示例。文本输出始终只有一个级别。
$ apt-cache depends hello
hello
Depends: libc6
|Depends: dpkg
Depends: install-info
您可以使用任何点文件查看器阅读该图表,例如dotty
(包含在 graphviz 包中,也是默认安装的一部分)
以下是以图形格式获取完整依赖关系树并显示它的示例。图形输出将始终是完整树。
$ apt-cache dotty hello > dotfile
$ dotty dotfile
仔细查看,您会发现“hello”包引入了大量的Perl包...以及哪些依赖项可以做到这一点。
答案3
可以使用内置的 APT 调试选项来从解析器了解底层依赖关系树。
从apt.conf(5)
调试::pkgDepCache::自动安装
生成调试消息,描述哪些软件包正在自动安装以解决依赖关系。这对应于在 apt-get install 等中执行的初始自动安装过程,而不是完整的 apt 依赖解析器;有关详细信息,请参阅 Debug::pkgProblemResolver。
$ apt install -s -o Debug::pkgDepCache::AutoInstall=true mercurial
Reading package lists... Done
Building dependency tree
Reading state information... Done
Installing mercurial-common as Depends of mercurial
Installing python2 as Depends of mercurial-common
Installing python2-minimal as PreDepends of python2
Installing python2.7-minimal as Depends of python2-minimal
Installing libpython2.7-minimal as Depends of python2.7-minimal
Installing python2.7 as Depends of python2
Installing libpython2.7-stdlib as Depends of python2.7
Installing libpython2-stdlib as Depends of python2
The following additional packages will be installed:
libpython2-stdlib libpython2.7-minimal libpython2.7-stdlib mercurial-common python2 python2-minimal python2.7 python2.7-minimal
答案4
可能有更简单的方法可以做到这一点,但如果你使用反向依赖项,也可以做到这一点。你需要通过执行以下操作来安装 ubuntu-dev-tools 包
apt-get install ubuntu-dev-tools
或者点击此按钮:
安装后,您可以使用 reverse-depends 查看依赖于特定软件包的内容。例如,如果您尝试安装需要安装一堆额外软件包的软件包,并且想要查看为什么要安装“libsmpeg0”,请运行
reverse-depends libsmpeg0
这将输出以下内容。
Reverse-Recommends
==================
* sandboxgamemaker
Reverse-Depends
===============
* btanks
* fenix-plugin-mpeg [armel armhf i386 powerpc]
* fillets-ng
* gltron [amd64 armel i386 powerpc]
* libalien-sdl-perl
* libsdl-perl [i386]
* libsmpeg-dev
* libtaoframework-sdl1.2-cil
* python-pygame
* ruby-sdl
* sdlbrt
* smpeg-gtv
* smpeg-plaympeg
* tdfsb
Packages without architectures listed are reverse-dependencies in: amd64, armel, armhf, i386, powerpc
查看您要安装的软件包是否在该列表中。如果不在,则在初始安装期间引入的另一个软件包将显示在该列表中,您需要对该软件包运行反向依赖。最终,您将在该列表中看到您要安装的初始软件包。此时,您应该有一个链,准确显示安装该软件包的原因。
补充一点,我认为推荐是默认开启的,所以如果某样东西被设置为推荐,它就会被拉进来。如果关闭,则建议,但反向依赖也可以显示该信息。