Mastering DNF: A Comprehensive Guide to the Dandified YUM Package Manager in Linux

According to DNF’s GitHub profile

“Dandified YUM (DNF) is the next upcoming major version of YUM. It does package management using RPM, libsolv and hawkey libraries. For metadata handling and package downloads, it uses librepo. To process and effectively handle the comps data it uses libcomps.”

In short, it is a YUM-based package manager that is used on RHEL and family distributions such as Fedora, Alma Linux, Rocky Linux, Oracle Linux and CentOS.

DNF makes it easy to maintain packages by automatically checking for dependencies and determines the actions required to install packages. This method eliminates the need to manually install or update the package, and its dependencies, using the rpm command. DNF is now the default software package management tool in Fedora.

Compared to other package managers, DNF has better memory utilization, improved dependency management and the ability to run Python 2 and Python 3. It is therefore considered one of the fastest and most complete package managers in all of Linux.

DNF officially debuted with Fedora 18, but quickly spread to other members of the RHEL-based distributions. And now it is the package manager for Fedora, RHEL, CentOS, and others.

Now, how to use it? Well, I’ll explain it to you.

Basic use of DNF on Linux

DNF solves all the problems associated with yum, such as low performance, high memory usage, slow dependency resolution. But it retains much of its syntax, so the transition is effortless to make.

The first thing to do is to open a terminal to use DNF. Remember that DNF is present by default in RHEL, Oracle Linux, Fedora, Alma Linux, Rocky Linux and CentOS.

When you open the terminal, you can consult the DNF help by running

dnf help

There you will get a fairly comprehensive output screen explaining how to use it.

You can also use help to get information and help on a particular subcommand like install.

dnf help install

The slightly more refined output will tell you all the necessary information about install which as you may notice we will use to install packages.

Another command you can use is version to get the version of DNF you have

dnf --version

Sample Output

4.13.0
  Installed: dnf-0:4.13.0-1.fc36.noarch at Mon 29 Aug 2022 07:48:09 AM GMT
  Built    : Fedora Project at Mon 30 May 2022 09:55:23 AM GMT

  Installed: rpm-0:4.17.1-3.fc36.x86_64 at Mon 29 Aug 2022 07:47:49 AM GMT
  Built    : Fedora Project at Tue 02 Aug 2022 12:31:56 PM GMT

With these first commands, you can get an idea about how to use it.

Package management using DNF (I)

Note: For package management, DNF requires root permissions. That is, you will probably have to use sudo.

Now comes the most important part, and it is related to package management with DNF.

The first thing we usually do is to look for packages inside the official repositories that are enabled on the system. To achieve this, just follow this syntax.

dnf search [package]

In [package] you can type a search criteria that allows you to identify possible packages.

dnf search vim

You will get an output similar to this

Last metadata expiration check: 0:00:34 ago on Thu 27 Oct 2022 12:03:45 AM UTC.
====================================================================== Name & Summary Matched: vim ======================================================================
awesome-vim-colorschemes.noarch : Collection of color schemes for Neo/vim, merged for quick use
beakerlib-vim-syntax.noarch : Files for syntax highlighting BeakerLib tests in VIM editor
boxes-vim.noarch : Vim plugin for boxes
espeak-ng-vim.noarch : Vim syntax highlighting for espeak-ng data files
fluxbox-vim-syntax.noarch : Fluxbox syntax scripts for vim
gap-vim.noarch : Edit GAP files with VIM
geany-plugins-vimode.x86_64 : Vim-mode plugin for Geany
neovim.x86_64 : Vim-fork focused on extensibility and agility
neovim-ale.noarch : Asynchronous NeoVim Lint Engine
neovim-qt.x86_64 : Qt GUI for Neovim
notmuch-vim.x86_64 : A Vim plugin for notmuch

If you already know the exact name of a package, you can also get information about it with the following command:

dnf info [package-name]

For example:

dnf info wget

Since vim is the name of the package, then the on-screen output will tell you valuable information about this package.

Last metadata expiration check: 0:00:36 ago on Thu 27 Oct 2022 12:06:38 AM UTC.
Installed Packages
Name         : wget
Version      : 1.21.3
Release      : 1.fc36
Architecture : x86_64
Size         : 3.2 M
Source       : wget-1.21.3-1.fc36.src.rpm
Repository   : @System
From repo    : fedora
Summary      : A utility for retrieving files using the HTTP or FTP protocols
URL          : http://www.gnu.org/software/wget/
License      : GPLv3+
Description  : GNU Wget is a file retrieval utility which can use either the HTTP or
             : FTP protocols. Wget features include the ability to work in the
             : background while you are logged out, recursive retrieval of
             : directories, file name wildcard matching, remote file timestamp
             : storage and comparison, use of Rest with FTP servers and Range with
             : HTTP servers to retrieve files over slow or unstable connections,
             : support for Proxy servers, and configurability.

Similarly, you can specify several packages at the same time.

dnf info vim nano wget

You will get a sorted output screen with information about each package.

Then with the information already specified, you can install a package by executing the following command

dnf install [package]

Automatically, dnf will calculate the dependencies, and you will be presented with a summary of the changes to be made. To confirm the installation, just press the y key, and it will start.

Similarly, you can specify several packages at once

dnf install vim nano wget

It will automatically resolve the dependencies and start the process.

Another command that is widely used by dnf is to remove packages. The syntax is quite similar to install but is changed to remove.

dnf remove [package]

For example,

dnf remove nano

