An RHCSA-Based Overview of the GNU/Linux dnf Command

Executive Summary

I wrote this new article as a comprehensive, RHCSA-based guide to the GNU/Linux dnf command, the modern and robust package manager for the RHEL ecosystem. It establishes that proficiency with dnf is a critical skill for any system administrator working with distributions like RHEL, Rocky Linux, or Fedora. As the successor to yum, dnf provides a faster, more reliable, and feature-rich experience for installing, updating, and managing software. This guide is designed for professionals at all levels, providing the necessary knowledge to manage software packages, handle dependencies, and prepare for industry certifications. It explains the core concepts of repositories and transactions and how dnf offers a superior framework for system maintenance compared to its predecessor.

This article follows a logical progression from theory to practical application. It begins by detailing the history of dnf, outlining the evolution from yum and the technical advantages that led to its adoption. It then explains the core concept of software repositories, which are the foundation of package management. The core of the article provides a detailed walkthrough of essential dnf commands, covering daily package operations (install, remove, upgrade), advanced querying (search, info, provides), and powerful features like history and transaction management. The instruction is reinforced with a collection of common command examples and culminates in a complete, real-world scenario of setting up a development environment on a Rocky 9 system.

Ultimately, we conclude that mastering dnf is a non-negotiable requirement for effective Linux administration. The commands and concepts presented empower administrators to manage a system's software lifecycle with confidence and efficiency. By synthesizing historical context with practical, hands-on examples, this guide provides readers with a solid foundation to manage any modern RHEL-based system, highlighting this skillset as critical for both professional competence and certification success.

Keywords: dnf, yum, Linux, GNU/Linux, RHCSA, RHEL, Rocky Linux, package management, system administration, sysadmin, Linux commands, repository, rpm, tutorial, guide

```
Glossary of Terms

├─ Package Managers
│  ├─ dnf: (Dandified YUM) The modern, default package manager for RHEL-family systems.
│  ├─ yum: (Yellowdog Updater, Modified) The legacy package manager replaced by dnf.
│  └─ rpm: (RPM Package Manager) The base system for managing individual software packages.

├─ Core Concepts
│  ├─ Repository: A centralized server that stores software packages and metadata.
│  ├─ Dependencies: Software required by another package to function correctly.
│  ├─ Transaction: A single recorded dnf action (e.g., install, remove) with a unique ID.
│  ├─ Metadata: Information about packages in a repository (versions, dependencies, etc.).
│  └─ Package Group: A collection of related packages that can be managed as a single unit.

├─ Related Technologies
│  └─ libsolv: The fast dependency-solving library that powers dnf.

└─ Abbreviations
   ├─ RHCSA: Red Hat Certified System Administrator.
   ├─ RHEL: Red Hat Enterprise Linux.
   ├─ API: Application Programming Interface.
   └─ GPG: (GNU Privacy Guard) Used for cryptographic package signing (gpgcheck).
```

A. Introduction

Effective management of software packages is a foundational skill for any system administrator. In the modern RHEL (Red Hat Enterprise Linux) ecosystem, this task is primarily handled by the dnf command, the command-line interface for software package management. dnf provides a unified and powerful framework for installing, updating, and removing software, automatically handling complex dependencies to ensure system stability.

As the default package manager on nearly all modern RHEL-family distributions, including RHEL 8+, Fedora, and Rocky Linux, dnf has replaced its well-known predecessor, yum. Consequently, proficiency with dnf is a critical requirement for effective system administration. This guide is designed for both seasoned professionals and new users, particularly those preparing for the Red Hat Certified System Administrator (RHCSA) exam.

This article provides a comprehensive, RHCSA-based overview of the dnf command. It begins with the history of dnf's evolution, followed by an explanation of core concepts such as repositories. The guide then covers essential commands for package management, querying the package database, and using advanced features like history and rollback. The instruction is reinforced with numerous practical examples, tested on a Rocky 9 system, and a complete, real-world scenario to build proficiency in using dnf in a production environment.

