26 DNF Command Examples in Fedora / CentOS / RHEL

DNF or Dandified YUM is a fork of YUM package manager. It was introduced in Fedora 18 & on Fedora 22. It has now become default package manager for handling the RPM packages on CentOS 8, RHEL 8 and Fedora.

DNF resolves all the problems that has been associated with yum, like poor performance, high memory usage, slowness for dependency resolution. DNF can be termed as the next major version of the YUM package manager. Currently, the most stable version of DNF is version 2.6.3

In this tutorial, we will discuss the DNF commands used for package management. This article will serve as a cheat sheet for DNF. So let’s start …..

DNF Command

The syntax for using DNF command is pretty similar to using YUM, so you will find lots of similarity between the two commands.

Example:1) List enabled repositories

To list all the enabled repositories on the system, run

[[email protected] ~]$ sudo dnf repolist
[sudo] password for linuxtechi:
repo id repo name status
*epel Extra Packages for Enterprise Linux 7 - x86_64 11,989
*fedora Fedora 26 - x86_64 53,912
*updates Fedora 26 - x86_64 - Updates 9,405
virtualbox Fedora 26 - x86_64 - VirtualBox 10
[linuxtec[email protected] ~]$

Example:2) List all repositories (enabled as well as disabled)

If we need to see all the repositories that are either enabled or disabled, we need to run following

[[email protected] ~]$ sudo dnf repolist all


Example:3) Installing a package

Like yum, we use ‘install‘ option followed by package name with dnf to install, Let’s suppose we want to install web server package (httpd)

[[email protected] ~]$ sudo dnf install httpd


Example:4) Removing a package

To remove a package, execute the following from terminal,

[[email protected] ~]$ sudo dnf remove httpd
[[email protected] ~]$ sudo dnf erase httpd

Output of above command would be something like below:


Example:5) Update a package

Run the following command to update a single package on the system,

Syntax: dnf update {pkg-name}

[[email protected] ~]$ sudo dnf update filezilla

Example:6) Check for full system update

For a system wide update check, execute the following command,

[[email protected] ~]$ sudo dnf check-update


Example:7) Upgrade all system packages

To upgrade all system packages, run the following

[[email protected] ~]$ sudo dnf upgrade


Example:8) List all group packages

Use the following to list all group packages

[[email protected] ~]$ sudo dnf grouplist
Last metadata expiration check: 1:40:19 ago on Tue 10 Oct 2017 10:08:39 AM IST.
Available Environment Groups:
   Fedora Custom Operating System
   Minimal Install
   Fedora Server Edition
   Fedora Workstation
   Fedora Cloud Server
   KDE Plasma Workspaces
   Xfce Desktop
   LXDE Desktop
   Hawaii Desktop
   LXQt Desktop
   Cinnamon Desktop
   MATE Desktop
   Sugar Desktop Environment
   Development and Creative Workstation
   Web Server
   Infrastructure Server
   Basic Desktop
Installed Groups:
Available Groups:
   3D Printing
   Administration Tools
   Ansible node
   Audio Production

Example:9) Installing Group packages

Similar packages are grouped together & can be installed from single command, rather than using separate commands. To install a group, run

[[email protected] ~]$ sudo dnf groupinstall "Development Tools"


Example:10) Removing group packages

To remove a complete group of packages from system, run the following dnf command,

Syntax:  dnf groupremove ‘group_name’

[[email protected] ~]$ sudo dnf groupremove "Development Tools"

We can also use ‘groupupdate’ for updating the group packages as well.

Example:11) Search for packages

To look for a particular package from the repositories, execute

Syntax: dnf search {package_name}

Let’s suppose I want to search net-tools package

[[email protected] ~]$ sudo dnf search net-tools
=========== Name Exactly Matched: net-tools =========
net-tools.x86_64 : Basic networking tools
[[email protected] ~]$

Example:12) Download (don’t not install) a package

There can some scenarios where we require to download the packages but don’t wish to install. Use the following command to download package like samba

Syntax : dnf download package_name

[[email protected] ~]$ sudo dnf download samba
samba-4.6.8-0.fc26.x86_64.rpm          139 kB/s | 636 kB     00:04
[[email protected] ~]$

Example:13) Show all available packages

To get list of all available packages from repositories, open terminal & run beneath dnf command

[[email protected] ~]$ dnf list available | more


Example:14) Show only installed packages

Now, if we only require a list of installed packages on the system, we can get it by executing following command,

[[email protected] ~]$ dnf list installed


Example:15) Show all installed as well as available packages

To get list of all packages i.e. installed as well as available, run the following command

[[email protected] ~]$ dnf list


Example:16) Enable repo for installation

To use a particular repository for installing a package, run

