dnf: install, remove, search, history
This lesson is open to everyone. The other lessons open with a package: sign in or sign up, then choose a package.
Key points
dnf install,dnf remove,dnf upgrade— there is no separate step likeapt update, dnf refreshes the list itself.dnf search name,dnf info package,dnf provides */command— finding which package you need.dnf group list/dnf group install "Development Tools"— a set of packages with one command.dnf historykeeps every transaction with a number,dnf history undo Nrolls it back.- An installed service does not start on RHEL:
systemctl enable --nowis a separate step.
Compared with apt
| Job | Ubuntu (apt) | RHEL (dnf) |
|---|---|---|
| Refresh the list | apt update | Not needed (automatic when the cache expires) |
| Install | apt install nginx | dnf install nginx |
| Remove | apt remove nginx | dnf remove nginx |
| Update everything | apt upgrade | dnf upgrade |
| Search | apt search | dnf search |
| Details | apt show | dnf info |
| Which package owns a file | dpkg -S | dnf provides / rpm -qf |
| History and undo | None | dnf history, dnf history undo |
The yum command still works on RHEL 9, but it is really a redirect to dnf.
Installing and removing
[ali@srv-web01 ~]$ sudo dnf install -y httpd Updating Subscription Management repositories. Last metadata expiration check: 0:12:41 ago on Tue 01 Dec 2026 10:20:11 AM +04. Dependencies resolved. ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: httpd x86_64 2.4.57-11.el9_4 rhel-9-appstream 47 k Installing dependencies: apr x86_64 1.7.0-12.el9_3 rhel-9-appstream 126 k httpd-core x86_64 2.4.57-11.el9_4 rhel-9-appstream 1.5 M ... Complete! [ali@srv-web01 ~]$ rpm -q httpd httpd-2.4.57-11.el9_4.x86_64 [ali@srv-web01 ~]$ systemctl is-active httpd inactive
Note the last line: the package is installed, but the service is not running. On RHEL the admin does this explicitly:
[ali@srv-web01 ~]$ sudo systemctl enable --now httpd Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
| Command | What it does |
|---|---|
dnf install package | Installs (-y — without asking) |
dnf reinstall package | Restores damaged files |
dnf remove package | Removes (together with dependencies no longer needed) |
dnf upgrade | Updates the whole system |
dnf upgrade package | Only one package |
dnf check-update | Are there updates — without installing anything |
dnf upgrade --security | Security updates only |
Searching: which package do you need
[ali@srv-web01 ~]$ dnf search mariadb | head -n 4 ======================== Name Exactly Matched: mariadb ======================== mariadb.x86_64 : A very fast and robust SQL database server ======================== Name & Summary Matched: mariadb ====================== mariadb-server.x86_64 : The MariaDB server and related files [ali@srv-web01 ~]$ dnf provides "*/semanage" policycoreutils-python-utils-3.6-2.1.el9.noarch : SELinux policy core python utilities Repo : rhel-9-for-x86_64-baseos-rpms Matched from: Filename : /usr/sbin/semanage
dnf provides is very useful in RHCSA: when a command is missing (command not found), it finds which package provides it. For example, the semanage command is in the policycoreutils-python-utils package — hard to guess from the name.
Package groups
[ali@srv-web01 ~]$ dnf group list --hidden | head -n 6 Available Environment Groups: Server with GUI Server Minimal Install Available Groups: Container Management Development Tools [ali@srv-web01 ~]$ sudo dnf group install -y "Development Tools"
A group is a set of packages for one purpose: "Development Tools" brings gcc, make, git and so on.
History and undo
One of dnf's most useful features:
[ali@srv-web01 ~]$ sudo dnf history ID | Command line | Date and time | Action(s) | Altered -------------------------------------------------------------------------------- 4 | install -y php | 2026-12-01 10:41 | Install | 14 3 | install -y httpd | 2026-12-01 10:33 | Install | 9 2 | upgrade -y | 2026-12-01 09:58 | Upgrade | 37 1 | | 2026-11-28 14:02 | Install | 412 EE [ali@srv-web01 ~]$ sudo dnf history info 4 | head -n 8 [ali@srv-web01 ~]$ sudo dnf history undo 4 -y
undo 4 fully rolls back transaction 4: it removes the 14 packages that came with php. If you installed the wrong package or an update caused trouble, this is the fastest way out.
The cache
[ali@srv-web01 ~]$ sudo dnf clean all [ali@srv-web01 ~]$ sudo dnf makecache
When a repository changes or "metadata" errors appear, cleaning and rebuilding the cache helps.
Lab: install httpd and roll back
Start with the "dnf: install httpd" task in the Red Hat simulator, then try the history part on your own VM:
- Look at the repositories and install httpd:
[ali@srv-web01 ~]$ dnf repolist [ali@srv-web01 ~]$ sudo dnf install -y httpd [ali@srv-web01 ~]$ rpm -q httpd
- See that the service is not running, then start it:
[ali@srv-web01 ~]$ systemctl is-active httpd inactive [ali@srv-web01 ~]$ sudo systemctl enable --now httpd [ali@srv-web01 ~]$ curl -s http://localhost | grep -o "<title>.*</title>" <title>Test Page for the HTTP Server on Red Hat Enterprise Linux</title>
- (On your own VM) install the
treepackage, find the transaction number withdnf historyand roll it back withdnf history undo.rpm -q tree→package tree is not installed.
Check: in the simulator "dnf: install httpd" is green, and curl localhost returns the test page.
Check yourself
5 questions · answers are shown instantly · 3 correct answers complete the lesson
1What is the RHEL equivalent of Ubuntu's apt update?
2semanage: command not found. How do you find which package you need?
3How do you roll back a wrongly installed package together with its transaction?
4Right after installing httpd, what does systemctl is-active httpd show?
5Which command installs security updates only?
Comments
Sign in to comment.