B. History of dnf: The Evolution from yum

To understand the importance of dnf, one must first understand the tool it replaced: YUM (Yellowdog Updater, Modified). For years, YUM was the standard for package management on RHEL-based systems. It was a significant improvement over managing individual RPM (RPM Package Manager) files directly, as it introduced the crucial ability to automatically resolve and install software dependencies from configured repositories. This meant an administrator could simply ask to install a web server, and YUM would figure out all the necessary libraries and tools that the web server needed to function.

While revolutionary, YUM began to show its age. Its dependency resolution algorithm could be slow and consume large amounts of memory, especially on systems with many repositories or complex package requirements. In certain situations, it could get stuck in an unresolvable "dependency hell." The underlying code was also difficult to maintain and extend with a clean API for other applications to use.

In 2015, DNF (Dandified YUM) was introduced as the modern replacement, debuting as the default in Fedora 22 and later in RHEL 8. While it maintains command-line compatibility with YUM for a smooth transition, dnf is a complete rewrite under the hood. It was designed to overcome YUM's limitations by leveraging a state-of-the-art dependency solver called libsolv. This makes dnf significantly faster, less memory-intensive, and more reliable at resolving complex dependency graphs. It also provides a stable, well-documented API, making it a better platform for other software management tools (like graphical installers) to build upon. Today, dnf stands as the essential and universal command-line interface for package management on all modern RHEL-based systems.

C. Understanding Repositories

At the core of dnf is the concept of a repository. A repository is a centralized storage server that holds a collection of RPM software packages and the critical metadata that describes them. This metadata, which dnf downloads and caches locally, acts like a catalog. It tells your system what packages are available, which versions exist, and, most importantly, the dependencies required by each package.

Essentially, when you ask dnf to install a package, it doesn't just look on your local disk. It consults its cached metadata from all configured repositories to build a complete dependency tree and then downloads the required RPM files from the appropriate server URLs.

These repositories are defined in simple text files ending in .repo, located in the /etc/yum.repos.d/ directory. A typical .repo file contains entries for one or more repositories, each with key information:

  • [repository_id]: A unique name for the repository.
  • name: A human-readable description.
  • baseurl: The URL pointing to the location of the packages.
  • enabled: Set to 1 (on) or 0 (off).
  • gpgcheck: Set to 1 to enable cryptographic signature verification, ensuring the packages are authentic and have not been tampered with.

By managing the files in /etc/yum.repos.d/, a system administrator has complete control over which software sources their system trusts and uses.

D. Managing Packages: The Daily Basics

With a solid understanding of repositories, we can now move to the practical, everyday commands used to manage the software on your system. These are the foundational operations you will perform countless times as a system administrator. For the following examples, we will use the Nginx web server (nginx) as our target package.

Installing Packages

To install a new piece of software, use the dnf install command. dnf will automatically resolve and install all required dependencies.
[root@rocky9 ~]# dnf install nginx

During the process, dnf will present a summary of the packages to be installed and ask for confirmation. To automatically answer "yes" to this prompt, you can add the -y flag.
[root@rocky9 ~]# dnf install nginx -y

Removing Packages

To uninstall a package and its dependencies that are no longer needed, use the dnf remove command.
[root@rocky9 ~]# dnf remove nginx -y

Updating Packages

Keeping system software up-to-date is crucial for security and stability. To upgrade a single package to the latest available version, specify its name.
[root@rocky9 ~]# dnf upgrade nginx -y

To upgrade all installed packages on the entire system, run the command without any package names.
[root@rocky9 ~]# dnf upgrade -y

Note: The command dnf update is also available and is largely identical to dnf upgrade. The latter is officially preferred as it handles package obsoletes correctly.

E. Querying and Inspecting Packages

Beyond just managing software, a key task is finding and learning about packages. dnf provides a powerful set of tools to search repositories and inspect packages, whether they are installed or not.

Searching for Packages

If you don't know the exact name of a package, you can use dnf search to find packages based on a keyword in their name or description.
[root@rocky9 ~]# dnf search "web server"

