Home Fedora Fedora package management with DNF

Fedora package management with DNF

by Enock
Published: Updated:
Fedora Package Management DNF

DNF is a software package manager on RPM distros such as Fedora, CentOS, OpenMandriva, RHEL, and Mageia. It is an installer wizard that installs, updates, and removes packages and is the successor to YUM (Yellow-Dog Updater). It was introduced in Fedora 18 and has been the default package manager since Fedora 22.

DNF or Dandified Yum automatically computes dependencies to determine the actions required to install packages and maintain packages. With DNF, you do not have to install or update packages using the rpm command manually.

Package management system

Fedora uses a package management system based on rpm (RPM package manager) and other tools such as PackageKit (GUI), Gnome Package Manager (GUI), DNF, Yumex(Yum Extender), Yum (command line).

Advantages of package management systems

  • It makes it easy to query installed and available packages.
  • You can easily remove a package and its files entirely.
  • It makes it easy to verify the integrity of package files.
  • It makes it easy to upgrade a package and remove all old version files, which might break your system.
  • You can easily downgrade back to previous versions.
  • It makes it easy for a user to install or remove groups of packages.

Avoid mixing source installs and packages

Some instances require you to install software from a source, but you should avoid mixing source installs and packaged installs.
Here is at least why:

  • You do not get to enjoy all the advantages that come with a package-managed system.
  • Source installs may overwrite, delete, or change existing package files breaking the package.
  • Installing from source files makes it difficult and almost impossible to debug issues.
  • Packages may include patches to work with other packages, but source installs do not, which leads to loss of functionality.
  • Source installs will not upgrade with package managed packages, leading to breakages on upgrades or system updates.

If the software is missing in your installation, you should try the following steps to get a packaged version. Search in Fedora using dnf or yum, try the available 3rd party repositories, or build your own package.

Features of DNF

  • Supports multiple repositories.
  • It features a simple configuration and interface.
  • It features package group support and multiple-repository groups.
  • RPM-consistent behavior.
  • It runs in both Python 2 and Python 3.
  • It includes C bindings for lower-level libraries like librepo, libcomps, and hawkey.

Available commands

The DNF command can be used exactly as yum to search, install and remove packages.

Search for a package

Before you install a package, you may need to confirm if it exists in the Fedora servers. Use the common name of the application with the DNF search command. For example, to typeset a document with LaTeX in Fedora, you need to search and install the TeXstudio application:

# sudo dnf search packagename
[tuts@fosslinux ~]$ sudo dnf search texstudio
texstudio.x86_64 : A feature-rich editor for LaTeX documents

There is an exact match for the TeXstudio package listed as texstudio.x86_64. The .x86_64 in the name denotes the CPU architecture, and by default, your Fedora system installs packages with matching CPU architecture. After you have confirmed that the package is called texstudio, you can install it with dnf install.

Install a package.

# dnf install packagename
$ sudo dnf install texstudio

Package metadata

Sometimes the DNF search results aren’t precise. It is often helpful to browse a package’s metadata, such as the project’s URL, license, detailed description, and so on. Use the DNF info command to get package metadata:

[tuts@fosslinux ~]$ dnf info texstudio 
TeXstudio

Display TeXstudio information

Find a package that provides a file

During a search, a package name does not always return the desired outcome. For example, a search query for a dependency like qmake-qt5 returns ‘No matches found.’

$ dnf search qmake-qt5
No matches found.

Use dnf to widen your search query in the DNF database and determine whether any resource provides what you are looking for or if it is part of a larger package.

[tuts@fosslinux ~]$ sudo dnf provides texstudio
DNF provides

Display dnf provides texstudio

The results from the command confirm that the texstudio package is available in the system as texstudio-3.0.1-1.fc33.x86_64, and another version, texstudio-3.1.2-1.fc33.x86_64 is also available in the updates repo.

Find files included in a package