Similarly, you can specify many packages at the same time.

dnf remove nano wget tar

Package management using DNF (II)

To update a package, then the update command is used. If you specify one or several packages, then you will update them.

dnf update nano

The above command will update nano if there is a newer package in the official repositories.

You can also specify two packages simultaneously

dnf update nano wget tar

But if you want to upgrade all the installed packages, then run

dnf upgrade

On servers and workstations, it is sometimes convenient to upgrade only the most essential parts of the system to have the security patches. This can be accomplished with the command.

sudo dnf upgrade --security

Another interesting option is to check the updates that the system requires. In this case, you can run.

dnf check-update

DNF will then check with the official system repositories and present you with a summary of available system-wide updates.

It is common in enterprise environments for many sysadmin to download packages for installation on another computer. This can be done with the download command.

dnf download [package-name]

For example:

dnf download nano wget

In this way, the packages will be downloaded but

Package group management

One of the main features of RHEL-based distributions is that their official repositories group their packages into groups to make them easier to manage and use.

First, you need to know which package groups are in the system. To achieve this, run.

dnf group list

Sample output:

Last metadata expiration check: 0:01:12 ago on Thu 27 Oct 2022 12:06:38 AM UTC.
Available Environment Groups:
   Fedora Custom Operating System
   Minimal Install
   Fedora Server Edition
   Fedora Workstation
   Fedora Cloud Server
.
.
Available Groups:
   3D Printing
   Administration Tools
   Audio Production
   Authoring and Publishing
   C Development Tools and Libraries
   Cloud Infrastructure
   Cloud Management Tools
   Compiz

This way, you will be able to know all the available package groups.

You will also be able to display information about one of these groups:

dnf group info "Server"

This way, you will be able to know which packages constitute that group. You can replace Server with the name of another group.

And to install a package group, you can run

dnf group install [package-group-name]

For example:

dnf group install "Server"

So, after the dependency calculation, the installation process will start.

The reverse process, i.e., removing a package-group, can be done by running

dnf group remove [package-group-name]

For example:

dnf group remove "Server"

Repository management with DNF on Linux

As you know, the distribution of packages on Linux is done through repositories where the packages are hosted.

To find out which packages are enabled on the system, you have to run the following command

dnf repolist

Sample Output:

repo id                                                                    repo name
fedora                                                                     Fedora 36 - x86_64
fedora-cisco-openh264                                                      Fedora 36 openh264 (From Cisco) - x86_64
fedora-modular                                                             Fedora Modular 36 - x86_64
updates                                                                    Fedora 36 - x86_64 - Updates
updates-modular                                                            Fedora Modular 36 - x86_64 - Updates

This way you can quickly find out which repositories are enabled on the system.

Now, if you want to list all the repositories on the system including the disabled ones, run

dnf repolist all

If you would like to add a repository, you have to run

dnf config-manager --add-repo [repository-url]

By default, many added repositories are not hailed by the system for security reasons. So, after adding them, you may have to enable it.

dnf config-manager --set-enabled [repository]

The reverse process would be something like this:

dnf config-manager --set-disabled [repository]

Advanced package management using DNF

Installing, uninstalling and upgrading packages along with their dependencies are basic operations that any package manager should do, but it is always possible to interact in a more advanced way with it to get wonderful results.

An important feature of DNF is that it allows you to search for a package by a file that contains it. The provides command is a great way to do this.

dnf provides [file-name]

For example,

dnf provides named

This will show all packages containing that file name. Usually, there should only be a few or even one result.

There are certain applications that are distributed on the Internet as RPM packages. So, you download this package and what proceeds is a local installation of the package. To achieve this, you can run.

dnf install [package-name].rpm

Remember that the package has to be in the same directory as the prompt.

Typically, this is the way to install applications like Code, Edge or Google Chrome.

If there is a problem with a package, you can reinstall it by just running

dnf reinstall [package-name]

If you want to synchronize the system with the official repositories, you can run

dnf distro-sync

This command will be able to upgrade or downgrade packages according to the information obtained from the repositories.

Using DNF to clean up packages and save disk space

Although the DNF cache is generated automatically over time, you can always create it manually. This is important for many configurations and for tracking packages installed on the hard disk.

To achieve this, you can run the following command

sudo time dnf makecache

Now, it is also possible to remove this and the other cache from the system. The purpose of this is to remove packages that have already been installed and are taking up disk space.

To do this, run

sudo dnf clean all

Another way to save disk space is to remove orphaned packages from the system. These packages are dependencies of other packages that have already been removed. Therefore, they are no longer useful.

It is effortless to do this with the following command

sudo dnf autoremove

Manage the usage history of DNF

DNF is so complete that it allows with the history subcommand to query the times it has been used to handle packages.

To achieve this, just run

dnf history

By default, the last 20 transactions made with dnf will be shown.

If you want more details about a particular transaction, then you can add info and the transaction ID to query. For example:

dnf history info 19

This way, there is a record of what dnf has done on the system.

There is also the possibility to revert the changes made by this transaction. This is ideal if you detect inappropriate behavior as a result of an update or a package uninstallation.

To achieve this, you just need to know the ID of the DNF transaction and revert it like this

dnf history undo [id]

Or redo it otherwise.

dnf history redo [id]

Conclusion

Package managers make Linux a usable system. Of all the ones out there, DNF is emerging as one of the best for its speed, efficiency, and number of different options to manage the system smoothly.

I hope this complete guide will help you understand DNF. I hope you liked it and share it with your friends.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top