How to use DNF Software Package Manager with Examples

The dandified yum (DNF) command is the next-generation version of the YUM package manager for Fedora, CentOS, AlmaLinux, and other RHEL-based distributions.

This command was first implemented after the Fedora 22, CentOS 8, and RHEL 8 release. The launch was to remove the bottleneck involved in the YUM command.

DNF supports various extensions, but YUM is limited to Python extensions. It also provides extra support for multiple repositories, package group support, less memory consumption, a well-documented API, backend support for YUM, and many more.

Check Update

You can run dnf check-update command to check if the update is available with your enabled repositories for the packages you have installed in your system. This command does not update the packages; it simply gives you a list of packages that have an update for installation.

$ dnf check-update

Upgrade Packages

System and manually installed packages can be easily upgraded to their newest version using the following command.

$ sudo dnf upgrade

This also includes the latest security patches and fixes to improve the security of your system.

Searching Packages

The DNF command is precisely like YUM to search for packages from the repositories. It can be operated as dnf search package-name, replacing the package-name with the actual package name, as shown below.

$ dnf search httpd

Do not be overwhelmed if a long list of related httpd commands is found. This is another advantage of using DNF search. If you do not know the package’s name, search for it using relative terms (example: webserver).

Package Information

Once, you find the desired package using the dnf search command. You can use the dnf info command with package name to learn about the package information and other valuable data such as version, release, size, source, repository, URL, license, and description.

$ dnf info httpd

Install Packages

Once you are satisfied with the information provided by the dnf info command and ready to install, then execute sudo dnf package-name, replacing the package-name with the actual package name, as shown below.

$ sudo dnf install httpd

Running the above command without an option may ask for yes and no when required. Execute the below command to apply for “yes” for all questions.

$ sudo dnf install httpd -y

If you face any problems after the package installation, you can easily reinstall the package using the below command.

$ sudo dnf reinstall httpd

If you have a locally downloaded “.rpm” package, then you can easily install it by specifying “./” with the package name, as shown below.

$ sudo dnf install ./httpd-2.4.53-1.fc36.x86_64.rpm 

Installation of packages lists essential information, such as the dependencies that will be installed. If you want to hide them, use the -q option to enable quiet mode, as shown below.

$ sudo dnf install httpd -q

If you want to list some extra details of the packages, you can enable the verbose mode using the -v option, as shown below.

$ sudo dnf install httpd -v

Remove Packages

Oops, accidentally installed the httpd package while learning the dnf command? Then let me tell you how to remove it. First, execute the sudo dnf remove package-name command by replacing package-name with your package (example: httpd), as shown below.

$ sudo dnf remove httpd

Once the package is removed, execute the below command to remove the dependencies installed at the package installation time.

$ sudo dnf autoremove

Download Packages

Rather than installing the packages from the sudo dnf install command, you can easily download a package and share it with other systems having the same architecture or install it later on your system without re-downloading.

$ sudo dnf download httpd

The downloaded package extension will be “.rpm” and can be used for installation in other RHEL-based distributions.

List of Installed Packages

Do you have more packages to remove? No worry, you can easily find the list of all packages installed on your system using the below command.

$ dnf list --installed

Find Packages

Have you ever wanted to execute a command but you are not sure which package is required? This is where the dnf provides command comes into use.

It will find the name of the package that provide specific file or sub-packages. For example, I would like to find what provides /etc/hosts, which can be followed as:

$ sudo dnf provides /etc/hosts

View Repository Information

By default, we have a number of the enabled repositories in our system located at the “/etc/yum.repos.d” used while the dnf command is executed. Execute the below command to list all the enabled repositories on your system.

$ dnf repolist                       # List enabled repositories names
$ dnf repoinfo                       # List details information of enabled repositories

By default, the dnf repolist command only lists the enabled repositories. Add all at the end to list the disabled repositories with enabled.

$ dnf repolist all

Adding Repository

Most of the requirements can be easily fulfilled with the default enabled repository. Still, if some packages are not found in the default repository, you can easily add that packages repository.

There are multiple ways to add a package repository by creating a new repository with the extension “.repo” at “/etc/yum.repos.d” or using the dnf config-manager (recommended) command.

$ dnf config-manager --add-repo

Enable/Disable Repository

Enabling the repository can be done quickly using the same dnf config-manager command as follows.

$ dnf config-manager --set-enabled repository…

Execute the below command to disable the enabled repository on your system.

$ dnf config-manager --set-disabled repository…

View Transactions History

The dnf history command lists all the actions performed by the dnf command. This lets you know what happened to your system, and you can even undo, redo, or roll back to different actions.

$ dnf history

The above command lists the action performed by dnf command with the ID. You can use the ID to find the changes made by that command in your system.

$ dnf history info 6

Once you find the changes made by that command and want to undo the changes, execute the below command.

$ dnf history undo 6

Oops, accidentally undo the essential package and want to redo it again. Execute the below command.

$ dnf history redo 6

List all Group Packages

Packages that are related to each other can be grouped together into a package group. For example, you will have “Server” group that groups all the packages related to the server, such as Basic Web Server, DNS Name Server, FTP Server, etc.

Furthermore, “Basic Web Server” holds the packages related to a web server such as httpd. Execute the below command to find the list of available grouped packages on your system.

$ dnf grouplist

The best thing about grouping related packages is that you can easily install, remove, or update all the packages in the group by defining the group name.

Install a Group Package

If you do not have a “Server” group, then you can install it using the below command.

$ sudo dnf groupinstall "Server"

Update a Group Package

Let’s assume the “Server” group package was already in your system, but the packages within the group are outdated. You can execute the below command to update all the packages within the “Server” group.

$ sudo dnf groupupdate "Server"

Remove a Group Package

If you do not want the “Server” group package anymore, use the below command to remove it from your system.

$ sudo dnf groupremove "Server"

Clear Cached Data

By default, dnf caches data at the /var/cache/dnf directory. This includes package and repository data. This makes the process faster when you execute the dnf command without letting you fetch data from the internet.

But sometimes, your cache might consist of the stale version of a package, requiring cache cleaning, which can be done using the below command.

$ dnf clean all

The above command removes all the cache from your system created by dnf command. If you want to remove a specific cache, such as packages, metadata, expire-cache, rpmdb or plugins. Specify them in a place of all, I recommended executing this command only if it is necessary.

Downgrade Packages

The first step of downgrading a package will be to know all the available releases of that specific package. Execute the below command to view all versions of a package in your enabled repositories.

$ dnf --showduplicates list httpd

After knowing all the available versions, if you want to step one version down, execute the below command.

$ sudo dnf downgrade httpd

You can even install a package by defining the specific name version, as shown below.

$ sudo dnf install httpd-2.4.53

Excluding Packages From Transactions

There will be cases where it is good to exclude the app from upgrading. It might be a malfunction or bug in the latest release.

To avoid upgrading, specify the package name with the --exclude option, as shown below.

$ sudo dnf upgrade --exclude=httpd    # Replace httpd with the package name you want to exclude

You can also add this package to /etc/dnf/dnf.conf to exclude it from being upgraded.

exclude=httpd                 # Replace httpd with the package name you want to exclude


The core functionality of the dnf command can be extended more by installing the plugin. There are official supported Core DNF plugins and also third-party Extra DNF plugins.

To install them, use the below command with the plugin name.

$ sudo dnf install dnf-plugins-core-PLUGIN_NAME

Wrap Up

All the essential topics to know while using the dnf command have been explained in this article. If something is left, let us know in the comment section.

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments