dnf is the package manager on every RHEL-family distro from RHEL 8 onward — Rocky, Alma, Oracle Linux, Fedora. It replaced yum, though yum still exists as a symlink for muscle-memory. This guide covers the commands you will run weekly.
Prerequisites
- Rocky 9 / Alma 9 / RHEL 9 with
sudo. - Outbound HTTPS reachable for the configured mirrors.
Step 1: Refresh metadata and list updates
sudo dnf check-update # exit code 100 = updates available
sudo dnf list --installed | wc -l
sudo dnf list --upgrades
Step 2: Install, remove, search
sudo dnf install -y vim git tmux
sudo dnf remove -y unwanted-pkg
dnf search redis # search names + summaries
dnf info redis # detailed metadata
dnf provides /usr/bin/openssl # which package owns this file?
Step 3: Upgrades
sudo dnf upgrade -y # security + bugfix updates
sudo dnf upgrade --security -y # security only
sudo dnf upgrade --refresh -y # force a metadata refresh first
After kernel updates:
sudo dnf needs-restarting -r # 0 = no reboot; 1 = reboot needed
Step 4: Repositories
dnf repolist # enabled repos
dnf repolist --all # all configured repos (incl. disabled)
sudo dnf config-manager --enable crb # enable CodeReady Builder
sudo dnf install -y epel-release # add EPEL
sudo dnf config-manager --add-repo https://example.com/repo.repo
config-manager is in dnf-plugins-core on RHEL 9 — install it if missing.
Step 5: Modules and streams (AppStream)
RHEL 9 ships PHP, Node, Python, etc. as modules with selectable streams:
dnf module list nodejs
sudo dnf module enable -y nodejs:20
sudo dnf module install -y nodejs:20/common
sudo dnf module reset nodejs # back to default stream
Step 6: Clean and lock
Reclaim disk used by the package cache:
sudo dnf clean all
sudo dnf clean dbcache
Lock a package at a known version (useful for production stability):
sudo dnf install -y python3-dnf-plugin-versionlock
sudo dnf versionlock add postgresql-server
sudo dnf versionlock list
Verify
sudo dnf history list | head # last transactions
sudo dnf history info 5 # what changed in transaction 5
sudo dnf history undo 5 # revert that transaction (carefully)
Conclusion
dnf is the same toolbox as apt on Debian/Ubuntu, just spelled differently. Learn check-update, upgrade, install, remove, info, provides, history, and you are 95 percent of the way to RHEL operations.
Next steps
- Set up firewalld zones for inbound rules.
- See Subscribe RHEL 9 to AppStream if you are on Red Hat proper rather than Rocky/Alma.
- Read the Fedora dnf vs yum post for the Fedora-specific differences.
Comments
0 total · 0 threads