The other day while writing up the blog post How to install Oracle Database 18c XE on Oracle Linux 8 I stumbled across the question of how to list all the dependencies of a rpm package on Oracle Linux 8. The solution was easier than I thought but required some googling, so here is it for easy reference:
dnf command provides a nice little sub command called
repoquery which is equivalent to
rpm -q and to the
repoquery command provided by
yum-utils on Linux 7. It’s quite a powerful little command which is reflected by the long list of parameters it takes. You can check for yourself by just typing
dnf repoquery --help. One of these parameters is
--requires which allows you to, as the documentation puts it “Display capabilities that the package depends on.“
So the next time you want to know what dependencies a package has, all you have to type is
dnf repoquery --requires <your package name>, for example:
[root@localhost ~]# dnf repoquery --requires vim Last metadata expiration check: 0:36:36 ago on Wed 05 May 2021 09:24:46 PM PDT. autoconf desktop-file-utils >= 0.2.93 file gcc gettext gpm-devel gtk3-devel libICE-devel libSM-devel libX11-devel libXpm-devel libXt-devel libacl-devel libappstream-glib libselinux-devel lua-devel ncurses-devel perl(ExtUtils::Embed) perl(ExtUtils::ParseXS) perl-devel perl-generators python2-devel python3-devel rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 ruby ruby-devel [root@localhost ~]#
The package does not even have to be installed on the local machine,
dnf will automatically resolve any packages dependencies based on the repository information from the web, which makes it my favorite over
[root@localhost ~]# dnf list installed | grep oracle-database-preinstall-19c [root@localhost ~]# dnf repoquery --requires oracle-database-preinstall-19c Last metadata expiration check: 0:40:03 ago on Wed 05 May 2021 09:24:46 PM PDT. /bin/bash /bin/sh /etc/redhat-release bash bc bind-utils binutils config(oracle-database-preinstall-19c) = 1.0-1.el8 config(oracle-database-preinstall-19c) = 1.0-2.el8 ethtool glibc glibc-devel initscripts ksh libaio libaio-devel libgcc libnsl libstdc++ libstdc++-devel make module-init-tools net-tools nfs-utils openssh-clients openssl-libs pam procps psmisc rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1 rpmlib(PayloadIsXz) <= 5.2-1 smartmontools sysstat tar unzip util-linux-ng xorg-x11-utils xorg-x11-xauth [root@localhost ~]#
So if you ever wonder again what dependencies a package has,
dnf repoquery is your friend! 🙂
3 thoughts on “How to list dependencies of a rpm package via dnf”
This command just pulls metadata from the RPM’s “requires” field. A “capability” is not a “package.” To resolve “capabilities” to “packages,” you also need the –resolve flag. Also, “Linux 8” isn’t a thing. The Linux kernel is on version 5.16.12 as of 2 March 2022. I presume you mean the Red Hat Enterprise Linux version 8 family (RHEL, CentOS, and Oracle Linux).
Thanks a lot for that additional information!
You are right, I am talking about Oracle / RHEL Linux 8, will add that to the post.
This is a great tip! The phrasing “lists requirements” is a bit ambiguous. This will list what the given RPM depends on. If you want to find out the reverse – which other packages require the given one, use –whatrequires instead of –requires. This will only give you the immediate dependencies; it won’t recurse to show you rpms that depend on your dependencies. It will also only show you installed RPMs.