Bookmark this page

Install and Update Software Packages with DNF

Objectives

Find, install, and update software packages with the dnf command.

Manage Software Packages with DNF

DNF (Dandified YUM) replaced YUM as the package manager in Red Hat Enterprise Linux 9. DNF commands are functionally the same as YUM commands. For compatibility, YUM commands still exist as symbolic links to DNF:

[user@host ~]$ ls -l /bin/ | grep yum | awk '{print $9 " " $10 " " $11}'
yum -> dnf-3
yum-builddep -> /usr/libexec/dnf-utils
yum-config-manager -> /usr/libexec/dnf-utils
yum-debug-dump -> /usr/libexec/dnf-utils
yum-debug-restore -> /usr/libexec/dnf-utils
yumdownloader -> /usr/libexec/dnf-utils
yum-groups-manager -> /usr/libexec/dnf-utils

In this course, you work with the dnf command. Some documentation might still refer to the yum command, but the files are the same linked command.

The low-level rpm command can be used to install packages, but it is not designed to work with package repositories or to resolve dependencies from multiple sources automatically.

DNF improves RPM-based software installation and updates. With the dnf command, you can install, update, remove, and get information about software packages and their dependencies. You can get a history of transactions and work with multiple Red Hat and third-party software repositories.

Find Software with DNF

The dnf help command displays usage information. The dnf list command displays installed and available packages.

[user@host ~]$ dnf list 'http*'
Available Packages
http-parser.i686               2.9.4-6.el9    rhel-9.0-for-x86_64-appstream-rpms
http-parser.x86_64             2.9.4-6.el9    rhel-9.0-for-x86_64-appstream-rpms
httpcomponents-client.noarch   4.5.13-2.el9   rhel-9.0-for-x86_64-appstream-rpms
httpcomponents-core.noarch     4.4.13-6.el9   rhel-9.0-for-x86_64-appstream-rpms
httpd.x86_64                   2.4.51-5.el9   rhel-9.0-for-x86_64-appstream-rpms
httpd-devel.x86_64             2.4.51-5.el9   rhel-9.0-for-x86_64-appstream-rpms
httpd-filesystem.noarch        2.4.51-5.el9   rhel-9.0-for-x86_64-appstream-rpms
httpd-manual.noarch            2.4.51-5.el9   rhel-9.0-for-x86_64-appstream-rpms
httpd-tools.x86_64             2.4.51-5.el9   rhel-9.0-for-x86_64-appstream-rpms

The dnf search KEYWORD command lists packages by keywords that are in the name and summary fields only. To search for packages with "web server" in their name, summary, and description fields, use search all:

[user@host ~]$ dnf search all 'web server'
================== Summary & Description Matched: web server ===================
nginx.x86_64 : A high performance web server and reverse proxy server
pcp-pmda-weblog.x86_64 : Performance Co-Pilot (PCP) metrics from web server logs
========================= Summary Matched: web server ==========================
libcurl.x86_64 : A library for getting files from web servers
libcurl.i686 : A library for getting files from web servers
======================= Description Matched: web server ========================
freeradius.x86_64 : High-performance and highly configurable free RADIUS server
git-instaweb.noarch : Repository browser in gitweb
http-parser.i686 : HTTP request/response parser for C
http-parser.x86_64 : HTTP request/response parser for C
httpd.x86_64 : Apache HTTP Server
mod_auth_openidc.x86_64 : OpenID Connect auth module for Apache HTTP Server
mod_jk.x86_64 : Tomcat mod_jk connector for Apache
mod_security.x86_64 : Security module for the Apache HTTP Server
varnish.i686 : High-performance HTTP accelerator
varnish.x86_64 : High-performance HTTP accelerator
...output omitted...

The dnf info PACKAGENAME command returns detailed information about a package, including the needed disk space for installation. For example, the following command retrieves information about the httpd package:

[user@host ~]$ dnf info httpd
Available Packages
Name         : httpd
Version      : 2.4.51
Release      : 5.el9
Architecture : x86_64
Size         : 1.5 M
Source       : httpd-2.4.51-5.el9.src.rpm
Repository   : rhel-9.0-for-x86_64-appstream-rpms
Summary      : Apache HTTP Server
URL          : https://httpd.apache.org/
License      : ASL 2.0
Description  : The Apache HTTP Server is a powerful, efficient, and extensible
             : web server.

The dnf provides PATHNAME command displays packages that match the specified path name (the path names often include wildcard characters). For example, the following command finds packages that provide the /var/www/html directory:

