dnf is the package manager for Red Hat Enterprise Linux and its derivatives — AlmaLinux, Rocky Linux, Oracle Linux — and Fedora. It replaced yum in RHEL 8; on current systems yum is simply an alias for dnf, so old commands keep working.
Update
sudo dnf check-update # list available updates
sudo dnf upgrade # install all updates (same as "dnf update")
sudo dnf upgrade --security # security updates only
sudo dnf upgrade nginx # one package
dnf refreshes repository metadata automatically when it’s stale; sudo dnf makecache forces it.
Need a reboot after updates?
sudo dnf needs-restarting -r
(Provided by dnf-utils/yum-utils on some releases.)
Install and remove
sudo dnf install nginx
sudo dnf install -y git htop tmux
sudo dnf install ./package.rpm # local RPM with dependencies
sudo dnf reinstall nginx
sudo dnf remove httpd
sudo dnf autoremove # remove unneeded dependencies
Search and inspect
dnf search redis
dnf info nginx
dnf list installed | grep php
dnf list --available 'php*'
dnf provides /usr/bin/htpasswd # which package provides a file or command
dnf repoquery --requires nginx # dependencies
rpm -ql nginx # files in an installed package
rpm -qf /etc/nginx/nginx.conf # owner package of a file
dnf provides is the answer to “which package do I install to get command X?” — e.g. dnf provides '*/semanage'.
Repositories and EPEL
dnf repolist # enabled repositories
dnf repolist all # including disabled ones
sudo dnf config-manager --set-enabled crb # CodeReady Builder (needed by many EPEL packages)
sudo dnf install epel-release # Extra Packages for Enterprise Linux
EPEL, maintained by the Fedora project, provides thousands of packages not in the base distribution — htop, fail2ban, certbot and more. On RHEL itself, CRB is enabled with subscription-manager repos --enable codeready-builder-for-rhel-9-$(arch)-rpms.
config-manager is part of dnf-plugins-core.
Package groups
dnf group list
sudo dnf group install "Development Tools"
Module streams (RHEL 8/9)
Some software is offered in several versions as module streams:
dnf module list php
sudo dnf module reset php
sudo dnf module enable php:8.2
sudo dnf install php php-fpm
RHEL/AlmaLinux/Rocky 10 moves away from modules toward regular versioned packages; check what your release offers.
History and rollback
dnf records every transaction:
dnf history
dnf history info 42
sudo dnf history undo 42 # revert that transaction
sudo dnf history rollback 40 # revert everything after transaction 40
Handy when an update breaks something — though undo depends on older package versions still being available in the repositories.
Lock a version
sudo dnf install 'dnf-command(versionlock)'
sudo dnf versionlock add docker-ce
dnf versionlock list
sudo dnf versionlock delete docker-ce
Or exclude packages from updates in /etc/dnf/dnf.conf: exclude=kernel*.
Clean up
sudo dnf clean all # clear cached metadata and packages
sudo dnf autoremove
Old kernels are kept according to installonly_limit in /etc/dnf/dnf.conf (default 3).
Automatic updates
sudo dnf install dnf-automatic
Edit /etc/dnf/automatic.conf (apply_updates = yes, optionally upgrade_type = security), then:
sudo systemctl enable --now dnf-automatic.timer
Speed up dnf
In /etc/dnf/dnf.conf:
max_parallel_downloads=10
fastestmirror=True
yum → dnf cheat sheet
| yum (old) | dnf |
|---|---|
yum update |
dnf upgrade |
yum install |
dnf install |
yum remove |
dnf remove |
yum search |
dnf search |
yum provides |
dnf provides |
yum history |
dnf history |
yum-config-manager |
dnf config-manager |
package-cleanup --oldkernels |
dnf remove --oldinstallonly |
Quick reference
| Task | Command |
|---|---|
| Update all | dnf upgrade |
| Install | dnf install PKG |
| Remove | dnf remove PKG |
| Search | dnf search TERM |
| Who provides a file | dnf provides PATH |
| Enable EPEL | dnf install epel-release |
| Undo a transaction | dnf history undo ID |
| Lock a version | dnf versionlock add PKG |
For Debian/Ubuntu, see the apt cheat sheet. Choosing between RHEL clones? Read AlmaLinux vs Rocky Linux.