Introduction
In this lab, you will gain hands-on experience managing software packages on Red Hat Enterprise Linux (RHEL) systems using DNF. You will begin by understanding the subscription-manager command for Red Hat support registration, even in a simulated environment. Subsequently, you will explore how to retrieve and interpret RPM package information, and then master the installation and removal of software packages using DNF.
Furthermore, this lab will guide you through managing DNF software repositories, including adding, enabling, and disabling them. Finally, you will learn how to view and understand the DNF transaction history, providing a comprehensive overview of package management operations.
Note: This lab requires network connectivity to download packages and access repositories. It is only available to LabEx Pro users.
Register Your System for Red Hat Support
In this step, you will learn how to register your system for Red Hat support using the subscription-manager command. While a full Red Hat subscription is not available in this simulated environment, understanding the subscription-manager command is crucial for managing software on Red Hat Enterprise Linux systems. This command allows you to register your system with Red Hat, attach subscriptions, and access Red Hat's content delivery network for software packages and updates.
First, let's attempt to register the system using a placeholder username. This will demonstrate the command's usage, even though actual registration requires valid Red Hat credentials.
sudo subscription-manager register --username labex
You will be prompted for a password. Since this is a simulated environment, you can enter any password, or simply press Enter if the system allows it. The command will likely fail to connect to Red Hat's subscription service, which is expected in this lab environment. The important part is to understand the command's syntax and its intended use.
Registering to: subscription.rhsm.redhat.com:443/subscription
Password:
Invalid username or password. To create a login, please visit https://www.redhat.com/wapps/ugc/register.html (HTTP error code 401: Unauthorized)
Finally, let's see how to view consumed subscriptions. This command shows which subscriptions are currently attached to your system.
sudo subscription-manager list --consumed
Since the system is not registered, you will see a message indicating no consumed subscriptions.
No consumed subscription pools were found.
Next, let's explore how you would typically list available subscriptions for your Red Hat account. This command would show you the various subscription pools associated with your Red Hat account.
sudo subscription-manager list --available
Since the system is not yet registered, you will see an error message indicating that registration is required first.
This system is not yet registered. Try 'subscription-manager register --help' for more information.
This exercise demonstrates the basic usage of subscription-manager for registration and viewing subscription information. While full functionality is limited in this simulated environment, these commands are fundamental for managing software access on RHEL systems.
Explore RPM Package Information
In this step, you will learn how to use the rpm command to investigate software packages. RPM (Red Hat Package Manager) is the core package management system used by Red Hat Enterprise Linux. While dnf (which you'll explore later) is a higher-level tool for managing packages from repositories, rpm allows you to query, verify, install, and uninstall individual .rpm files.
First, let's list all installed RPM packages on your system. This can generate a very long list, so we'll pipe the output to head to see just the beginning.
rpm -qa | head
You will see a list of package names, versions, and architectures. For example:
libgcc-11.4.1-3.el9.x86_64
crypto-policies-20240202-1.git283706d.el9.noarch
tzdata-2024a-1.el9.noarch
subscription-manager-rhsm-certificates-20220623-1.el9.noarch
redhat-release-9.4-0.4.el9.x86_64
setup-2.13.7-10.el9.noarch
filesystem-3.16-2.el9.x86_64
basesystem-11-13.el9.noarch
pcre2-syntax-10.40-5.el9.noarch
ncurses-base-6.2-10.20210508.el9.noarch
Next, let's find out which package provides a specific file. We'll use /etc/yum.repos.d as an example, which is a directory containing DNF repository configuration files.
rpm -qf /etc/yum.repos.d
The output will show you the package that owns this directory.
redhat-release-9.4-0.4.el9.x86_64
Now, let's get detailed information about an installed package. We'll use the dnf package itself as an example.
rpm -qi dnf
This command provides a wealth of information, including the package name, version, release, architecture, size, summary, URL, license, and a detailed description.
Name : dnf
Version : 4.14.0
Release : 9.el9
Architecture: noarch
Install Date: Thu Jul 18 15:50:10 2024
Group : Unspecified
Size : 2425281
License : GPLv2+
Signature : RSA/SHA256, Fri Nov 10 10:14:09 2023, Key ID 199e2f91fd431d51
Source RPM : dnf-4.14.0-9.el9.src.rpm
Build Date : Thu Oct 26 05:20:14 2023
Build Host : x86-64-01.build.eng.rdu2.redhat.com
Packager : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
Vendor : Red Hat, Inc.
URL : https://github.com/rpm-software-management/dnf
Summary : Package manager
Description :
Utility that allows users to manage packages on their systems.
It supports RPMs, modules and comps groups & environments.
You can also list all files installed by a package. This can be useful for understanding what a package places on your system.
rpm -ql dnf | head -n 10
This will show the first 10 files installed by the dnf package.
/usr/bin/dnf
/usr/lib/systemd/system/dnf-makecache.service
/usr/lib/systemd/system/dnf-makecache.timer
/usr/share/bash-completion
/usr/share/bash-completion/completions
/usr/share/bash-completion/completions/dnf
/usr/share/locale/ar/LC_MESSAGES/dnf.mo
/usr/share/locale/bg/LC_MESSAGES/dnf.mo
/usr/share/locale/bn/LC_MESSAGES/dnf.mo
/usr/share/locale/bn_IN/LC_MESSAGES/dnf.mo
To see only the configuration files installed by a package, use the -qc option. Let's check the openssh-clients package.
rpm -qc openssh-clients
This will list configuration files related to SSH clients.
/etc/ssh/ssh_config
/etc/ssh/ssh_config.d/50-redhat.conf
Finally, to view the change log information for a package, use --changelog. This can provide insights into the history of updates and fixes for a package. Let's look at the audit package.
rpm -q --changelog audit | head -n 5
If the package is not installed, you will see an error message:
package audit is not installed
You can try with an installed package instead. For example, with the setup package:
rpm -q --changelog setup | head -n 5
These rpm commands are powerful tools for understanding the packages installed on your system and the files they contain.
Install and Remove Software Packages with DNF
In this step, you will learn how to use dnf (Dandified YUM) to manage software packages. dnf is the default package manager in Red Hat Enterprise Linux 9 and is used for installing, updating, and removing software packages, as well as managing software repositories. It automatically handles dependencies, making software management much easier than with rpm alone.
First, let's list all available and installed packages that have "http" in their name. This will give you an idea of what packages are related to HTTP services.
sudo dnf list 'http*'
You will see a list of packages, indicating whether they are installed or available for installation.
Last metadata expiration check: 0:00:00 ago on Mon Apr 22 08:00:00 2024.
Available Packages
http-parser.i686 2.9.4-6.el9 rhel-9-for-x86_64-appstream-rpms
http-parser.x86_64 2.9.4-6.el9 rhel-9-for-x86_64-appstream-rpms
httpcomponents-client.noarch 4.5.13-2.el9 rhel-9-for-x86_64-appstream-rpms
httpcomponents-core.noarch 4.4.13-6.el9 rhel-9-for-x86_64-appstream-rpms
httpd.x86_64 2.4.51-5.el9 rhel-9-for-x86_64-appstream-rpms
httpd-devel.x86_64 2.4.51-5.el9 rhel-9-for-x86_64-appstream-rpms
httpd-filesystem.noarch 2.4.51-5.el9 rhel-9-for-x86_64-appstream-rpms
httpd-manual.noarch 2.4.51-5.el9 rhel-9-for-x86_64-appstream-rpms
httpd-tools.x86_64 2.4.51-5.el9 rhel-9-for-x86_64-appstream-rpms
Now, let's search for packages that contain "web server" in their name, summary, or description. The search all option is useful for a broader search.
sudo dnf search all 'web server'
This command will return a list of packages that match the search terms.
Last metadata expiration check: 0:00:00 ago on Mon Apr 22 08:00:00 2024.
================== 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
Let's get detailed information about the httpd package, which is the Apache HTTP Server.
sudo dnf info httpd
This will display comprehensive details about the package, including its size, license, and description.
Last metadata expiration check: 0:00:00 ago on Mon Apr 22 08:00:00 2024.
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-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.
Now, let's install the httpd package. You will need sudo privileges for this operation.
sudo dnf install httpd -y
The -y flag automatically answers "yes" to any prompts, which is useful for scripting but use with caution in production environments.
Last metadata expiration check: 0:00:00 ago on Mon Apr 22 08:00:00 2024.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
httpd x86_64 2.4.51-5.el9 rhel-9-for-x86_64-appstream-rpms
1.5 M
Installing dependencies:
apr x86_64 1.7.0-11.el9 rhel-9-for-x86_64-appstream-rpms
126 k
apr-util x86_64 1.6.1-20.el9 rhel-9-for-x86_64-appstream-rpms
106 k
apr-util-bdb x86_64 1.6.1-20.el9 rhel-9-for-x86_64-appstream-rpms
13 k
apr-util-openssl x86_64 1.6.1-20.el9 rhel-9-for-x86_64-appstream-rpms
15 k
httpd-filesystem noarch 2.4.51-5.el9 rhel-9-for-x86_64-appstream-rpms
14 k
httpd-tools x86_64 2.4.51-5.el9 rhel-9-for-x86_64-appstream-rpms
100 k
mailcap noarch 2.1.49-5.el9 rhel-9-for-x86_64-baseos-rpms
36 k
mod_http2 x86_64 1.15.7-5.el9 rhel-9-for-x86_64-appstream-rpms
150 k
redhat-logos-httpd noarch 90.4-1.el9 rhel-9-for-x86_64-appstream-rpms
20 k
Transaction Summary
================================================================================
Install 10 Packages
Total download size: 2.1 M
Installed size: 6.9 M
Downloading Packages:
... (downloading package details omitted) ...
Running transaction
... (installation progress 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
httpd-2.4.51-5.el9.x86_64
httpd-filesystem-2.4.51-5.el9.noarch
httpd-tools-2.4.51-5.el9.x86_64
mailcap-2.1.49-5.el9.noarch
mod_http2-1.15.7-5.el9.x86_64
redhat-logos-httpd-90.4-1.el9.noarch
Complete!
You can verify that httpd is installed by querying rpm:
rpm -q httpd
httpd-2.4.51-5.el9.x86_64
Now, let's remove the httpd package.
sudo dnf remove httpd -y
This will remove the httpd package and any dependencies that are no longer needed by other installed packages.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Removing:
httpd x86_64 2.4.51-5.el9 @appstream 4.7 M
Removing dependent packages:
apr-util-bdb x86_64 1.6.1-20.el9 @appstream 13 k
apr-util-openssl x86_64 1.6.1-20.el9 @appstream 15 k
httpd-filesystem noarch 2.4.51-5.el9 @appstream 14 k
mod_http2 x86_64 1.15.7-5.el9 @appstream 150 k
redhat-logos-httpd noarch 90.4-1.el9 @appstream 20 k
Transaction Summary
================================================================================
Remove 6 Packages
Freed space: 4.9 M
... (transaction progress omitted) ...
Removed:
apr-util-bdb-1.6.1-20.el9.x86_64
apr-util-openssl-1.6.1-20.el9.x86_64
httpd-2.4.51-5.el9.x86_64
httpd-filesystem-2.4.51-5.el9.noarch
mod_http2-1.15.7-5.el9.x86_64
redhat-logos-httpd-90.4-1.el9.noarch
Complete!
You can confirm its removal:
rpm -q httpd
package httpd is not installed
This demonstrates the basic dnf commands for installing and removing software packages.
Manage DNF Software Repositories
In this step, you will learn how to manage DNF software repositories. Repositories are locations where software packages are stored and from which dnf retrieves them. Understanding how to list, enable, disable, and add repositories is crucial for controlling what software is available on your system.
First, let's list all configured DNF repositories and their status (enabled or disabled).
sudo dnf repolist all
You will see a list of repository IDs, names, and their current status.
Not root, Subscription Management repositories not updated
repo id repo name status
ubi-9-appstream-debug-rpms Red Hat Universal Base Image 9 (Debug RPMs) - AppStream disabled
ubi-9-appstream-rpms Red Hat Universal Base Image 9 (RPMs) - AppStream enabled
ubi-9-appstream-source Red Hat Universal Base Image 9 (Source RPMs) - AppStream disabled
ubi-9-baseos-debug-rpms Red Hat Universal Base Image 9 (Debug RPMs) - BaseOS disabled
ubi-9-baseos-rpms Red Hat Universal Base Image 9 (RPMs) - BaseOS enabled
ubi-9-baseos-source Red Hat Universal Base Image 9 (Source RPMs) - BaseOS disabled
ubi-9-codeready-builder Red Hat Universal Base Image 9 (RPMs) - CodeReady Builder enabled
ubi-9-codeready-builder-debug-rpms Red Hat Universal Base Image 9 (Debug RPMs) - CodeReady Builder disabled
ubi-9-codeready-builder-rpms Red Hat Universal Base Image 9 (RPMs) - CodeReady Builder disabled
ubi-9-codeready-builder-source Red Hat Universal Base Image 9 (Source RPMs) - CodeReady Builder disabled
The dnf config-manager command is a powerful tool for managing repository configurations. You can use it to enable or disable repositories. For example, let's try to enable a hypothetical debug repository. While this specific repository might not exist or be accessible in this lab environment, the command demonstrates the syntax.
sudo dnf config-manager --enable rhel-9-server-debug-rpms
You will see messages about subscription management and an error indicating that the repository is not found, which is expected in this environment.
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered with an entitlement server. You can use subscription-manager to register.
Error: No matching repo to modify: rhel-9-server-debug-rpms.
Now, let's try to disable a repository. We'll use rhel-9-for-x86_64-appstream-rpms as an example. Note: This specific repository name doesn't exist in this UBI environment, but the command demonstrates the syntax.
sudo dnf config-manager --disable rhel-9-for-x86_64-appstream-rpms
You will see subscription management messages and an error indicating the repository doesn't exist in this environment.
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered with an entitlement server. You can use subscription-manager to register.
Error: No matching repo to modify: rhel-9-for-x86_64-appstream-rpms.
Let's verify that this repository name doesn't exist in the current system:
sudo dnf repolist all | grep rhel-9-for-x86_64-appstream-rpms
As expected, there will be no output since this repository doesn't exist in the UBI environment.
(no output)
Let's try the same enable command to confirm the repository doesn't exist:
sudo dnf config-manager --enable rhel-9-for-x86_64-appstream-rpms
Again, you'll see the same error message:
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered with an entitlement server. You can use subscription-manager to register.
Error: No matching repo to modify: rhel-9-for-x86_64-appstream-rpms.
The dnf config-manager --add-repo command can also be used to add new repositories by specifying a URL. For demonstration purposes, we will attempt to add a common EPEL (Extra Packages for Enterprise Linux) repository URL. While this might not fully configure the repository (as it often requires a GPG key and a specific .repo file), it shows the command's capability.
sudo dnf config-manager --add-repo="https://dl.fedoraproject.org/pub/epel/9/Everything/x86_64/"
You will see output indicating that a new .repo file has been created.
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered with an entitlement server. You can use subscription-manager to register.
Adding repo from: https://dl.fedoraproject.org/pub/epel/9/Everything/x86_64/
You can inspect the newly created .repo file in /etc/yum.repos.d/. The name of the file will be derived from the URL.
ls /etc/yum.repos.d/
You should see a file like dl.fedoraproject.org_pub_epel_9_Everything_x86_64_.repo along with the existing repository files.
dl.fedoraproject.org_pub_epel_9_Everything_x86_64_.repo redhat.repo ubi.repo
Finally, let's remove the repository configuration file we just added to clean up.
sudo rm /etc/yum.repos.d/dl.fedoraproject.org_pub_epel_9_Everything_x86_64_.repo
This step has shown you how to list, enable, disable, and add DNF repositories, which are essential skills for managing software sources on RHEL.
View DNF Transaction History
In this step, you will learn how to view the transaction history of DNF operations. dnf keeps a detailed log of all package installations, removals, and updates. This history is invaluable for troubleshooting, auditing, and even reverting changes if necessary.
First, let's view the summary of all DNF transactions that have occurred on your system.
sudo dnf history
You will see a table listing each transaction with an ID, the command line used, the date and time, the action(s) performed, and the number of packages altered.
ID | Command line | Date and time | Action(s) | Altered
--------------------------------------------------------------------------------
3 | install httpd | 2024-04-22 08:00 | Install | 10
2 | remove httpd | 2024-04-22 08:01 | Remove | 6
1 | | 2024-04-22 07:50 | Install | 767 EE
The ID column is particularly important, as it allows you to refer to specific transactions. For example, if you want to see detailed information about a specific transaction, you can use dnf history info <ID>. Let's look at the details of the last transaction (which should be the httpd removal from the previous step). You can find the ID from the dnf history output. In the example above, it's 2.
sudo dnf history info 2
This command provides a comprehensive breakdown of the selected transaction, including the packages that were removed, their versions, and the reason for the action.
Transaction ID : 2
Begin time : Mon Apr 22 08:01:00 2024
Begin rpmdb : 777:a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4x5y6z7a8b9c0d1e2f3
End time : Mon Apr 22 08:01:05 2024 (5 seconds)
End rpmdb : 771:a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4x5y6z7a8b9c0d1e2f3
User : labex <labex>
Return Code : Success
Command Line : dnf remove httpd -y
Packages Altered:
Removed apr-util-bdb-1.6.1-20.el9.x86_64
Removed apr-util-openssl-1.6.1-20.el9.x86_64
Removed httpd-2.4.51-5.el9.x86_64
Removed httpd-filesystem-2.4.51-5.el9.noarch
Removed mod_http2-1.15.7-5.el9.x86_64
Removed redhat-logos-httpd-90.4-1.el9.noarch
One of the most powerful features of DNF history is the ability to undo or redo transactions. For example, to undo the httpd removal, you would use dnf history undo <ID>. Let's undo the httpd removal transaction (using the ID from your dnf history output, e.g., 2).
sudo dnf history undo 2 -y
This command will reinstall the httpd package and its dependencies that were removed in that specific transaction.
Last metadata expiration check: 0:00:00 ago on Mon Apr 22 08:00:00 2024.
Undoing transaction 2, from Mon Apr 22 08:01:00 2024
Removed apr-util-bdb-1.6.1-20.el9.x86_64
Removed apr-util-openssl-1.6.1-20.el9.x86_64
Removed httpd-2.4.51-5.el9.x86_64
Removed httpd-filesystem-2.4.51-5.el9.noarch
Removed mod_http2-1.15.7-5.el9.x86_64
Removed redhat-logos-httpd-90.4-1.el9.noarch
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
httpd x86_64 2.4.51-5.el9 ubi-9-appstream-rpms 1.5 M
Installing dependencies:
apr x86_64 1.7.0-11.el9 ubi-9-appstream-rpms 126 k
apr-util x86_64 1.6.1-20.el9 ubi-9-appstream-rpms 106 k
apr-util-bdb x86_64 1.6.1-20.el9 ubi-9-appstream-rpms 13 k
apr-util-openssl x86_64 1.6.1-20.el9 ubi-9-appstream-rpms 15 k
httpd-filesystem noarch 2.4.51-5.el9 ubi-9-appstream-rpms 14 k
httpd-tools x86_64 2.4.51-5.el9 ubi-9-appstream-rpms 100 k
mailcap noarch 2.1.49-5.el9 ubi-9-baseos-rpms 36 k
mod_http2 x86_64 1.15.7-5.el9 ubi-9-appstream-rpms 150 k
redhat-logos-httpd noarch 90.4-1.el9 ubi-9-appstream-rpms 20 k
Transaction Summary
================================================================================
Install 10 Packages
Total download size: 2.1 M
Installed size: 6.9 M
... (installation progress omitted) ...
Complete!
You can verify that httpd is now installed again:
rpm -q httpd
httpd-2.4.51-5.el9.x86_64
Finally, let's remove httpd again to leave the system in a clean state for future labs.
sudo dnf remove httpd -y
... (output omitted) ...
Complete!
This step has demonstrated how to use dnf history to view, inspect, and even revert DNF transactions, providing powerful capabilities for system management.
Summary
In this lab, we learned essential skills for managing software packages on Red Hat Enterprise Linux using DNF. We began by understanding the subscription-manager command, crucial for registering systems with Red Hat and accessing their content delivery network, even though full registration wasn't possible in the simulated environment.
Subsequently, we explored how to query RPM package information, install and remove software using DNF, manage DNF software repositories, and view the DNF transaction history. These steps provided a comprehensive overview of DNF's capabilities for efficient software management.