[user@host ~]$ dnf provides /var/www/html
httpd-filesystem-2.4.51-5.el9.noarch : The basic directory layout for the Apache HTTP Server
Repo        : rhel-9.0-for-x86_64-appstream-rpms
Matched from:
Filename    : /var/www/html

Install and Remove Software with DNF

The dnf install PACKAGENAME command obtains and installs a software package, including any dependencies.

[root@host ~]# dnf install httpd
Dependencies resolved.
================================================================================
 Package          Arch   Version       Repository                          Size
================================================================================
Installing:
 httpd            x86_64 2.4.51-5.el9  rhel-9.0-for-x86_64-appstream-rpms 1.5 M
Installing dependencies:
 apr              x86_64 1.7.0-11.el9  rhel-9.0-for-x86_64-appstream-rpms 127 k
 apr-util         x86_64 1.6.1-20.el9  rhel-9.0-for-x86_64-appstream-rpms  98 k
 apr-util-bdb     x86_64 1.6.1-20.el9  rhel-9.0-for-x86_64-appstream-rpms  15 k
 httpd-filesystem noarch 2.4.51-5.el9  rhel-9.0-for-x86_64-appstream-rpms  17 k
 httpd-tools      x86_64 2.4.51-5.el9  rhel-9.0-for-x86_64-appstream-rpms  88 k
 redhat-logos-httpd
                  noarch 90.4-1.el9    rhel-9.0-for-x86_64-appstream-rpms  18 k
Installing weak dependencies:
 apr-util-openssl x86_64 1.6.1-20.el9  rhel-9.0-for-x86_64-appstream-rpms  17 k
 mod_http2        x86_64 1.15.19-2.el9 rhel-9.0-for-x86_64-appstream-rpms 153 k
 mod_lua          x86_64 2.4.51-5.el9  rhel-9.0-for-x86_64-appstream-rpms  63 k

Transaction Summary
================================================================================
Install  10 Packages

Total download size: 2.1 M
Installed size: 5.9 M
Is this ok [y/N]: y
Downloading Packages:
(1/10): apr-1.7.0-11.el9.x86_64.rpm             6.4 MB/s | 127 kB     00:00
(2/10): apr-util-bdb-1.6.1-20.el9.x86_64.rpm    625 kB/s |  15 kB     00:00
(3/10): apr-util-openssl-1.6.1-20.el9.x86_64.rp 1.9 MB/s |  17 kB     00:00
...output omitted...
Total                                            24 MB/s | 2.1 MB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1
  Installing       : apr-1.7.0-11.el9.x86_64                               1/10
  Installing       : apr-util-bdb-1.6.1-20.el9.x86_64                      2/10
  Installing       : apr-util-openssl-1.6.1-20.el9.x86_64                  3/10
...output omitted...
Installed:
  apr-1.7.0-11.el9.x86_64              apr-util-1.6.1-20.el9.x86_64
  apr-util-bdb-1.6.1-20.el9.x86_64     apr-util-openssl-1.6.1-20.el9.x86_64
...output omitted...
Complete!

The dnf update PACKAGENAME command obtains and installs a later version of the specified package, including any dependencies. Generally, the process tries to preserve configuration files in place, but in some cases, those files might be renamed if the packager considers that the earlier name will not work after the update. If no PACKAGENAME is specified, then it installs all relevant updates.

[root@host ~]# dnf update

Because a new kernel can be tested only by booting to that kernel, the package specifically supports the installation of multiple versions at once. If the new kernel fails to boot, then the earlier kernel is still available. Running the dnf update kernel command installs the new kernel. The configuration files hold a list of packages to always install even if the administrator requests an update.

Use the dnf list kernel command to list all installed and available kernels. To view the currently running kernel, use the uname command. The uname command -r option shows only the kernel version and release, and the uname command -a option shows the kernel release and additional information.

[user@host ~]$ dnf list kernel
Installed Packages
kernel.x86_64                       5.14.0-70.el9                        @System
[user@host ~]$ uname -r
5.14.0-70.el9.x86_64
[user@host ~]$ uname -a
Linux workstation.lab.example.com 5.14.0-70.el9.x86_64 #1 SMP PREEMPT Thu Feb 24 19:11:22 EST 2022 x86_64 x86_64 x86_64 GNU/Linux

The dnf remove PACKAGENAME command removes an installed software package, including any supported packages.

[root@host ~]# dnf remove httpd

