Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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.
  • yum and dnf are one skill — on any system where both exist, yum install X is literally dnf install X.

dnf is 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:

CommandRoleUse it for
dnfThe modern managerEverything, on Fedora and modern RHEL
yumCompatibility aliasOld scripts and muscle memory; same job as dnf
rpmThe low-level toolQuerying 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 yum on old RHEL for new features. yum cannot install modular packages or handle some modern repo syntax; on RHEL 8+ prefer dnf, and on RHEL 7 remember yum is the only option.
  • Forgetting the ./ for local files. dnf install file.rpm searches the repos; dnf install ./file.rpm installs the file. The dot is the whole difference.
  • Skipping autoremove. Repeated install/remove cycles orphan dependency packages that dnf list installed will 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-update exits 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; dnf will refuse rather than half-do the work.

PageWhy it is here
Package ManagementThe concept section — packages, repos, and why managers exist.
aptThe same job on Debian and Ubuntu.
pacmanThe same job on Arch Linux.
snapCross-distro packages that can coexist with dnf.
flatpakDesktop apps delivered independently of the system repos.
sudoWhy most of these commands need it.

dnf Cheatsheet

CommandWhat it does
sudo dnf check-updateList upgradable packages (exit 100 = updates available).
sudo dnf upgradeUpgrade every installed package.
sudo dnf upgrade htopUpgrade one package.
sudo dnf install htopInstall a package (and its dependencies).
sudo dnf install -y git curlInstall several packages without asking.
sudo dnf install ./file.rpmInstall a local RPM file, resolving dependencies.
sudo dnf remove htopUninstall a package.
sudo dnf autoremoveRemove orphaned dependency packages.
dnf search editorSearch package names and descriptions.
dnf info nginxShow details of one package.
dnf list installedList installed packages.
dnf list availableList everything the repos offer.
dnf provides */htopFind which package provides a file or command.
dnf repoquery --whatrequires curlShow what depends on a package.
dnf repolistList configured repositories.
dnf group listList installable package groups.
rpm -qaList every installed package (low level).
rpm -ql htopList files owned by an installed package.
rpm -qf /usr/bin/htopFind which package owns a file.