[[email protected] ~]$ sudo dnf install --enablerepo=epel mysql
Extra Packages for Enterprise Linux 7 - x86_64     3.9 MB/s |  13 MB  00:03
Dependencies resolved.
 Package               Arch      Version     Repository        Size
 mariadb                 x86_64      3:10.1.26-2.fc26    updates         6.4 M
Installing dependencies:
 mariadb-common          x86_64      3:10.1.26-2.fc26    updates         100 k
 mariadb-config          x86_64 3:10.1.26-2.fc26    updates         33 k
 mariadb-libs           x86_64      3:10.1.26-2.fc26    updates         663 k
Transaction Summary
Total download size: 7.2 M
Installed size: 44 M
Is this ok [y/N]: y

Example:17) Check which package provides the required function

If we wants to know which package is responsible for getting a particular functionality, like we need to know package name that is associated with ‘crontab’ or with some other command, than we can use the dnf command ‘provides‘ option in the following manner,

[[email protected] ~]$ sudo dnf provides crontab
cronie-1.5.1-5.fc26.x86_64 : Cron daemon for executing programs at set times
Repo        : @System
cronie-1.5.1-5.fc26.x86_64 : Cron daemon for executing programs at set times
Repo        : fedora
[[email protected] ~]$

Same can be done against a file, we can also use the same command with a file location to get the package name with which the file is associated,

[[email protected]]$ sudo dnf provides /var/www/html

Example:18) View package information

To get details of a specific package, execute

[[email protected] ~]$ dnf info cronie
Installed Packages
Name         : cronie
Version      : 1.5.1
Release      : 5.fc26
Arch         : x86_64
Size         : 236 k
Source       : cronie-1.5.1-5.fc26.src.rpm
Repo         : @System
From repo    : anaconda
Summary      : Cron daemon for executing programs at set times
URL          : https://fedorahosted.org/cronie
License      : MIT and BSD and ISC and GPLv2+
Description  : Cronie contains the standard UNIX daemon crond that runs /
specified programs at
             : scheduled times and related tools. It is a fork of the / original vixie-cron and
             : has security and configuration enhancements like the /
ability to use pam and
             : SELinux.
[[email protected] ~]$

Example:19) Building a cache

Though the cache is built automatically over time but we also have an option to manually build the cache, so that the future actions are fast & completed quickly. To create a cache manually, execute

[[email protected] ~]$ sudo time dnf makecache
Last metadata expiration check: 0:04:41 ago on Thu 12 Oct 2017 09:53:00 AM IST.
Metadata cache created.
0.86user 0.12system 0:01.04elapsed 95%CPU (0avgtext+0avgdata 106872maxresident)k
0inputs+1192outputs (0major+39606minor)pagefaults 0swaps
[[email protected] ~]$

Example:20) Delete a cache

To delete all the dnf cached data, execute the following commands

[[email protected] ~]$ sudo dnf clean all
34 files removed
[[email protected] ~]$

Example:21) Check the transaction history

To check all the transactions that have been done using DNF command, run the following commands

[[email protected] ~]$ sudo dnf history


It will produce a list of all transactions in order as they have occurred with a corresponding number. We can use this number to further get the details of that transaction,

[[email protected] ~]$ sudo dnf history info 5


Logs related to installation, removal or updates are kept in the log file /var/log/dnf.log, Using dnf history command we can also rollback the system updates.

Example:22) Removing orphan packages

Orphan packages are those packages that were once installed to satisfy dependency for some other package but are not required now. To remove such packages, run

[[email protected] ~]$ sudo dnf autoremove


Example:23) Synchronize all the packages to latest stable releases

Run the following command in order to synchronize all the packages to latest stable releases,

[[email protected] ~]$ sudo dnf distro-sync


If we need to sync only a single package, mention that package_name at the end otherwise all the packages will be synced.

Example:24) Reinstall a package

To reinstall a package, if need be, run the following command,

[[email protected] ~]$ sudo dnf reinstall postfix
Dependencies resolved.
 Package         Arch        Version            Repository      Size
 postfix         x86_64       2:3.2.2-1.fc26    fedora           1.4 M
Transaction Summary
Total download size: 1.4 M
Is this ok [y/N]: y

Example:25) Upgrade to a particular version

With DNF, its also possible to upgrade the rpm package to a particular version, to achieve this run the following command,

[[email protected] ~]$ sudo dnf upgrade-to httpd-2.4.27-3.fc26

Example:26) Get list of all DNF commands and options

To get a list of all the available options that can be used with DNF, run

[[email protected] ~]$ dnf help


This was our complete tutorial for DNF package manager with examples. Please do leave any queries or questions you have for this tutorial in the comments below.

Posted by WordPress Guru