Warning

The dnf remove command removes the listed packages and any package that requires the packages to be removed (and packages which require those packages, and so on). This command can lead to unexpected removal of packages, so review the list of packages to be removed.

Install and Remove Groups of Software with DNF

The dnf command also has the concept of groups, which are collections of related software that are installed together.

In Red Hat Enterprise Linux 9, the dnf command can install two kinds of package groups. Regular groups are collections of packages. Environment groups are collections of regular groups. The packages or groups that these collections provide might be listed as mandatory (they must be installed if the group is installed), default (normally installed if the group is installed), or optional (not installed when the group is installed, unless specifically requested).

Similar to the dnf list command, the dnf group list command shows the names of installed and available groups.

[user@host ~]$ dnf group list
Available Environment Groups:
   Server with GUI
   Server
   Minimal Install
...output omitted...
Available Groups:
   Legacy UNIX Compatibility
   Console Internet Tools
   Container Management
...output omitted...

Some groups are normally installed through environment groups and are hidden by default. List these hidden groups with the dnf group list hidden command.

The dnf group info command displays information about a group. It includes a list of mandatory, default, and optional package names.

[user@host ~]$ dnf group info "RPM Development Tools"
Group: RPM Development Tools
 Description: Tools used for building RPMs, such as rpmbuild.
 Mandatory Packages:
   redhat-rpm-config
   rpm-build
 Default Packages:
   rpmdevtools
 Optional Packages:
   rpmlint

The dnf group install command installs a group that installs its mandatory and default packages and their dependent packages.

[root@host ~]# dnf group install "RPM Development Tools"
...output omitted...
Installing Groups:
 RPM Development Tools

Transaction Summary
================================================================================
Install  19 Packages

Total download size: 4.7 M
Installed size: 15 M
Is this ok [y/N]: y
...output omitted...

Important

Starting in Red Hat Enterprise Linux 7, the behavior of Yum groups changed, to be treated as objects and tracked by the system. If an installed group is updated, and if the Yum repository added new mandatory or default packages to the group, then those new packages are installed at update.

RHEL 6 and earlier versions consider a group to be installed if all its mandatory packages are installed, or if it had no mandatory packages, or if any default or optional packages in the group are installed. Starting in RHEL 7, a group is considered to be installed only if yum group install was used to install it. You can use the yum group mark install GROUPNAME command to mark a group as installed, and any missing packages and their dependencies are installed at the next update.

RHEL 6 and earlier versions did not have the two-word form of the yum group commands. In other words, in RHEL 6 the command yum grouplist existed, but the equivalent RHEL 7 and RHEL 8 yum group list command did not.

View Transaction History

All installation and removal transactions are logged in the /var/log/dnf.rpm.log file.

[user@host ~]$ tail -5 /var/log/dnf.rpm.log
2022-03-23T16:46:43-0400 SUBDEBUG Installed: python-srpm-macros-3.9-52.el9.noarch
2022-03-23T16:46:43-0400 SUBDEBUG Installed: redhat-rpm-config-194-1.el9.noarch
2022-03-23T16:46:44-0400 SUBDEBUG Installed: elfutils-0.186-1.el9.x86_64
2022-03-23T16:46:44-0400 SUBDEBUG Installed: rpm-build-4.16.1.3-11.el9.x86_64
2022-03-23T16:46:44-0400 SUBDEBUG Installed: rpmdevtools-9.5-1.el9.noarch

The dnf history command displays a summary of installation and removal transactions.

[root@host ~]# dnf history
ID     | Command line              | Date and time    | Action(s)      | Altered
--------------------------------------------------------------------------------
     7 | group install RPM Develop | 2022-03-23 16:46 | Install        |   20
     6 | install httpd             | 2022-03-23 16:21 | Install        |   10 EE
     5 | history undo 4            | 2022-03-23 15:04 | Removed        |   20
     4 | group install RPM Develop | 2022-03-23 15:03 | Install        |   20
     3 |                           | 2022-03-04 03:36 | Install        |    5
     2 |                           | 2022-03-04 03:33 | Install        |  767 EE
     1 | -y install patch ansible- | 2022-03-04 03:31 | Install        |   80

The dnf history undo command reverses a transaction.

[root@host ~]# dnf history undo 6
...output omitted...
Removing:
 apr-util-openssl x86_64 1.6.1-20.el9 @rhel-9.0-for-x86_64-appstream-rpms  24 k
 httpd            x86_64 2.4.51-5.el9 @rhel-9.0-for-x86_64-appstream-rpms 4.7 M
