dnf Command Guide for Installing Software on Fedora and RHEL
dnf is Fedora, RHEL, and their relatives’ package manager — it installs RPM packages, resolves dependencies, and keeps the system consistent.
What is dnf, and Why Use It?
dnf (Dandified YUM) is the default package manager on Fedora, RHEL, AlmaLinux, and Rocky Linux. It installs RPM packages — the .rpm archive format these distributions use — from configured repositories, resolving dependencies the same way apt does on Debian systems. Its older predecessor yum did the same job for over a decade; dnf replaced it because yum’s dependency resolver could not always find the best solution, only a solution. On modern systems yum still exists, but as a compatibility alias that calls dnf.
Why Learn dnf?
- It is the front door to the Red Hat world — Fedora workstations, RHEL servers, and most cloud images run on it.
- The resolver is smarter than
yum’s — module streams and better dependency solving mean fewer impossible upgrades. - It teaches the RPM model — once you know repos, RPMs, and dependency solving here, the pattern repeats everywhere.
yumanddnfare one skill — on any system where both exist,yum install Xis literallydnf install X.
dnfis the librarian of the RPM world: it knows every book in the repository, which books reference which others, and which editions your shelves already hold — so upgrades never leave a hole.
1. Refreshing and Checking for Updates
dnf refreshes repository metadata automatically, but an explicit check is the habit worth keeping:
sudo dnf check-update # list upgradable packages (exit code 100 means "yes, there are")
sudo dnf upgrade # upgrade everything installed
sudo dnf upgrade --refresh # force fresh metadata first
check-update prints nothing and exits 0 when the system is already current — a quiet success. Scripts test for exit code 100 (“updates available”) rather than parsing output.
To upgrade one package instead of the world:
sudo dnf upgrade htop # or: sudo dnf update htop
2. Installing a Package
sudo dnf install htop
dnf shows what it will install, asks for confirmation, and fetches dependencies automatically. In scripts, add -y:
sudo dnf install -y git curl tmux
Install several packages in one transaction, or a specific version when a newer one would break something:
sudo dnf install nginx-1.24.0-1.fc40
sudo dnf install @development-tools # install a package group
Groups (prefixed with @) bundle related packages — @development-tools is the classic one that pulls in compilers and debuggers. List them with dnf group list.
3. Removing Packages
sudo dnf remove htop
Removal keeps configuration files (RPMs do not have a purge equivalent — configs live in /etc and are only deleted if the package owns them and they are unmodified). To remove a package and everything that came in with it:
sudo dnf autoremove # remove orphaned dependencies
autoremove is the tidy-up habit: after removing a big package, run it and reclaim the dependency packages nothing needs anymore.
4. Searching and Inspecting Packages
dnf search editor # search names and descriptions
dnf info nginx # full details: version, size, license, dependencies
dnf list installed | grep -i python
dnf list available # everything the repos offer
dnf provides */htop # which package contains this file or command?
dnf repoquery --whatrequires curl # what would break if curl were removed?
dnf provides answers one of the most common Linux questions: “I have this file/command — which package installed it?” It searches file paths, so dnf provides */ffmpeg finds the package even when the name differs.
5. Installing Local RPM Files
dnf can install a downloaded .rpm directly, and — unlike rpm -i — resolves its dependencies first:
sudo dnf install ./some-package.rpm
sudo dnf install https://example.com/some-package.rpm
Prefer this over rpm -i whenever possible. The ./ prefix tells dnf “this is a local file, not a package name” — without it, dnf install some-package.rpm fails looking for a package named that.
6. Repository Management
Repository configuration lives in /etc/yum.repos.d/*.repo. List what is configured:
dnf repolist # enabled repos
dnf repolist --all # including disabled ones
dnf config-manager --set-enabled updates-testing # enable a repo (dnf5)
On Fedora and RHEL derivatives, third-party software often arrives via a vendor’s own repo file — install it once (usually from the vendor’s website) and the packages become normal dnf install targets from then on.
yum vs. dnf vs. rpm
Three names, one stack:
| Command | Role | Use it for |
|---|---|---|
dnf | The modern manager | Everything, on Fedora and modern RHEL |
yum | Compatibility alias | Old scripts and muscle memory; same job as dnf |
rpm | The low-level tool | Querying installed packages, not installing from repos |
yum on a modern system is dnf wearing an older name — yum install and dnf install do the same thing. The real distinction is rpm: it unpacks and queries individual .rpm files but does not resolve dependencies from repositories. You meet it mainly when inspecting:
rpm -qa # list every installed package
rpm -qi htop # information about an installed package
rpm -ql htop # list files owned by it
rpm -qf /usr/bin/htop # which package owns this file?
rpm -q --changelog htop # what changed between versions
Rule of thumb: install and remove with dnf; use rpm only to ask questions about what is already installed.
Common Pitfalls
- Using
yumon old RHEL for new features.yumcannot install modular packages or handle some modern repo syntax; on RHEL 8+ preferdnf, and on RHEL 7 rememberyumis the only option. - Forgetting the
./for local files.dnf install file.rpmsearches the repos;dnf install ./file.rpminstalls the file. The dot is the whole difference. - Skipping
autoremove. Repeated install/remove cycles orphan dependency packages thatdnf list installedwill show you still occupying space. - Mixing repos from different releases. A Fedora 39 repo file on a Fedora 40 system causes dependency chaos; keep repo files matched to your release.
- Trusting exit codes blindly in scripts.
dnf check-updateexits 100 when updates exist — a “failure” that is actually success-with-news. Test for 0 or 100. - Running as a normal user. Everything that changes the system needs root;
dnfwill refuse rather than half-do the work.
Related Pages
| Page | Why it is here |
|---|---|
| Package Management | The concept section — packages, repos, and why managers exist. |
| apt | The same job on Debian and Ubuntu. |
| pacman | The same job on Arch Linux. |
| snap | Cross-distro packages that can coexist with dnf. |
| flatpak | Desktop apps delivered independently of the system repos. |
| sudo | Why most of these commands need it. |
dnf Cheatsheet
| Command | What it does |
|---|---|
sudo dnf check-update | List upgradable packages (exit 100 = updates available). |
sudo dnf upgrade | Upgrade every installed package. |
sudo dnf upgrade htop | Upgrade one package. |
sudo dnf install htop | Install a package (and its dependencies). |
sudo dnf install -y git curl | Install several packages without asking. |
sudo dnf install ./file.rpm | Install a local RPM file, resolving dependencies. |
sudo dnf remove htop | Uninstall a package. |
sudo dnf autoremove | Remove orphaned dependency packages. |
dnf search editor | Search package names and descriptions. |
dnf info nginx | Show details of one package. |
dnf list installed | List installed packages. |
dnf list available | List everything the repos offer. |
dnf provides */htop | Find which package provides a file or command. |
dnf repoquery --whatrequires curl | Show what depends on a package. |
dnf repolist | List configured repositories. |
dnf group list | List installable package groups. |
rpm -qa | List every installed package (low level). |
rpm -ql htop | List files owned by an installed package. |
rpm -qf /usr/bin/htop | Find which package owns a file. |