Intermediate · Software and networking · topic 19 of 57 · 30 min
Installing software with dnf and rpm
Explanation
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.
dnf: the everyday tool
# 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-rpmsdnf 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
$ 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 installedrpm: asking about installed packages
$ 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_configYou 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
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.
$ 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 sshdPractice (0/3 done)
You need the "dig" command but do not know the package. What do you run?
Which command tells you which package installed /etc/chrony.conf?
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
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- Repositories, BaseOS, AppStream and module streamsSoftware and networking · same module
- Network basics: IP addresses, routes, DNS and the ip commandSoftware and networking · same module
- NetworkManager with nmcli, the hostname and name resolutionSoftware and networking · same module
- The Linux filesystem and everyday commandsDevOps: Git, Docker, Kubernetes and CI/CD · Linux for DevOps
- GRUB2, kernel arguments and the default kernelBoot, recovery and containers
- Everyday modules and handlersAnsible fundamentals
Questions people ask about this
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.
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.
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.
Where are RHEL 9 per-kernel boot entries stored?Related
Answer: /boot/loader/entries/
BLS entries live in /boot/loader/entries/.
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
- 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.
- Module 4 exam: Software and networking · 14 questions · 25 min, without help. 5 topics of this module still to finish first.
- 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