Getting Package Information

To get detailed information about a package, such as its version, architecture, size, and a full description, use the dnf info command. This works for both installed and available packages.
[root@rocky9 ~]# dnf info bash

Listing Packages

dnf can list packages in various ways. To see every package currently installed on your system, use dnf list installed.
[root@rocky9 ~]# dnf list installed

To see every package available to be installed from all your enabled repositories, use dnf list available.
[root@rocky9 ~]# dnf list available

Finding Which Package Provides a File

Sometimes you know the name of a file or command but not which package it belongs to. The dnf provides (or whatprovides) command can identify the source package.
[root@rocky9 ~]# dnf provides /usr/sbin/nginx

F. Managing Repositories and Groups

While daily package management is crucial, administrators also need to manage their software sources (repositories) and handle large collections of related packages (groups).

Listing Repositories

To see a list of all repositories your system is configured to use, run the dnf repolist command. This will show the ID and name for each enabled repository.
[root@rocky9 ~]# dnf repolist

To see all repositories, including disabled ones, add the --all flag.

Using Specific Repositories

For a single transaction, you can temporarily enable or disable a repository from the command line without permanently editing its .repo file. This is done with the --enablerepo and --disablerepo flags.
[root@rocky9 ~]# dnf --enablerepo=epel install my-cool-package

Working with Package Groups

Repositories often organize packages into "groups" to simplify the installation of software with a common purpose. For example, instead of installing dozens of development packages one by one, you can install the "Development Tools" group.

  • dnf group list: Shows all available package groups.
  • dnf group info "Group Name": Displays the packages included in a group.
  • dnf group install "Group Name": Installs all packages in the group.

G. Viewing History and Undoing Transactions

One of the most powerful features of dnf is its detailed transaction history. Every time you install, remove, or upgrade packages, dnf records it as a transaction with a unique ID. This creates an audit trail and even allows you to undo or redo actions.

Viewing History

To see a list of all recent transactions, use the dnf history command.
[root@rocky9 ~]# dnf history


ID | Command line             | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
 5 | install nginx            | 2025-10-07 07:20 | Install        |    8 EE
 4 | upgrade                  | 2025-10-06 15:30 | I, U           |   12
 3 | remove htop              | 2025-10-06 11:15 | Erase          |    1

Inspecting and Undoing Transactions

You can get more details about a specific transaction with dnf history info <ID>.
[root@rocky9 ~]# dnf history info 5

Most importantly, you can revert a transaction with dnf history undo <ID>. For example, running dnf history undo 5 would execute the necessary steps to remove Nginx and its dependencies, returning the system to the state it was in before transaction 5 occurred. This is an incredibly powerful tool for recovering from a bad package installation.

H. dnf in Action: Common Examples

Now that we've covered the core concepts, let's explore other practical examples that demonstrate the versatility of dnf.

Cleaning the Cache

dnf stores repository metadata and downloaded packages in a local cache. To clear this out and force dnf to download fresh information, use dnf clean all.
[root@rocky9 ~]# dnf clean all

Checking for Updates

To see a list of all available updates without actually applying them, use dnf check-update.
[root@rocky9 ~]# dnf check-update

Downgrading a Package

If a package update causes problems, you can revert it to a previously installed version with dnf downgrade.
[root@rocky9 ~]# dnf downgrade <package_name>

Reinstalling a Package

If you suspect a package's files have become corrupted, you can reinstall it to restore the original files with dnf reinstall.
[root@rocky9 ~]# dnf reinstall <package_name>

I. Putting It All Together: A Practical Scenario

Theory and individual commands are essential, but the true test of understanding comes from applying that knowledge to a real-world task. In this section, we will walk through a complete scenario: setting up a server with the necessary tools to compile software from source code.

Step 1: Search for the Right Group

We know we need compilers and related tools like make and gcc, but we aren't sure of all the package names. This is a perfect use case for package groups. Let's search for a relevant group.
[root@rocky9 ~]# dnf group list

