Ubuntu – How to determine why apt-get will install a package

dependencies

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.

Best Answer

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.

Related Question