LinuxXI · Package Managementdnf and rpm
dnf and rpm — RHEL-family package management
What you'll learn
- Update, upgrade, install, and remove packages with dnf
- Query installed packages and their contents
- Configure repositories and GPG keys safely
- Distinguish dnf from rpm and use each appropriately
Prerequisites
Verified against Ubuntu 24.04 LTS · Debian 12 (Bookworm) · RHEL 9.x · Rocky Linux 9.x · AlmaLinux 9.x · Linux kernel 6.1 LTS / 6.6 LTS · systemd 255+ · OpenSSH 8.7p1 (RHEL 9) / 9.6p1 (Ubuntu 24.04) · nftables 1.0.x · chrony 4.x · Pacemaker 2.1.x · Corosync 3.1.x · 2026-08-09
dnf is the high-level interface to the RPM package system on
modern RHEL-family distributions. rpm is the low-level tool.
RHEL 8 deprecated yum in favour of dnf; on RHEL 9 and
later, dnf is the only high-level tool.
The day-to-day commands
$ sudo dnf check-update; sudo dnf upgrade -y...Illustrative output
$ dnf search web-server | head; dnf info nginx...Illustrative output
$ sudo dnf install nginx; sudo dnf remove nginx...Illustrative output
Module streams
RHEL-family packages use modules for multiple versions:
$ dnf module list; dnf module enable nodejs:18; sudo dnf install @nodejs:18...Illustrative output
Querying installed packages
$ rpm -qa 'nginx*'; rpm -ql nginx; rpm -qf /etc/nginx/nginx.conf...Illustrative output
$ rpm -V nginx 2>&1 | headS.5....T. c /etc/nginx/nginx.conf\n..?Illustrative output
Configuring repositories
$ ls /etc/yum.repos.d/; cat /etc/yum.repos.d/rocky.repo 2>/dev/null | head -20...Illustrative output
A typical local-mirror.repo file has the following structure. The bracketed section name is the repository identifier, the baseurl points to the package source, enabled activates the repository, gpgcheck enforces signature verification, and gpgkey references the GPG key file or URL. The optional priority field (covered earlier in this lesson) controls preference.
dnf history and rollback
$ dnf history list; sudo dnf history undo <id>...Illustrative output
Module streams and version pinning
$ dnf module list nginx; dnf module info nginx:1.24...Illustrative output
Knowledge check
Knowledge check · 3 questions
Q1. What does rpm -V nginx report?
Q2. gpgcheck=1 with a trusted gpgkey is what stops a compromised mirror from installing arbitrary binaries.
Q3. Which of the following are correct dnf practices? Select all that apply.
Passing score: 75%. Answers are checked in this browser.