Chapter 6: rpm and dnf — Fedora and RHEL-Based Systems


If you use Fedora, Red Hat Enterprise Linux (RHEL), CentOS Stream, AlmaLinux, or Rocky Linux, your native package format is .rpm and your package manager is dnf. The concepts are identical to apt and .deb — repositories, package databases, dependency resolution — but the commands and ecosystem differ.


The Red Hat Family

Distribution Notes
Fedora Community distro, cutting-edge packages, upstream for RHEL
RHEL Enterprise, paid support from Red Hat
CentOS Stream Rolling preview of upcoming RHEL
AlmaLinux Free RHEL rebuild, community-maintained
Rocky Linux Free RHEL rebuild, community-maintained

All of these use .rpm packages and dnf (or yum on older systems).


Essential dnf Commands

Installing and removing

sudo dnf install package-name          # install a package
sudo dnf install package1 package2     # install multiple
sudo dnf remove package-name           # uninstall a package
sudo dnf autoremove                    # remove unused dependencies

Upgrading

sudo dnf upgrade                       # upgrade all packages
sudo dnf upgrade package-name          # upgrade a specific package

Searching and inspecting

dnf search keyword                     # search package names and descriptions
dnf info package-name                  # show package details
dnf list installed                     # list all installed packages
dnf list installed | grep name         # filter by name
dnf repolist                           # list configured repositories

Installing a .rpm File

When a developer distributes a .rpm file directly (e.g., VS Code, Chrome), use dnf install rather than rpm -idnf resolves dependencies automatically:

sudo dnf install ./package.rpm

The ./ prefix tells dnf to treat the argument as a local file.

If you use rpm -i directly and hit dependency errors, resolve them with:

sudo dnf -f install

Third-Party Repositories: RPM Fusion

The official Fedora repositories exclude software with patent or licensing issues (codecs, proprietary drivers). RPM Fusion provides these:

# Add RPM Fusion free and non-free repos
sudo dnf install \
  https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm \
  https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm

# Then install media codecs
sudo dnf install gstreamer1-plugins-{bad-\*,good-\*,base} gstreamer1-plugin-openh264

Querying the RPM Database

The low-level rpm tool is useful for querying what is installed:

rpm -qa                                # list all installed RPM packages
rpm -qa | grep python                  # filter by name
rpm -ql package-name                   # list files installed by a package
rpm -qf /usr/bin/python3               # which package owns a file
rpm -qi package-name                   # show package info (version, description)

dnf vs apt: Quick Reference

Task apt (Debian/Ubuntu) dnf (Fedora/RHEL)
Update package index apt update dnf check-update
Upgrade all packages apt upgrade dnf upgrade
Install a package apt install pkg dnf install pkg
Remove a package apt remove pkg dnf remove pkg
Search packages apt search kw dnf search kw
Show package info apt show pkg dnf info pkg
List installed apt list --installed dnf list installed
Install local .deb/.rpm apt install ./file.deb dnf install ./file.rpm
Find package owning file dpkg -S /path rpm -qf /path
Remove unused deps apt autoremove dnf autoremove

dnf Plugins and History

dnf keeps a history of all transactions:

dnf history                            # list all past transactions
dnf history info 5                     # details of transaction #5
sudo dnf history undo 5                # undo transaction #5

This makes it easy to roll back an accidental install or upgrade.


Key Takeaways


← Chapter 5: AppImage Table of Contents Chapter 7: File Compression →