27

This question is similar to How can I find out why a package was installed?, but in my case I'd like to know before actually installing a package, why it will install a particular dependency.

So for example I might run

sudo apt-get install superfoo

and the output will say something like:

The following extra packages will be installed:
  foo bar baz ... libderp libjunk

And this might be a really huge list. In some instances I'll see something that is going to be installed that doesn't really make sense to me given what I'm installing, so I want to know why that particular dependency is going to be installed.

In the above example let's say I'd like to understand why libderp would get installed. I know that somehow there is a chain of dependencies between superfoo and libderp but the huge list of packages to be installed makes it hard to see what this chain is.

Once I know the dependency chain, I can decide whether I really want to install the original package or not, and/or whether I should get in touch with the maintainer of that package to see if they really need to have those dependencies there.

1
  • If someone's answer was helpful to you, then please consider marking it as the accepted answer so others may more easily find it in the future. This is also a polite way to thank the person answering your question for helping you out. – Danatela Apr 15 '14 at 7:56
18

What you really seem to be asking is "How do I diagram dependencies?" so you can see which packages pull in which dependencies.

You get both text and diagrammed dependencies from the apt-cache command (included in the apt package, part of the default install).

Here's an example of apt-cache for listing dependencies of the 'hello' package in text format. Text output will always be only one level.

$ apt-cache depends hello
hello
  Depends: libc6
 |Depends: dpkg
  Depends: install-info

You can read the diagram using any dotfile viewer, such as dotty (included in the graphviz package, also part of the default install)

Here's an example of getting the full dependency tree in graphical format, then displaying it. Graphical output will always be the full tree.

$ apt-cache dotty hello > dotfile
$ dotty dotfile

Looking it over, you can see that the 'hello' package pulls in a ton of Perl packages...and which dependency does it.

9
  • While that would work, it would be some serious work to do it this way to see what was pulling in a certain package if the package was a dependency of a dependency. – tgm4883 May 6 '12 at 23:51
  • Not at all. Merely look at the dotfile picture. – user535733 Jan 20 '13 at 3:57
  • 3
    apt-cache depends --recurse will give you the full picture, but apt-rdepends below is better because it only follows actual dependencies, not recommended or suggested ones. – mhsmith Feb 23 '15 at 21:33
  • Although apt-get actually will install recommended dependencies unless you use the --no-install-recommends flag. – mhsmith Feb 23 '15 at 21:49
  • 3
    What does that bar mean? | – CMCDragonkai Sep 21 '15 at 4:52
14

apt-rdepends does this, without installing 50+ libraries of cruft like 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)

On my clean ubuntu server install, apt-rdepends only required libapt-pkg-perl for installation. It's much lighter then ubuntu-dev-tools, and yet is still recursive, so you get all the dependencies, rather then just the first-order dependencies, like apt-cache depends returns.

2
  • Sorry if I misunderstood, but I think apt-rdepends is not the same as reverse-depends. apt-rdepends lists the recursive dependencies of a package, while reverse-depends lists the packages that depend on the package given. – rsuarez Apr 7 '16 at 10:20
  • 1
    apt-rdepends -r lists the reverse dependencies. – Keith Sep 23 '16 at 10:01
8

There may be an easier way to do this, but it can be done if you use reverse-depends. You will need to install the ubuntu-dev-tools package by doing

apt-get install ubuntu-dev-tools

Or by clicking this button:

Install via the software center

Once installed, you can then use reverse-depends to see what depends on a specific package. For example, if you try to install something that wants to install a bunch of extra packages and you want to see why "libsmpeg0" is being installed, you run

reverse-depends libsmpeg0

Which would output the following.

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

Take a look and see if the package you want to install is in that list. If not, then another one of the packages that is being pulled in during that initial install will show up in that list, and you will need to run reverse-depends on that package. Eventually you will see the initial package you want to install in that list. At that point, you should have a chain showing exactly why that package was installed.

As an added note, I believe recommends is on by default, so if something is set as a recommends it will get pulled in to. Suggests if off, but reverse-depends can show that info as well.

2
  • 2
    While I'm sure this answer would work, it personifies the issue the OP is trying to avoid. ubuntu-dev-tools results in the following packages being installed. bzr bzr-builddeb dctrl-tools debian-archive-keyring debian-keyring debootstrap devscripts diffstat distro-info distro-info-data dput genisoimage gettext hardening-includes intltool-debian libapt-pkg-perl libarchive-zip-perl libasprintf-dev libassuan0 libauthen-sasl-perl libautodie-perl libclone-perl libcommon-sense-perl libcroco3 libdigest-hmac-perl libdistro-info-perl libemail-valid-perl libencode-locale-perl liberror-perl – Fake Name Apr 15 '14 at 7:38
  • 2
    [continued] python-launchpadlib python-lazr.restfulclient python-lazr.uri python-oauth python-paramiko python-reportbug python-secretstorage python-simplejson python-soappy python-support python-wadllib python3-debian python3-magic quilt reportbug t1utils unzip wdiff xdelta (Note: The above was just the required packages from sudo apt-get install ubuntu-dev-tools on a fairly clean ubuntu server instance). If you're trying to avoid installing huge amounts of cruft, this is probably the worst solution possible. – Fake Name Apr 15 '14 at 7:41
3

One can use builtin APT debug options to get a sense of the underlying dependency tree from the resolver.

From apt.conf(5)

Debug::pkgDepCache::AutoInstall

Generate debug messages describing which packages are being automatically installed to resolve dependencies. This corresponds to the initial auto-install pass performed in, e.g., apt-get install, and not to the full apt dependency resolver; see Debug::pkgProblemResolver for that.

$ 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
  • This answer is the real one, don't know why did people down-vote it. Note that the quoted output goes to stderr, it's important if you are using grep for example – Chan Tzish Jun 18 '20 at 13:25
  • This is the only one which listed everything. Other tools don't list packages brought in because they are Recommended or installed through virtual packages/Provides. Thanks so much! Now to parse this and turn it into DOT... – remram Feb 12 at 17:00
  • @remram You're welcome. Note if you need dot output you might find debtree helpful – pmartycz Feb 13 at 18:11
  • What if I already installed mercurial? – Gqqnbig Mar 19 at 3:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.