In certain instances, you might find that an application is already installed in your system and want to know what package put it on your system. To find out such details, you need to reverse engineer the package payload with the DNF repoquery command with the –list option. The command looks at the repository metadata about the package and returns a list of all file provided by the specified package:

[tuts@fosslinux ~]$ sudo dnf repoquery --list texstudio
TeXstudio repoquery

Display TeXstudio repoquery

Remove a package

If you no longer need a package in your system, use dnf remove to uninstall it. The command will remove all the installed package files and any unnecessary dependencies.

# dnf remove packagename
$ sudo dnf remove texstudio

In some instances, two or more packages require the same dependency. In such cases, the DNF remove command does not remove the dependency. However, you might still end up with stray packages after installing and uninstalling many applications and packages. To clear any unused packages, use dnf autoremove:

$ sudo dnf autoremove

Automatic updates

The DNF-automatic package provides a service for automatic download and installation of updates. It can automatically monitor available updates, send logs about downloaded packages and reports of installed updates via email.  It is an alternative to dnf-upgrade and can be executed automatically from systemd timers or cron jobs

To install dnf-automatic RPM, run the following command:

$ sudo dnf install dnf-automatic

By default, the dnf-automatic runs configurations in /etc/dnf/automatic.conf file. Default configurations only download but do not apply the changes to your system.

To run dnf-automatic:

systemctl enable dnf-automatic.timer && systemctl start dnf-automatic.timer

To check the status of dnf-automatic:

systemctl list-timers dnf-automatic-download.timer

Available timers to control dnf-automatic

To download only

# dnf-automatic-download.timer

To download and install

# dnf-automatic-install.timer 

To notify via configured emitters in /etc/dnf/automatic.conf

# dnf-automatic-notifyonly.timer - 

System upgrades

You can upgrade Fedora systems directly with DNF or the DNF system upgrade plugin.

To update your Fedora release directly from DNF:

$ sudo dnf upgrade --refresh

then reboot your system.

To update your system from the dnf upgrade plugin.

First, install the plugin with the following command:

$ sudo dnf install dnf-plugin-system-upgrade

Download updated packages:

$ sudo dnf system-upgrade download --releasever=34

Change the –releasever=34 number if you want to upgrade to a different release. In our case, the latest stable release is 34. You can also use 35 to upgrade to a branched release or Rawhide to upgrade to Rawhide. Note, a Fedora system upgrade is only officially tested and supported over two releases at most (i.e., from 32 to 34).

Trigger the upgrade process and system reboot with the following command:

$ sudo dnf system-upgrade reboot

Adding repositories

To add a new software repository, add a new file with the .repo (I.e fedoraextra.repo) extension to the /etc/yum.repos.d/ directory. Use dnf config-manager to add a newly created repository with the following command:

# dnf config-manager --add-repo new_repository

Replace new_repository with the path to the .repo(i.e., fedoraextra.repo) file you created.

# dnf config-manager --add-repo /etc/yum.repos.d/fedoraextra.repo

Enable repositories.

To enable a newly created repository, run the following command as root:

$ sudo dnf config-manager --set-enabled new_repository

Replace the new_repository with the repo (i.e., fedoraextra) you created.

$ sudo dnf config-manager --set-enabled fedoraextra

Remove and disable repositories

To disable a specific repository, run the following command as root:

$ dnf config-manager --set-disabled new_repository

Replace new_repository with the unique repo ID (i.e., fedoraextra) you created.

$ dnf config-manager --set-disabled fedoraextra

Enable RPM Fusion repositories

Third-party software repositories have more liberal licensing policies and provide software packages that Fedora excludes from its official releases. These software repos are not officially affiliated or endorsed by the Fedora Project. Users should exercise caution when installing software from these repositories.
RPM Fusion is a community-maintained repository providing additional packages that cannot be distributed in Fedora for legal reasons. It also provides packages for Red Hat Enterprise Linux.