In the output, we see a group named "Development Tools." This sounds exactly like what we need.

Step 2: Install the Package Group

Now we can install the entire group with a single command.
[root@rocky9 ~]# dnf group install "Development Tools" -y

dnf will now resolve and install all the packages associated with that group, which can include dozens of individual RPMs.

Step 3: Verify the Installation

After the installation completes, we should verify our work. We can check that key tools are now present. For example, we can use the rpm command to query if the gcc compiler was installed.
[root@rocky9 ~]# rpm -q gcc
gcc-11.3.1-4.el9_2.x86_64

The output confirms that the gcc package is now installed on the system.

Step 4: Check the History

Finally, let's look at the transaction history to see the record of our action.
[root@rocky9 ~]# dnf history

We will see a new entry for our group install command, showing exactly when it was run and how many packages were added. We have now successfully used dnf's group functionality to configure our system for software development.

J. Conclusions

Throughout this guide, we have journeyed from the historical context of dnf's creation to the practical, hands-on commands that form the core of modern package management. We have seen how to install, remove, and update software, and how to query the vast library of available packages with precision. By exploring repositories, we learned how to manage our software sources, and with transaction history, we unlocked the ability to audit and even revert changes to the system.

The dnf command is far more than a simple replacement for yum; it is the cornerstone of a stable, secure, and well-maintained system. It provides a fast and powerful framework that has become an essential skill for anyone working with modern GNU/Linux distributions in the RHEL family. A thorough grasp of these tools is not only a fundamental requirement for certifications like the RHCSA but is also a prerequisite for competent and confident system administration in any professional environment.

With the foundational knowledge and practical examples presented here, you are now well-equipped to manage software on any dnf-based system. The next steps in your learning journey could involve creating your own custom repositories, working with dnf modules, or exploring the DNF Automatic tool for scheduled updates. The package management ecosystem is vast, but mastering the dnf command is the most critical step, and one you have now successfully taken.

```
An RHCSA-Based Overview of the GNU/Linux dnf Command

├─ A. Introduction
│  ├─ Role of dnf & Package Management
│  ├─ Importance for RHCSA
│  └─ Article Roadmap

├─ B. History: The Evolution from yum
│  ├─ Legacy System: YUM
│  │  └─ Limitations (Slow, dependency hell)
│  └─ Modern System: DNF
│     └─ Key Features (Faster, libsolv solver)

├─ C. Understanding Repositories
│  ├─ Definition (Centralized software storage)
│  ├─ Role of Metadata
│  └─ Configuration (.repo files)

├─ D. Managing Packages: The Daily Basics
│  ├─ Installing Packages (install)
│  ├─ Removing Packages (remove)
│  └─ Updating Packages (upgrade)

├─ E. Querying and Inspecting Packages
│  ├─ Searching for Packages (search)
│  ├─ Getting Package Info (info)
│  ├─ Listing Packages (list)
│  └─ Finding Providers of Files (provides)

├─ F. Managing Repositories and Groups
│  ├─ Listing Repositories (repolist)
│  ├─ Using Specific Repos (--enablerepo)
│  └─ Working with Package Groups (group install)

├─ G. Viewing History and Undoing Transactions
│  ├─ Viewing History (history)
│  ├─ Inspecting a Transaction (history info)
│  └─ Undoing a Transaction (history undo)

├─ H. dnf in Action: Common Examples
│  ├─ Cleaning Cache (clean all)
│  ├─ Checking for Updates (check-update)
│  ├─ Downgrading a Package (downgrade)
│  └─ Reinstalling a Package (reinstall)

├─ I. A Practical Scenario: Setup Development Tools
│  ├─ Step 1: Search for Group (group list)
│  ├─ Step 2: Install Group (group install)
│  ├─ Step 3: Verify Installation (rpm -q)
│  └─ Step 4: Check History (history)

└─ J. Conclusions
   ├─ Summary of Key Learnings
   ├─ Reiteration of Importance
   └─ Encouragement for Further Learning
```

 

You should also read: