dnf
Overview
dnf (Dandified YUM) is the primary high-level package manager on Fedora, RHEL 8+, CentOS Stream, Rocky, AlmaLinux, and related RPM distributions. This book is Ubuntu-first (apt), but operators routinely jump onto RHEL-family hosts — learn dnf as the counterpart to apt. It installs/removes RPM packages, resolves dependencies, and manages repositories/modules.
On older RHEL/CentOS 7 systems you will still see yum; on modern releases yum is often a compatibility symlink to dnf.
Syntax
dnf [options] <command> [<args>...]Common commands
| Command | Description |
|---|---|
install PKG… |
Install packages |
remove PKG… |
Remove packages |
reinstall PKG… |
Reinstall |
update / upgrade |
Apply updates (wording varies by version; both common) |
check-update |
List available updates without installing |
search KEYWORD |
Search names/descriptions |
info PKG |
Package metadata |
list |
List packages (--installed, --available, …) |
provides / whatprovides |
Which package owns a file/feature |
repoquery |
Advanced query (also dnf repoquery) |
repolist |
Enabled repositories |
makecache |
Refresh metadata |
clean all |
Clear caches |
history |
Transaction history / undo |
group install "Group Name" |
Environment/group packages |
module |
Modular streams (AppStream) |
distro-sync |
Sync to repo versions (powerful; careful) |
autoremove |
Remove unneeded deps (when supported) |
Common options
| Option | Description |
|---|---|
-y, --assumeyes |
Assume yes |
-q |
Quiet |
--refresh |
Force metadata refresh |
--enablerepo=ID / --disablerepo=ID |
Temporary repo toggles |
--setopt= |
Override config for this run |
--allowerasing |
Allow erasing conflicts to satisfy install |
--best / --nobest |
Strictness of version selection |
--security |
Prefer security updates where metadata allows |
--downloadonly |
Fetch without install |
--destdir=DIR |
With downloadonly, place RPMs here |
Safety
- Read the transaction summary before accepting (package installs/removals).
- Avoid blind
dnf update -yon production without a window and rollback plan. - Third-party repos and modular stream switches can pin you into painful upgrades.
dnf history undois helpful but not magic after major version jumps or manualrpm -Uvhchaos.- Prefer official AppStream modules over random COPR packages for critical runtimes.
Key Use Cases
- Install and update software on RHEL-family hosts
- Map a binary path back to an owning package
- Apply security updates selectively
- Review and reverse recent transactions
Examples with Explanations
Example: refresh and update
sudo dnf check-update
sudo dnf upgrade
# older muscle memory:
sudo dnf updatecheck-update is a dry look at pending work. Confirm changelogs for kernel and glibc bumps.
Example: install and remove
sudo dnf install htop jq curl
sudo dnf remove htopDependencies are resolved automatically. Removal may leave weak deps depending on config.
Example: search and inspect
dnf search nginx
dnf info nginx
dnf list installed 'nginx*'Non-root search/info works for most queries.
Example: which package owns a file
dnf provides /usr/bin/ps
dnf provides '*/bin/htop'Invaluable when a command is missing or two packages conflict.
Example: repository visibility
dnf repolist
dnf repolist all
sudo dnf config-manager --set-enabled crb # name varies by distroRocky/Alma often need CodeReady/CRB/PowerTools-style repos for extra build deps.
Example: transaction history
dnf history
dnf history info 42
sudo dnf history undo 42Undo a mistaken install when history still maps cleanly to reverse operations.
Example: download only
sudo dnf download --resolve nginx
# or
sudo dnf install --downloadonly --destdir=/var/tmp/rpms nginxUseful for air-gapped copies and change tickets that require artifact review.
Example: groups and modules
dnf group list
sudo dnf group install "Development Tools"
dnf module list nodejs
sudo dnf module enable nodejs:18
sudo dnf module install nodejs:18/commonModules select streams (versions) on RHEL-family AppStream — read stream notes before switching.
Example: security-focused updates
sudo dnf update --security
sudo dnf updateinfo list securityDepends on repository updateinfo metadata quality.
Example: clean caches
sudo dnf clean all
sudo dnf makecacheWhen metadata looks stale or disk under /var/cache/dnf is tight.
Example: scripted noninteractive
sudo dnf -y install package-nameStill log transactions and pin versions when builds must be reproducible.
Notes & Pitfalls
- This page is for RPM-family hosts; on Ubuntu use
apt/dpkg. yumvsdnf: preferdnfon modern systems; checkyum --versionif both exist.- EPEL is common for extra packages — enable deliberately.
- Kernel updates need reboot; live patching may exist separately (kpatch, vendor tools).
- Mixing
rpm -e --nodepswith dnf creates dependency debt — avoid. - Proxy/SSL interception breaks metadata fetches; configure
/etc/dnf/dnf.confand repo files carefully.
Additional Resources
man dnfman dnf.conf- Distribution docs: Fedora DNF guide, RHEL System Administrator’s Guide (packaging chapters)