Run the following command to enable the Free repository:

$ sudo dnf install \ https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm

Run the following command to enable the Nonfree repository:

$ sudo dnf install \
https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm

Note that you have to confirm repository signatures when installing packages for the first time from these repositories.

Other common DNF commands

  • dnf check-update – only checks for updates but does not download or install the package.
  • dnf downgrade – reverts to a previous version of an installed package.
  • dnf reinstall – reinstall the current package.
  • dnf upgrade – checks your repositories for newer packages and updates all of them.

DNF Plugins

You can extend core DNF functionality with officially supported Core DNF plugins or third-party Extras DNF Plugins. Install plugins with the following commands:

# dnf install dnf-plugins-core-PLUGIN_NAME
$ sudo dnf install dnf-plugins-core-versionlock
OR
# dnf install dnf-plugins-extras-PLUGIN_NAME

DNF version lock plugin

The DNF versionlock plugin is part of Core DNF plugins and allows you to limit the packages included in a DNF transaction. You can list what versions of specific packages should be considered in a dnf transaction. All other versions of the particular packages will be ignored.

To use, install the plugin with the following command:

# dnf install dnf-plugins-core-(plugin)
$ sudo dnf install dnf-plugins-core-versionlock

To lock the current version of a package:

$ sudo dnf versionlock add packagename

To remove the version lock:

$ sudo dnf versionlock delete packagename

To list all locked packages:

$ sudo dnf versionlock list

To delete all locked packages:

$ sudo dnf versionlock clear

Excluding packages from transactions

In certain instances, it is helpful to exclude specific packages from transactions and updates. One such scenario is when an update includes a bug or a regression. This method is handy when using the GUI update application, which does not specify packages to exclude from a transaction.

Exclude a package with the following commands:

$ sudo dnf upgrade --exclude=packagename

You can also exclude a package using the /etc/dnf/dnf.conf or /etc/yum.repos.d/ for specific repository configuration files.

excludepkgs=packagename

To disable this configuration, use the –disableexcludes in individual dnf commands.

DNF commands compared with APT

If you are making a shift from Debian or Ubuntu-based distros, you will be familiar with the APT package manager. It manages .deb packages installed by the DPKG program. We could say DNF is to .rpm as APT is to .deb, and here we list some common APT commands with their DNF equivalents.

APT commandsDNF commands
apt update
apt-get update
dnf check-update
apt upgrade
apt-get upgrade
dnf upgrade
apt full-upgrade
apt-get dist-upgrade
dnf distro-sync or
dnf system-upgrade
apt remove
apt-get remove
dnf remove
apt purge
apt-get purge
---
apt autoremove
apt-get autoremove
dnf autoremove
apt search
apt-cache search
dnf search

Installing application with GNOME software

As you would expect, you can also use the GNOME software GUI application to search, install and update applications in your Fedora system.

GNOME software app

Install apps using GNOME software

You can browse different categories to search for an application, then click the install button.
Alternatively, you can download .rpm or .flatpakref files and open them in GNOME software to install.

Wrapping Up

Even for casual desktop users, getting to know and use the DNF package manager is straightforward. It is a great and robust tool to query and install applications, packages, and software in Fedora.

You may also like

Leave a Comment

fl_logo_v3_footer

ENHANCE YOUR LINUX EXPERIENCE.



FOSS Linux is a leading resource for Linux enthusiasts and professionals alike. With a focus on providing the best Linux tutorials, open-source apps, news, and reviews written by team of expert authors. FOSS Linux is the go-to source for all things Linux.

Whether you’re a beginner or an experienced user, FOSS Linux has something for everyone.

Follow Us

Subscribe

©2016-2023 FOSS LINUX

A PART OF VIBRANT LEAF MEDIA COMPANY.

ALL RIGHTS RESERVED.

“Linux” is the registered trademark by Linus Torvalds in the U.S. and other countries.