...output omitted...

Summary of DNF Commands

Packages can be located, installed, updated, and removed by name or by package groups.

Task:Command:
List installed and available packages by name. dnf list [NAME-PATTERN]
List installed and available groups. dnf group list
Search for a package by keyword. dnf search KEYWORD
Show details of a package. dnf info PACKAGENAME
Install a package. dnf install PACKAGENAME
Install a package group. dnf group install GROUPNAME
Update all packages. dnf update
Remove a package. dnf remove PACKAGENAME
Display transaction history. dnf history

Manage Package Module Streams with DNF

Traditionally, managing alternative versions of an application's software package and its related packages meant maintaining different repositories for each version. For developers who wanted the latest version of an application and administrators who wanted the most stable version of the application, the resulting situation was tedious to manage. Red Hat simplifies this process by using a technology called modularity. With modularity, a single repository can host multiple versions of an application's package and its dependencies.

Introduction to BaseOS and Application Stream

Red Hat Enterprise Linux 9 distributes the content through two main software repositories: BaseOS and Application Stream (AppStream).

The BaseOS repository provides the core operating system content for Red Hat Enterprise Linux as RPM packages. BaseOS components have the same lifecycle as content in previous Red Hat Enterprise Linux releases. The Application Stream repository provides content with varying lifecycles as both modules and traditional packages.

Application Stream contains necessary parts of the system, as well as a wide range of applications that were previously available as part of Red Hat Software Collections and other products and programs. Each Application Stream has a lifecycle that is either the same as Red Hat Enterprise Linux 9 or shorter.

Both BaseOS and AppStream are necessary parts of a Red Hat Enterprise Linux 9 system.

The Application Stream repository contains two types of content: modules and traditional RPM packages. A module describes a set of RPM packages that belong together. Modules can contain several streams to make multiple versions of applications available for installation. Enabling a module stream gives the system access to the RPM packages within that module stream. Typically, modules organize the RPM packages around a specific version of a software application or programming language. A typical module contains packages with an application, packages with the application's specific dependency libraries, packages with documentation for the application, and packages with helper utilities.

Important

Red Hat Enterprise Linux 9.0 ships without modules. Future versions of RHEL 9 might introduce additional content and later software versions as modules. Furthermore, starting with RHEL 9, you must manually specify default module streams, because they are no longer defined by default. You can define default module streams with configuration files in the /etc/dnf/modules.defaults.d/ directory.

Module Streams

Each module has one or more module streams, which hold different versions of the content. Each of the streams receives updates independently. Think of the module stream as a virtual repository in the Application Stream physical repository.

For each module, you can enable only one of its streams, and this stream provides its packages.

Module Profiles

Each module can have one or more profiles. A profile is a list of packages that you can install together for a particular use case, such as for a server, client, development, minimal installation, or other.

Installing a module profile installs a particular set of packages from the module stream. You can subsequently install or uninstall packages normally. If you do not specify a profile, then the module installs its default profile.

Manage Modules with DNF

Red Hat Enterprise Linux 9 supports modular features of Application Stream. To handle the modular content, you can use the dnf module command. Otherwise, the dnf command works with similar modules to regular packages.

See the following list for some important commands to manage modules:

  • dnf module list : List the available modules with the module name, stream, profiles, and a summary.

  • dnf module list module-name : List the module streams for a specific module and retrieve their status.

  • dnf module info module-name : Display details of a module, including the available profiles and a list of the packages that the module installs. Running the dnf module info command without specifying a module stream lists the packages that are installed from the default profile and stream. Use the module-name:stream format to view a specific module stream. Add the --profile option to display information about packages that each of the module's profiles installed.

  • dnf module provides package : Display which module provides a specific package.

 

References

dnf(1) and dnf.conf(5) man pages

For more information, refer to the Managing Software Packages chapter in the Red Hat Enterprise Linux 9 Configuring Basic system Settings Guide at https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html-single/configuring_basic_system_settings/index#managing-software-packages_configuring-basic-system-settings

For more information, refer to the Distribution of Content in RHEL 9 chapter in the Red Hat Enterprise Linux 9 Managing Software with the DNF Tool Guide at https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html-single/managing_software_with_the_dnf_tool/index#assembly_distribution-of-content-in-rhel-9_managing-software-with-the-dnf-tool

Modularity

Revision: rh124-9.0-398f302