1. Introduction

Dependencies are prerequisite packages or libraries that are required for the proper working of a program. In Linux, when we install a program through repositories via apt or yum, the dependencies are automatically installed along with the program. The same applies to packages installed via Snaps or Flatpak. However, installing a program through a third-party source might require manually installing the dependencies.

Sometimes, we may need to check which packages depend on a specific package that might already be installed. In this tutorial, we’ll cover different ways to list the dependent packages of a program on Debian and RPM-based distributions.

2. Debian-Based Distributions

On Debian-based distributions, we can use the apt-cache and apt-rdepends commands to list the reverse dependencies of a package.

2.1. Using apt-cache

The apt-cache command is used to query and retrieve information about a package such as its version, description, dependencies, and dependents. Using the apt-cache command with the rdepends option specifically lists the dependents of a package.

Let’s check which packages depend on nano using the apt-cache command:

$ apt-cache rdepends nano
nano
Reverse Depends:
  usrmerge
  ubuntu-standard
  junior-writing
  ubuntu-standard

From the output, we can see the four packages that depend on nano. To limit the output to only the packages installed on our system, we can use the –installed option:

$ apt-cache rdepends --installed nano
nano
Reverse Depends:
  usrmerge
  ubuntu-standard
  ubuntu-standard

Now, it lists only the installed packages which depend on nano.

We can also use the apt-cache showpkg command to list the dependent packages of a package. For instance, to see which packages depend on nano, we’ll use:

$ apt-cache showpkg nano
Package: nano
Versions:
6.2-1 (/var/lib/apt/lists/pk.archive.ubuntu.com_ubuntu_dists_jammy_main_binary-amd64_Packages) (/var/lib/dpkg/status)
Description Language:
File: /var/lib/apt/lists/pk.archive.ubuntu.com_ubuntu_dists_jammy_main_binary-amd64_Packages
MD5: af29527665aea4297c3c5acbb24cf1fa
Description Language: en
File: /var/lib/apt/lists/pk.archive.ubuntu.com_ubuntu_dists_jammy_main_i18n_Translation-en
MD5: af29527665aea4297c3c5acbb24cf1fa

Reverse Depends:
usrmerge,nano 2.3.99pre3-1~
ubuntu-standard,nano
junior-writing,nano
ubuntu-standard,nano
Dependencies:
6.2-1 - libc6 (2 2.34) libncursesw6 (2 6) libtinfo6 (2 6) pico (0 (null)) nano-tiny (3 2.8.6-2) hunspell (0 (null)) nano-tiny (3 2.8.6-2) pico (0 (null))
Provides:
6.2-1 -

The apt-cache showpkg command shows information about the package version, dependencies, and dependents. In the output, we can see the list of dependent packages under Reverse Depends.

2.2. Using apt-rdepends

Another way to list the dependent packages in Debian-based distributions is to use the apt-rdepends command. The apt-rdepends command recursively lists package dependencies. However, if we use the apt-rdepends command with the -r option, we can get the reverse dependencies, listing each package that depends on a specified package.

If not already installed, we can install apt-rdepends using apt:

$ sudo apt install apt-rdepends

Let’s check which packages depend on the telnet package using the apt-rdepends command:

$ apt-rdepends -r telnet
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
telnet
  Reverse Depends: coturn (4.5.2-3.1~ubuntu22.04.1)
  Reverse Depends: forensics-extra (2.35)
  Reverse Depends: mininet (2.3.0-1ubuntu1)
  Reverse Depends: zssh (1.5c.debian.1-8)
coturn
forensics-extra
  Reverse Depends: forensics-full (2.35)
forensics-full
mininet
zssh
  Reverse Depends: deepin-terminal (5.2.11-1build1)
deepin-terminal

The output lists all the dependent packages, as well as the packages that in turn depend on those listed packages.

3. RPM-Based Distributions

On RPM-based distributions, we can use the repoquery and rpm commands to list dependent packages of a package.

3.1. Using repoquery

We can use the repoquery tool to list the dependent packages of a package. It queries information about a package from YUM repositories. Therefore, we can use the repoquery command to inquire about any package, regardless of whether it’s installed or not. 

We can install the repoquery tool using the yum command:

$ sudo yum install yum-utils

On newer distributions such as RHEL 8, Fedora, and CentOS 8, we can use the dnf command:

$ sudo dnf install yum-utils

Once installed, we can use the repoquery tool to list the reverse dependencies of a package. Here, we’ll use the repoquery command with the –whatrequires option. For instance, let’s check which packages depend on the curl package:

$ repoquery -q --whatrequires curl
abrt-addon-kerneloops-0:2.10.9-21.el8.x86_64
abrt-addon-xorg-0:2.10.9-21.el8.x86_64
clevis-0:15-1.el8.x86_64
dracut-live-0:049-191.git20210920.el8.x86_64
ipa-client-0:4.9.6-6.module_el8.5.0+947+fabc681e.x86_64
libguestfs-tools-c-1:1.40.2-28.module_el8.5.0+821+97472045.x86_64
libreport-plugin-kerneloops-0:2.9.5-15.el8.x86_64
osbuild-0:35-3.el8.noarch
rpm-0:4.14.3-19.el8.x86_64
rpmdevtools-0:8.10-8.el8.noarch
sblim-wbemcli-0:1.6.3-15.el8.x86_64
virt-dib-1:1.40.2-28.module_el8.5.0+821+97472045.x86_64
virt-v2v-1:1.40.2-28.module_el8.5.0+821+97472045.x86_64
wsmancli-0:2.6.0-8.el8.x86_64

The output shows a list of all packages that require curl as their dependency.

To include only the installed packages, we can use the –installed option:

$ repoquery -q --installed --whatrequires curl
abrt-addon-kerneloops-0:2.10.9-21.el8.x86_64
abrt-addon-xorg-0:2.10.9-21.el8.x86_64
clevis-0:15-1.el8.x86_64
rpm-0:4.14.3-19.el8.x86_64

On newer RPM-based distributions, we use the dnf repoquery command instead of repoquery:

$ dnf repoquery -q --installed --whatrequires curl

Notably, using this command requires installing the dnf-plugins-core package.

3.2. Using rpm

We can also use the rpm command to display the reverse dependencies.  This command works only for the installed packages. For example, let’s list all the installed packages that depend on the curl package:

$ rpm -q --whatrequires curl
rpm-4.14.3-19.el8.x86_64
clevis-15-1.el8.x86_64
abrt-addon-kerneloops-2.10.9-21.el8.x86_64
abrt-addon-xorg-2.10.9-21.el8.x86_64

Importantly, the output includes all the installed packages that have a direct dependency on the curl package itself. However, it doesn’t account for packages that might depend on specific files or libraries provided by curl.

4. Conclusion

In this article, we explored various methods to list dependent packages in Debian and RPM-based systems. On Debian-based systems, we used the apt-cache and apt-rdepends commands, while on RPM-based systems, we employed the repoquery and rpm commands. These methods allow us to identify which packages depend on a particular package.