Skip to content

Intermediate · Software and networking · topic 19 of 57 · 30 min

Installing software with dnf and rpm

Explanation

Software on RHEL comes in RPM packages. dnf downloads packages from repositories and installs them with all their dependencies; rpm queries what is installed. Learn dnf install, remove, update, search, info, provides and history, and rpm -qa, -qi, -ql and -qf.

Packages and dependencies

A package is a single file that holds a program, its config files and information about it: the version, a description, and its dependencies, meaning the other packages it needs to work. RHEL packages use the RPM format (Red Hat Package Manager) and have names like httpd-2.4.57-11.el9_4.x86_64.rpm: name, version, release (el9 means built for RHEL 9), and architecture.

Think of it like this: Installing a package with dependencies is like ordering a phone online: the shop also sends the charger and cable it needs. dnf is the shop that knows what goes with what. rpm is like the box label: it tells you what is inside, but on its own it does not fetch the missing charger.

dnf: the everyday tool

bash
# dnf install -y httpd            # install (and its dependencies); -y answers yes
# dnf remove httpd                 # uninstall
# dnf update                       # update everything (dnf upgrade is the same)
# dnf update openssh-server        # update one package
$ dnf search nginx                 # search names and summaries
$ dnf info httpd                   # version, size, repository, description
$ dnf provides /usr/sbin/semanage  # which package gives this file?
policycoreutils-python-utils-3.6-2.1.el9.noarch : SELinux policy core python utilities
$ dnf list installed | grep ^kernel
kernel.x86_64          5.14.0-427.13.1.el9_4    @rhel-9-for-x86_64-baseos-rpms

dnf provides is a lifesaver in exams and at work: you know the command you need (semanage, dig, ifconfig), but not the package name. It also accepts patterns: dnf provides "*/dig".

Groups and history

bash
$ dnf group list
Available Environment Groups:
   Server with GUI
   Server
   Minimal Install
Available Groups:
   Development Tools
   System Tools
   ...
# dnf group install "Development Tools"
$ dnf history
ID | Command line             | Date and time    | Action(s) | Altered
 7 | install -y httpd         | 2026-10-19 10:05 | Install   |    5
 6 | update                   | 2026-10-18 22:00 | Upgrade   |   41
# dnf history undo 7               # remove what transaction 7 installed

rpm: asking about installed packages

bash
$ rpm -qa | wc -l                     # how many packages are installed
612
$ rpm -q openssh-server               # is it installed? which version?
openssh-server-8.7p1-38.el9.x86_64
$ rpm -qi httpd | head -4             # information
$ rpm -ql httpd | grep conf$          # list the files it installed
/etc/httpd/conf/httpd.conf
$ rpm -qf /etc/ssh/sshd_config        # which package owns this file?
openssh-server-8.7p1-38.el9.x86_64
$ rpm -qc openssh-server              # only its config files
$ rpm -V openssh-server               # verify: which files changed since install
S.5....T.  c /etc/ssh/sshd_config
In rpm -V output, S = size changed, 5 = content changed, T = time changed, c = a config file.

You can install a downloaded .rpm file with dnf install ./file.rpm; dnf still fetches its dependencies from the repositories. Avoid rpm -i for that: it does not resolve dependencies and leaves dnf's history out of the picture.

Kernels are special

dnf update installs a new kernel next to the old one instead of replacing it, and keeps a few versions (3 by default, set by installonly_limit in /etc/dnf/dnf.conf). If the new kernel has a problem, you can pick the older one in the GRUB menu. The new kernel is used only after a reboot.

Common mistakes

  • Running dnf install without sudo or root: "This command has to be run with superuser privileges".
  • Installing random .rpm files from websites. Only use repositories you trust: Red Hat, EPEL for extras, or your company's mirror.
  • Updating production servers blindly at noon. Plan updates, test them on a staging server first, and keep dnf history undo and the old kernel as your rollback.

Need help?

Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.

Try:

Watch the lesson

