DNF in Action - Package Management Everyday Tips

DNF in Action - Package Management Everyday Tips
Photo by Lukas / Unsplash

DNF — package manager in Red Hat Enterprise Linux, Centos, Fedora.
It's a very powerful and fast tool, and solid user experience can be very helpful for your everyday tasks, massive deployments or even certifications like RHCSA, RHCE, LPIC. RHEL is very popular in the enterprise world and de facto belongs to the industry standards.
DNF works with *.rpm-packages (Red Hat Package Manager). Yum, dnf's predecessor, is currently defined as legacy software.

For the beginning, just type in terminal

$ dnf

You can see a long list of basic commands.

Performance tips

# vi /etc/dnf/dnf.conf

# use a near mirror to your location

# increase packages download speed with parallelization (thanks, Reddit!)

Try to search a package

# dnf se blender
Last metadata expiration check: 0:00:27 ago on Thu Apr 14 10:29:11 2022.
============================ Name Exactly Matched: blender =======================
blender.x86_64 : 3D modeling, animation, rendering and post-production
============================= Name & Summary Matched: blender ======================
YafaRay-blender.x86_64 : Blender integration scripts for YafaRay
blender-luxcorerender.x86_64 : Blender export plugin to luxcorerender
blender-rpm-macros.noarch : RPM macros to build third-party blender addons packages

It works! Here we're using se as the shortcut to search.

Now let's run a global search in all packages description

# dnf search all "C library"
============================== Matched: C library ==============================
libkcompactdisc.i686 : A KDE compact disc library
libkcompactdisc.x86_64 : A KDE compact disc library
lives-devel.i686 : headers for lives OSC library
lives-devel.x86_64 : headers for lives OSC library

Install or reinstall the package

# dnf install package1 package2
# dnf reinstall package1 package2

How to delete the package

# dnf erase package1 package2

Get more information about packages

# dnf info package1 package2

Often you know the name of a library and need to find out which package provides it. The next command will help:

# dnf provides "*/audioadapter.so"
jack-audio-connection-kit-1.9.10-2.x86_64 : The Jack Audio Connection Kit
Repo        : @System

To get the audioadapter.so library, we need to install jack-audio-connection-kit package. The flags --enablerepo and --disablerepo are helpful in case when one repository needs to be excluded.

# dnf --disablerepo=rpmfusion* provides "*/audioadapter.so"

List of package groups

# dnf grouplist
Pantheon Desktop
Python Classroom

Now we can easily install Python education environment:

dnf groupinstall "Python Classroom"

Download the packages without installation:

# dnf download package1 package2


There are all basic commands. If you don't understand any of these commands, run again dnf or dnf command help in your terminal.
Let's talk about more difficult things. For example, we have a package with ~100 dependencies. Deleting the whole dependency list will be a serious pain, but dnf package transactions can help.

# dnf history
ID     | Login user               | Date a | Action | Altere
    79 | Paul <paul>              | 2022-05-31 00:55 | Install        |    9
    78 | Paul <paul>              | 2022-05-30 13:25 | Install        |    1
    77 | Paul <paul>              | 2022-05-30 13:24 | Install        |    1

We can search for one package in all transaction since OS installation moment and install/uninstall this package in one command:

# dnf history list ffmpeg
ID     | Command line             | Date a | Action | Altere
    71 | -4 update --refresh      | 2022-05-09 22:08 | E, I, U        |  382 EE
    15 | --nogpgcheck --enablerepo | 2022-03-06 21:34 | Install        |   21 EE

# dnf history undo 15

And we can install again all these 21 packages:

# dnf history undo 15

Find a repository where's package belongs to:

# dnf repolist
repo id                       repo name                                   status
*fedora                       Fedora 36 - x86_64                          44,762
rpmfusion-free                RPM Fusion for Fedora 36 - Free                493

# dnf repository-packages rpmfusion-free list
Installed Packages
gstreamer1-libav.x86_64          1.4.3-1                     @System
lame-libs.x86_64                 3.99.5-5                    @System

Remove or reinstall all packages from selected repository:

# dnf repository-packages rpmfusion-free remove
# dnf repository-packages rpmfusion-free remove-old
# dnf repository-packages rpmfusion-free reinstall

DNF also works with Copr (like Lauchpad PPA) repositories:

# dnf copr list test
========================== List of test coprs ===========================
test/Test-project.235 : test description

# dnf copr enable test/Test-project.235
# dnf copr disable test/Test-project.235


DNF Repoquery searches previously selected packages and shows information about them. For example, we need all systemd packages:

# dnf repoquery 'systemd*'

Display the systemd package requirements:

# dnf repoquery --requires systemd --resolve

Name, architecture and repository of all systemd packages:

# dnf repoquery --queryformat '%{name}.%{arch} : %{reponame}' systemd
systemd.x86_64 : updates-testing
systemd.i686 : updates-testing
systemd.i686 : fedora
systemd.x86_64 : fedora
systemd.i686 : updates
systemd.x86_64 : updates

Display all available packages providing systemd, but only for x86_64 architecture:

# dnf repoquery --whatprovides systemd --arch x86_64

Show duplicated packages:

# dnf repoquery --duplicated

How to download and install a local package

# dnf download shotwell
# dnf install /tmp/shotwell-0.30.14-1.x86_64.rpm
Version lock

The versionlock plugin designed to freezing package version.

# dnf install 'dnf-command(versionlock)'
# dnf versionlock add locked_package

Package excluding

Very similar to versionlock, allows to completely forget about package.

# dnf upgrade --exclude=packagename

Broken package

If the package is broken like a missed file or dependency, low-level rpm tool can be used:

# rpm -e broken_package-version --noscripts

Useful options

-4 - resolve to IPv4 addresses only.

-6 - resolve to IPv6 addresses only.

--allowerasing - allows erasing of installed packages to resolve dependencies. This option could be used as an alternative to yum swap command where packages to remove are not explicitly defined.

-C, --cacheonly - run entirely from the operation system cache, don’t update the cache and use it even in case it is expired.

--debugsolver - dump data aiding in dependency solver debugging into local debugdata file.

--disablerepo=<id> - disable specific repositories by an id or a glob.

--installroot=<path> - set the installation root directory.

--releasever=<release> - configure DNF to use only defined .

-y or --assumeyes - answer 'yes' to all interactive questions.

That's all, feel free to contact us if you have any questions.