DNF in Action — Practice Guide for Centos/RHEL/Fedora Package Manager

DNF — package manager in Red Hat Enterprise Linux, Centos, Fedora(default in Fedora 22). It’s very powerful and speed tool and can be very helpful in your work. DNF work with *.rpm-packages(Red Hat Package Manager). Yum is currently defined as legacy software.

For begin just type in terminal:


# dnf
You need to give some command
usage: dnf [options] COMMAND

List of Main Commands

check-update              Check for available package upgrades
clean                     Remove cached data
distro-sync               Synchronize installed packages to the latest available versions
downgrade                 downgrade a package
group                     Display, or use, the groups information
help                      Display a helpful usage message
history                   Display, or use, the transaction history
info                      Display details about a package or group of packages
install                   Install a package or packages on your system
list                      List a package or groups of packages
makecache                 Generate the metadata cache
provides                  Find what package provides the given value
reinstall                 reinstall a package
remove                    Remove a package or packages from your system
repolist                  Display the configured software repositories
repository-packages       Run commands on top of all packages in given repository
search                    Search package details for the given string
updateinfo                Display advisories about packages
upgrade                   Upgrade a package or packages on your system
upgrade-to                Upgrade a package on your system to the specified version

List of Plugin Commands

builddep                  Install build dependencies for packagei or spec file
config-manager            manage dnf configuration options and repositories
copr                      Interact with Copr repositories.
debuginfo-install         install debuginfo packages
download                  Download package to current directory
kickstart                 Install packages defined in a kickstart file on your system
migrate                   migrate yum's history, group and yumdb data to dnf
needs-restarting          determine updated binaries that need restarting
playground                Interact with Playground repository.
repoquery                 search for packages matching keyword
reposync                  download all packages from remote repo

You can see a list of basic commands. For example, try to search package:

# dnf search copr-cli
Last metadata expiration check performed 0:46:03 ago on Tue Jun  2 20:39:39 2015.
============================ N/S Matched: copr-cli =============================
copr-cli.noarch : Command line interface for COPR
copr-cli-doc.noarch : Code documentation for COPR

It works! Now we run a global search in 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 package:

# dnf install package1 package2
# dnf reinstall package1 package2

Delete package:

# dnf erase package1 package2

Information about packages:

# dnf info package1 package2

Find what packages provide some library or file:

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

List of packages group:

# dnf grouplist

Download packages:

# dnf download package1 package2

This is all basic commands. If you don’t understand one of this 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 depends. Deleting all dependencies is serious pain, but transactions can help you. How?

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

We can search all packages in transaction and install/uninstall this packages in one command:

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

# dnf history undo 15

And we can install again this 21 packages:

# dnf history undo 15

Check packages in repository:

# dnf repolist
repo id                       repo name                                   status
*fedora                       Fedora 22 - x86_64                          44,762
rpmfusion-free                RPM Fusion for Fedora 22 - Free                493
rpmfusion-free-updates        RPM Fusion for Fedora 22 - Free - Updates        0
rpmfusion-nonfree             RPM Fusion for Fedora 22 - Nonfree             163
rpmfusion-nonfree-updates     RPM Fusion for Fedora 22 - Nonfree - Update      0
*updates                      Fedora 22 - x86_64 - Updates                 2,805
*updates-testing              Fedora 22 - x86_64 - Test Updates           15,970

# dnf repository-packages rpmfusion-free list
Installed Packages
gstreamer1-libav.x86_64          1.4.3-1.fc22                     @System
lame-libs.x86_64                 3.99.5-5.fc22                    @System
libva-intel-driver.x86_64        1.5.1-1.fc22                     @System
x264.x86_64                      0.142-11.20141221git6a301b6.fc22 @System
x264-libs.x86_64                 0.142-11.20141221git6a301b6.fc22 @System
x265-libs.x86_64                 1.2-6.fc22                       @System
xvidcore.x86_64                  1.3.2-6.fc22                     @System
Available Packages
DVDAuthorWizard.noarch           1.4.6-7.fc22                     rpmfusion-free
DVDRipOMatic.noarch              0.95-11.fc22                     rpmfusion-free

Remove or reinstall all packages from this repository:

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

DNF also work with Copr (PPA-analog) repositories:

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

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

Repoquery search previously selected packages and displays information about them:

# dnf repoquery 'systemd*'
#display all systemd packages

Display packages providing the requires of systemd package:

# dnf repoquery --requires systemd --resolve
Last metadata expiration check performed 2:24:48 ago on Tue Jun  2 20:39:39 2015.

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 local package:

# dnf download shotwell
# dnf install /tmp/shotwell-0.22.0-4.fc22.x86_64.rpm

Some useful options:

-4    Resolve to IPv4 addresses only.

-6    Resolve to IPv6 addresses only.

--allowerasing    Allow 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 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 ./debugdata

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

--installroot=<path>    Set install root

--releasever=<release>    Configure DNF as if the distribution release was

-y, --assumeyes    Answer yes for all questions

You can read also:

Changes in DNF CLI compared to Yum

DNF Documentation

That’s all, feel free to ask your question in comments. You can also buy the Red Hat Enterprise Linux and support this website and Linux. Joke 🙂


Read more:

Linux and Open Source Propaganda in “Mr. Robot” TV Show

Stable Wi-Fi Network How-to and Why We Maybe Can’t Do It in Future

Lennart Poettering merged “su” command replacement into systemd: Test Drive on Fedora Rawhide

KDE Plasma 5.4 and KDE Apps on Wayland Test Drive

  • Ade Malsasa Akbar

    Thank you.

    • Paul Alberto Rufous

      Always welcome.