57

I'd like to find out which packages

sudo apt-get build-dep <package>

would install (if I already got some dependencies installed, I'd also like to see those → so running or simulating the above is not enough). Command line preferred.

htorque
  • 64,798
  • 1
    I'm confused, doesn't sudo apt-get build-dep <package> show the list of packages (if the package has any build dependencies) it is going to install? – Isaiah Jan 13 '11 at 17:54
  • 2
    Unfortunately that only shows packages that aren't installed. – htorque Jan 13 '11 at 17:59

3 Answers3

51

For a full list of dependencies, including the dependencies' dependencies, you can use:

apt-rdepends --build-depends openoffice.org

The command may remind you to install apt-rdepends first.

You can use the following command to only show the ones that are not installed:

apt-rdepends --build-depends --print-state openoffice.org | grep NotInstalled

See apt-rdepends --help for all the options.

Note: This will generate a massive list.
apt-rdepends -b xterm, for example, generates 8773 lines of output, and takes it's time doing it.

If you only want to see the packages that are required to build the topmost package, i.e. what do I need to install to build nautilus, run:

apt-rdepends --build-depends --follow=DEPENDS nautilus

This is roughly equivalent to Carsten Thiel's answer (The following NEW packages will be installed), but the output format is a bit nicer. It also only shows the topmost package, whereas simulated apt-get also shows packages installed as dependencies of those.

This also shows packages that are installed. But it may also show packages that are installed by default. Unfortunately, neither method is much help when you're trying to clean up your system after running apt-get build-dep. As far as I know, there isn't a reliable method of finding which ones were installed except from looking at the apt log file at /var/log/apt/history.log.

  • 1
    Thanks, the version with --follow=DEPENDS is exactly what I was looking for. You can also find those build dependencies on Launchpad, eg. for Nautilus: https://launchpad.net/ubuntu/natty/+source/nautilus (scroll down). – htorque Jan 13 '11 at 19:23
  • Yeah, but apt-rdepends -b foo does not seem to "de-duplicate", so several packages will end up multiple times in the list. – Levente Feb 24 '21 at 23:39
  • 1
    While the version with --follow=DEPENDS works for me, DEPENDS seem to exploit a bug in apt-rdepends, namely, that it acceps anything case-sensitivly after --follow, with DEPENDS not being a valid symbol. For instance, --follow=none or --follow=Chuck-Norris do the same thing. – Torsten Bronger Apr 27 '21 at 15:02
24
apt-cache showsrc <pkgname> | grep ^Build-Depends

showsrc displays the debian/control file for a given source package. We then grep for the line(s) which begin with 'Build-Depends' which has the list of packages needed to build from source.

notpeter
  • 1,569
anonymous
  • 241
  • +1 if you explain what apt-cache showsrc and what | grep does. Still, good answer. Thanks for taking the time to provide it. – MadMike Dec 28 '14 at 12:17
  • sudo apt-cache showsrc inkscape doesn't work for inkscape in Ubuntu 18.10 - gives W: Unable to locate package inkscape N: No packages found – anatoly techtonik Nov 25 '18 at 09:27
  • @anatolytechtonik just tested on Ubuntu 18.10 in Docker, works for me. Did you apt-get update first? – Stéphane Gourichon Nov 04 '19 at 15:43
  • 1
    This should be the accepted answer as it provides the needed tool and does not need any extra package. – Stéphane Gourichon Nov 04 '19 at 15:45
  • @StéphaneGourichon Unfortunately it doesn't parse conditional dependencies or version requirements, both of which would affect what is actually installed by the build-dep command. – ATLief Jan 05 '23 at 12:14
16

The option -s (--simulate) will output everything that would be done without doing anything. You don't even need root privileges for that.

apt-get -s build-dep <package>