371

In order to research what caused the installation of a given package, I'd like to get a list of packages which depend on that package. I couldn't find anything obvious in man dpkg.

Garrett
  • 750
  • 3
  • 13
  • 28
l0b0
  • 8,529
  • 8
  • 42
  • 67
  • Related: http://askubuntu.com/questions/13296/how-do-i-find-the-reverse-dependency-of-a-package – Seth Feb 26 '15 at 03:58
  • 15
    The older question's answers all revolve around `aptitude`, something that hasn't been installed by default for years. In 2017, everyone on Ubuntu still has `apt-cache`. Anyone who follows the linked question is going to get lost in a discussion about a program few will have. – Lambart Aug 18 '17 at 17:48

8 Answers8

462

apt-cache rdepends packagename should do what you want.

To limit it to packages that are installed on your system: apt-cache rdepends --installed packagename

Bram
  • 2,169
  • 24
  • 42
RobotHumans
  • 29,190
  • 4
  • 76
  • 114
  • 3
    Excellent! `apt-cache rdepends tofrodos` confirmed the [suspicion](http://superuser.com/questions/52044/convert-crlfs-to-line-feeds-on-linux) that it was installed by another package (the obsoleted `dos2unix`). – l0b0 Apr 30 '12 at 13:12
  • Good deal. I do wish there was a recursive option. Sadly there is not as far as I am aware. – RobotHumans Apr 30 '12 at 13:27
  • 3
    As for today (apt version 0.9.9.1), there is --recurse option that works with rdepends. – jarno Dec 22 '13 at 14:00
  • Thanks for the heads up. /me is even more pleased than he was. – RobotHumans Dec 22 '13 at 22:50
  • @l0b0: btw, if you only needed to know if a package was installed automatically as a dependency - there is `apt-mark showauto` available – zerkms Feb 03 '14 at 21:24
  • 96
    If you add `--installed`, the output is even useful for packages which can be used by many others: `apt-cache rdepends --installed packagename` – quazgar May 27 '14 at 22:08
  • 5
    There's a slightly different syntax which helped me to differentiate between Recommends, Depends, Suggests, etc. Syntax is `sudo apt rdepends packagename` (Notice it is not using apt-cache but simply apt) – Vahid Pazirandeh Nov 16 '17 at 05:26
  • 7
    For the output, why do some of the packages have a vertical bar (pipe symbol) before them? – Vahid Pazirandeh Nov 16 '17 at 05:35
  • 1
    The command `apt-cache rdepends packagename` seem not to work in WSL. – Arcticooling Jan 17 '18 at 16:45
  • That sounds like a them problem not a me problem. It works on native systems. – RobotHumans Jan 18 '18 at 10:41
  • Unfortunately, the list is not sorted alphabetically (unlike the result of `apt-rdepends --reverse `) and includes reverse dependencies that aren’t installed by default (which I consider strange for a command with “cache” in the name). To address those issues, one can use `apt-cache rdepends --installed | tail --lines=+3 | sort`. (The `tail` command is used to strip the two heading lines, which must be done before the sort occurs.) – Patrick Dark Jun 08 '19 at 22:15
  • 1
    To add to the comment by @VahidPazirandeh: `apt` does not need `sudo` for operations like `rdepends`. Just `apt rdepends packagename` suffices. – Frank Kusters Mar 17 '22 at 09:13
  • @quazgar Unfortunately, `--installed` does not work as one may think and is rather useless. See [my answer](https://askubuntu.com/a/1451755/691424). – vinc17 Jan 25 '23 at 11:35
95

aptitude has a fairly nice way of handling this:

$ aptitude why bash
i   foomatic-filters PreDepends bash (>= 2.05)

By default, it only lists the "most installed, strongest, tightest, shortest" reason, but you can use aptitude -v why to make it output everything it finds.

n.st
  • 1,330
  • 11
  • 19
tumbleweed
  • 7,986
  • 23
  • 36
  • 7
    Seems like it considers only the installed packages, not everything available. And that was what I needed. – Tuukka Mustonen Jul 25 '13 at 10:06
  • 4
    For that you want `reverse-depends` in `ubuntu-dev-tools` – tumbleweed Jul 25 '13 at 11:38
  • How about debian? – Tuukka Mustonen Jul 25 '13 at 12:08
  • 1
    `ubuntu-dev-tools` is in Debian – tumbleweed Jul 26 '13 at 11:18
  • 1
    This is great. I learned that `openssh-server` *recommended* (and therefore installed) `xauth` on a headless server, dragging in *hundreds* of x11 dependencies and dozens of useless updates a month. That's the problem with automated package management! – BaseZen Mar 02 '18 at 03:17
  • I've found this the best way to figure out long and complex reverse dependencies. It does require installing `sudo apt install aptitude`, but it's really worth it. Helpe my know why `ubuntu-unity-desktop` ended up pulling `mysql-common`! – MestreLion Sep 21 '19 at 03:14
  • 1
    Worth noting that the `--recurse` option is useful too. As in `apt rdepends --recurse packagename` – Bernd Wechner Nov 18 '20 at 06:22
36

The simplest option is still:

apt rdepends package-name

which does not require you to install any package.

Corrado Topi
  • 627
  • 6
  • 3
  • 1
    What is this adding to the accepted answer? – l0b0 Nov 26 '18 at 23:58
  • 9
    The accepted answer has nothing to do with this one. The output is *completely* different and way more useful for human consumption than apt-cache's. The answer mentions that apt-cache is not installed by default everywhere - that alone should be a rather good hint why this answer has its purpose. finally, this is actually the answer I was looking for, so any downvote is rather silly. – stefanct Nov 28 '18 at 13:21
  • 2
    One very significant reason why this is better than the accepted version is that it includes the _version_ of the dependencies, unlike `apt-cache`s output. It's exactly what I needed right now (debugging a glibc 2.28 incompatibility, so upvoting) – Per Lundberg Jan 02 '19 at 09:10
  • 1
    upvote for using just apt. at the time of the original answer, I'm not sure this just apt solution would have been valid, but if it is now, that's good. – RobotHumans Apr 20 '19 at 11:53
34
apt-cache showpkg <pkgname> 

Example:

apt-cache showpkg lightdm
Seth
  • 57,282
  • 43
  • 144
  • 200
qorrow
  • 511
  • 3
  • 3
19

There is more than one way, with each method showing a different output.

For a detailed view of the full reverse dependency tree;

aptitude install apt-rdepends
apt-rdepends -r bash

Alternatively;

apt-cache showpkg bash

Or a concise list:

apt-cache rdepends bash
Zanna
  • 69,223
  • 56
  • 216
  • 327
papashou
  • 2,440
  • 1
  • 14
  • 9
  • What exactly does `rdepends` show in that tree? `apt-rdepends php7.0-fpm` shows `sed`. `sed` doesn't depend on PHP, let alone PHP FPM. – Dan Dascalescu Jan 09 '18 at 23:21
  • It is reverse depends, it means that PHP depends on sed. – Erik Berkun-Drevnig Apr 25 '18 at 03:30
  • 2
    Hi guys, actually "apt-rdepends" stands for "recursive dependency". If you want reverse recursive dependency, you have to type : `apt-rdepends -r yourPackageNameHere` – SebMa Apr 27 '18 at 12:56
  • The apt-cache man page says "rdepends shows a listing of each reverse dependency a package has". Whereas apt-rdepends requires the -r option to do reverse dependencies, as @SebMa says. – NeilG Feb 05 '19 at 03:16
16

In addition to other good answers, an apt/apt-get -s does a "simulated" removal (or install).

sudo apt -s remove <pkgname>

Using -s or --simulate to remove (or install) packages, will normally list any dependencies affected. It will show orphaned packages when removing, or needed dependencies when installing, without actually executing the install or remove. Informational only.

BeastOfCaerbannog
  • 12,964
  • 10
  • 49
  • 77
B. Shea
  • 1,120
  • 13
  • 16
  • `apt remove -s php7.0-fpm` shows `The following additional packages will be installed: apache2 apache2-bin apache2-data libapache2-mod-php7.0 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.1-0`. Why would apache get installed if I remove PHP FPM? – Dan Dascalescu Jan 09 '18 at 23:22
  • @DanDascalescu Hmm. Might be a bad install/remove script for apt pkg or might be you have some other dependencies that install apache2 as dep (meaning a webserver is needed - and I believe apache2 is default web server). Could be a few things. Just not sure. Has the smell of a good post on AskUbuntu if you haven't found an answer. – B. Shea Jul 10 '18 at 16:26
1

With the reverse-depends command from the package: ubuntu-dev-tools

reverse-depends libjs-openlayers
# For build depends search
reverse-depends -b libjs-openlayers
Reverse-Recommends
* gis-osm

Reverse-Depends
* cyclograph
* phpmyadmin
* sumo-tools

Packages without architectures listed are reverse-dependencies in: amd64, arm64, armhf, i386, ppc64el, s390x
1

Since the --installed option of apt-cache was mentioned in comments of RobotHumans's answer and does not make much sense as the matching is done against all versions, including uninstalled ones (see Debian bug 1029586), here's the solution proposed by Julian Andres Klode to get the reverse dependencies among the installed packages:

apt list '?any-version(?installed?depends(?exact-name(packagename)))'

Note that packagename is just the package name, without architecture information. For instance, libpcre3 works, but not libpcre3:amd64.

vinc17
  • 166
  • 6