18

Is there a better way to install only the required dependencies of a package, instead of installing it directly with apt-get (or any other frontend of dpkg) and then immediately removing it, leaving out its dependencies?

Vadim Kotov
  • 111
  • 4
Vinícius Ferrão
  • 5,400
  • 10
  • 52
  • 91

4 Answers4

23

apt-cache depends pkgname will show a package's dependencies.

If you want it all in one command, you could do worse than:

apt-get install `apt-cache depends pkgname | awk '/Depends:/{print$2}'`
smammy
  • 427
  • 3
  • 7
15

apt-get provides a command for exactly that...

apt-get build-dep <package name>

From the man pages you get

build-dep causes apt-get to install/remove packages in an attempt to satisfy the build dependencies for a source package. By default the dependencies are satisfied to build the package natively. If desired a host-architecture can be specified with the --host-architecture option instead.

Nathan Crock
  • 333
  • 2
  • 9
  • 12
    Couldn't there be a difference between `build dependencies` and `dependencies`? As in, if you normally install a program you get dependencies that it needs to actually run, and with build-dependencies I think more about libraries, compilers, stuff like that. So as I'm not sure (this answer does have upvotes) but it seems to me it is not trivial that getting build-dependencies is the same as getting the (run) dependencies the packages has? – Nanne Feb 25 '14 at 08:08
  • 1
    You are correct. At the of answering this, so very long ago, I did not have a complete understanding of the difference between build dependencies (build time) and dependencies (run time). Thank you for clarifying Nanne! – Nathan Crock Oct 01 '16 at 22:13
5

aptitude will let you specify a query instead of a package name when installing. If you wanted to install the dependencies of package named foo, you can install the packages which have a reverse dependency on foo:

aptitude install '?reverse-depends(foo)'

or

aptitude install '~Rfoo'

The problem with installing a package then removing it, is that all of the packages which get installed as dependencies will be marked as "automatically installed", and would be removed by any install/remove/upgrade action by aptitude or when you run apt-get autoclean unless you mark them as manually installed using aptitude mark or the apt-mark command.

However, this begs the question of why you would want to do this my best guess is that you are trying to install dependencies for some software which you are going to compile by hand. In that case, you would install the build dependencies first with apt-get build-dep packagename, but then you should be creating a dummy package which has the runtime dependencies (which generally differ from the build dependencies) by using the equiv package to build a dummy package with the correct dependencies for your manually compiled program. See information about equivs in The APT HOWTO

stew
  • 9,263
  • 1
  • 28
  • 43
3

In case of building pkgname from sources

apt-get build-dep pkgname
eri
  • 274
  • 2
  • 4
  • 15
  • 1
    build dependencies are not runtime dependencies – sehe Jul 21 '16 at 09:32
  • >> In case of building pkgname from sources – eri Jul 21 '16 at 10:53
  • I don't know where that's guaranteed/documented. Also, still doesn't make it the same for any purpose. I use build-dep [all the time](http://stackoverflow.com/search?q=user%3A85371+build-dep) but I'd really like a better answer to the current question. I need that too. – sehe Jul 21 '16 at 10:55