Installing software with dnf and rpm · 1/6

name-version-release.arch.rpm

Software on RHEL comes as RPM packages: a program, its files and a list of what it depends on.

Prefer a video by a teacher? Find free videos on “rhel 9 dnf rpm package management tutorial” on YouTube ↗

In real life: Patching a hospital's servers after a security alert

A security advisory says an OpenSSH flaw is being exploited. The admin at a Kochi hospital chain first checks which version each server runs with rpm -q, updates only openssh on a test server, checks that SSH still works, then rolls the update to the rest in the evening. dnf history keeps a record of exactly what changed and when, which the hospital's auditors ask for.

bash
$ rpm -q openssh-server
openssh-server-8.7p1-34.el9.x86_64
# dnf update -y openssh-server
...
Upgraded:
  openssh-8.7p1-38.el9.x86_64  openssh-clients-8.7p1-38.el9.x86_64  openssh-server-8.7p1-38.el9.x86_64
Complete!
# systemctl restart sshd

Practice (0/3 done)

Task 1 · Question

You need the "dig" command but do not know the package. What do you run?

Task 2 · Question

Which command tells you which package installed /etc/chrony.conf?

Task 3 · Code · Python

RPM file names look like "httpd-2.4.57-11.el9_4.x86_64.rpm": name-version-release.arch.rpm. The name itself can contain dashes (like "openssh-server"). Write split_rpm(filename) that returns a dict with name, version, release and arch. Hint: the last two dashes separate name, version and release.

Quick quiz

Question 1

1.What does dnf do that plain rpm -i does not?

Question 2

2.In httpd-2.4.57-11.el9_4.x86_64.rpm, what is "el9_4"?

Question 3

3.Which command lists every file installed by a package?

Question 4

4.After dnf update installs a new kernel, when is it used?

Question 5

5.What does dnf history undo 12 do?

Read more (free)

Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.

What does dnf do that plain rpm -i does not?

Answer: Resolves and downloads dependencies from repositories

dnf works out and fetches dependencies.

In httpd-2.4.57-11.el9_4.x86_64.rpm, what is "el9_4"?

Answer: Part of the release, meaning built for RHEL 9.4

The release field tells you the build and target RHEL version.

Which command lists every file installed by a package?

Answer: rpm -ql

-ql = query list.

After dnf update installs a new kernel, when is it used?

Answer: After the next reboot

The running kernel changes only at boot.

What does dnf history undo 12 do?

Answer: Reverses the changes made in transaction 12

undo reverses that transaction.

What should you run after changing repo files if dnf shows old data?Related

Answer: dnf clean all

dnf clean all removes cached metadata.

From Repositories, BaseOS, AppStream and module streams

Which package manager do you use on Rocky Linux?Related

Answer: dnf

Rocky Linux and other RHEL-family systems use dnf. apt is for Debian and Ubuntu, apk for Alpine.

From The Linux filesystem and everyday commands

Which command shows the RHEL release?Related

Answer: cat /etc/redhat-release

/etc/redhat-release holds the release line. uname -r shows the kernel version instead.

From What Linux and Red Hat Enterprise Linux are

Where are RHEL 9 per-kernel boot entries stored?Related

Answer: /boot/loader/entries/

BLS entries live in /boot/loader/entries/.

From GRUB2, kernel arguments and the default kernel

Pass the quiz (60% or more) or mark this topic as done when you are ready.

Your progress is saved on this device only.

Next steps

  1. 4 more topics in “Software and networking” before its exam: Repositories, BaseOS, AppStream and module streams, Network basics: IP addresses, routes, DNS and the ip command, NetworkManager with nmcli, the hostname and name resolution, firewalld: zones, services and ports.
  2. Module 4 exam: Software and networking · 14 questions · 25 min, without help. 5 topics of this module still to finish first.
  3. Then the next module, Storage: partitions, file systems and LVM. 57 topics left in the course before the final exam.

← Previous: Tuning profiles with tuned, and time with chrony