1. Introduction to
RHEL Package Management
Efficient package management in Linux is
essential to keep your Linux (RHEL) system secure, stable, and up to date. One
of the primary tasks of every Linux system administrator is to install packages
in RHEL, apply critical updates, or safely remove unused software.
Understanding the right tools and the right time to use them is the key.
RHEL provides powerful package
managers DNF and YUM as well as the lower-level RPM utility to handle every
aspect of Red Hat package management.
Your system should be registered with the Red Hat Subscription Manager
to access the official Red Hat repositories and receive new updates before
using DNF or YUM.
This guide explains a step-by-step
procedure to install, update and remove packages from the RHEL, manage
repositories and troubleshoot the common issues.
2. Overview of RHEL
Package Managers: DNF, YUM and RPM
Red Hat Enterprise Linux (RHEL) has a
hierarchy of package managers to manage software installation, removal and
updates. This hierarchy includes DNF, YUM and RPM, each serving a different
role.
What is YUM
(Yellowdog updater)
Yum is a high-level package manager
tool built on top of RPM used to install, remove, list and update packages. It
downloads packages from official repositories, resolves their dependencies
automatically and installs them in the right order. Yum provides commands for
searching, updating, installing and removing packages along with
adding/deleting repositories. Yum was the default package manager for Red Hat
Enterprise Linux till RHEL 7 and CentOS 7.
DNF (Dandified Yum)
DNF is a next-generation package
manager that is a successor of YUM and was introduced in RHEL8 and above. It
has better dependency resolution algorithms, offers improved performance and
fast package management than Yum. Yum is also available in new versions of RHEL
but used as a symbolic link.
Key
Difference between DNF and YUM
A
key difference between DNF and YUM is,
· Dnf is the successor of Yum and is faster
in managing packages than Yum
· Much
secure and modular
· Efficient
in dependency management
·
Better in memory usage
RPM (Red Hat
Package Manager)
RPM is an open source package
management system that comes by default with Red Hat Enterprise Linux
distributions. The name refers to both the package management system itself and
the .rpm file format. RPM is used to install, delete and update individual
packages, but it is not able to resolve dependencies like Dnf and Yum. RPM
maintains a database of installed packages to manage them and the integrity of
packages. It provides independence in managing software packages and helps verify
the integrity of the installed packages. RPM has basic modes of operation like
query, install, erase and show configuration. At least one of these operational
modes needs to be selected to perform package management tasks and every mode
has its own set of installation options.
3. Prerequisites for RHEL Package Management
- System
with RHEL installation
- Terminal
access with root or a user with sudo privileges
- Active
Red Hat subscription
4. Register RHEL System with Red Hat
(Required for DNF/YUM)
Red Hat subscription and registration
is necessary to access the official repositories. The following commands are
used for subscription and registration. For this purpose, terminal access is a
must.
Registration Help
To
see all the subscription and registration-related options
Subscription-manager
--help
Register
Subscription
To
register with Red Hat command is
#subscription-manager
register
It will ask you to enter your username
and password for registration, and upon successful registration, it will return
a message stating that the system has been registered with an ID number and the
registered system name.
Registration
Status
To check the status, system is
registered or not command is
#subscription-manager status
As you can see, the status of my
system registration. It is simple content access. The status command shows the
information according to the type of subscription.
Automatic Subscription Attachment
When this command is executed on a system
registered with Red Hat, it searches for appropriate registration from the
customer account and automatically attaches it to the system. Command is
#subscription-manager attach --auto
5. How to Update Packages in RHEL Using
DNF/YUM
Before installing any software, ensure
that your Red Hat Enterprise Linux system is registered with a Red Hat
subscription and that you have root access or sudo privileges to access the
system. For this guide, we fulfilled all the requirements to install software
packages with dnf/yum. As we have Red Hat Enterprise Linux 9 installed on the
system so we will follow the dnf throughout this guide.
Dnf Version
Let's
start by checking the DNF installed version on the RHEL system.
#sudo
dnf --version
Dnf Help
The
primary purpose of help is to display the available commands and options of
DNF.
#sudo
dnf --help
How to Check Updates
This
command is used to check whether updates are available or not
#sudo
dnf check-update
How
to Update a Package
An update is basically used to refresh
the package repositories and update the installed packages to their new version
if an update is available. As we have seen, updates are available using the
check-update command. Now, run the dnf update command to apply them. To update
a single package, run the update command following the package name.
#sudo dnf update
6. How to Search Packages in RHEL
If you are not sure of the exact package
name, use the search command to find the exact package name.
#sudo
dnf search nginx
7. How to List Packages
To
list a package or group of packages command is
#sudo
dnf list nginx
8. How to Install a Package in RHEL
To
install a package or packages the command is
#sudo
dnf install nginx
Press
y to install or press n to cancel the installation.
9. How to Verify the Installation
To
confirm the installed packages, the command is
#sudo
dnf list installed nginx
10. How to Remove or Uninstall Packages in RHEL
To
remove or uninstall a package the command is
#sudo
dnf remove nginx
11. How to Reinstall a Package
To
reinstall the already installed package for any reason, the command is
#sudo
dnf reinstall nginx
12. How to Auto-Remove Packages
Remove
all unneeded packages that were installed as dependencies. The command is
#sudo
dnf autoremove
13. How to Clean Cache
To
remove cache data, the command is
#sudo
dnf clean expire-cache or all
Managing RHEL Repositories for Package
Management
Repositories are the locations where
software packages are stored that you install with DNF/YUM. By managing these
repos correctly ensure you always have access to the latest updates and
security patches.
1. How to List Repos
To
list the available repos command is
#sudo
subscription-manager repos --list
To list repo with the
DNF command is
#sudo dnf repolist --all
1.
How to Check Enabled Repositories
Check
which repositories are currently active, the command is
#sudo
dnf repolist
2. How to Enable or
Disable a Repository
To
enable the specific repository command is
#sudo
subscription-manager repos --enable=lvms-4.16-for-rhel-9-x86_64-debug-rpms
To
enable the repository with the DNF command is
#sudo
dnf config-manager --set-enable amq-textonly-1-for-middleware-rpms
Disable Repository
To
disable the repository with the subscription-manager command is
#sudo
subscription-manager repos --disable lvms-4.16-for-rhel-9-x86_64-debug-rpms
To
disable with the DNF command is
#sudo
dnf config-manager --set-disable amq-textonly-1-for-middleware-rpms
Tips: Always
keep your system registered with Red Hat to maintain access to official
repositories.
Only
add trusted third-party repositories to avoid security risks.
Using RPM Commands for Advanced Package
Management
Now we see some package management
commands of RPM, such as install, upgrade, check package details and verify
signatures.
1. How to Check RPM Version
Let's
check first the current installed version of RPM. Command is
#sudo
rpm --version
2. RPM Help
RPM help shows all available options
and switches that can be used with the RPM command.
#sudo
rpm --help
3. How to Install a
Package
To
install the package with the rpm command is
#sudo
rpm -ivh at-3.1.23-12.el9_6.x86_64.rpm
4. How to Upgrade a
Package
To
upgrade the package with the rpm command is
#sudo
rpm -Uvh at-3.1.23-12.el9_6.x86_64.rpm
5. How to Verify
All Packages
To
verify all packages that is installed or not, -q is used for query and -a or --all is used for all packages. Command is
#sudo
rpm -qa
6. How to Verify a
Specific Package
To
verify a specific package command is
#sudo
rpm -q at
7. How to List
Files Installed by a Package
To
list a package's files, -l or --list is used with the rpm command.
#sudo
rpm -ql at
8. How to Query a
File
Query
a file that you don’t know from which package it belongs. Command is
#sudo
rpm -qf /usr/bin/batch
9. How to View a
Package Detail
If
you don’t know what the package does. Use this command to find information
about it.
#sudo
rpm -qip at-3.1.23-12.el9_6.x86_64.rpm
10. How to List All
Keys
To
display the list of all keys that are installed for the RPM verification
command is
#sudo
rpm -qa gpg-key*
11. Check GPG
Signature before Installation
If
you have downloaded .rpm file manually, verify its signature first with this
command.
#sudo rpm --checksig at-3.1.23-12.el9_6.x86_64.rpm
12. How to Remove a
Package
To
remove a package with rpm command is
#sudo
rpm -e at-3.1.23-12.el9_6.x86_64.rpm
Troubleshooting Common RHEL Package
Management Issues
Sometimes,
using DNF, YUM, or RPM, you encounter errors related to missing dependencies or
broken repository issues. Follow
these steps to diagnose and fix them.
1. Clean and
Rebuild the Package Cache
Sometimes
metadata is outdated. Refresh it with these commands. #sudo
dnf clean all
#sudo dnf makecache
2. Check for
Missing or Conflicting Dependencies
To
check missing or conflicting dependencies command is
#sudo
dnf check
It
reports if anything is missing or conflicting. If it reports any specific
package, try this command to resolve the issue automatically.
#sudo
dnf install --best --allowerasing at
3. Disable or
Remove Problematic Repositories
List
all repos and remove or disable the problematic repository with the command
#sudo
subscription-manager repos --disable=repo-name
Resolve GPG Key and Repository Problems
An
outdated and missing GPG key can block package installation.
1. Import Red Hat
GPG Key
RHEL
system includes gpg key. Reimport if needed.
#sudo
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
2. Manually Add a
Repository Key
If
you add a third-party repository, obtain its key and import it manually.
3. Verify
Repository File
Ensure
.repo file in /etc/yum.repos.d/ has correct gpgcheck=1 and a valid gpgkey URL.
Best Practices for RHEL Package Management
*
Regular system updates for security
*
Cache cleaning with dnf clean all
*
Verifying package sources and signatures
Conclusion
Efficient package management in RHEL is a
key to keeping your Red Hat Enterprise Linux servers secure and running smoothly.
When you register your system with Red Hat, keep your repositories organized
and use DNF, YUM or RPM to install, update or remove software, then you are
confident that every package is current and verified.
Staying up to update, managing the
repositories carefully and checking the package signatures will help you to
avoid the dependency issues and potential security problems. By these habits,
you can maintain a secure RHEL environment and concentrate on the
applications and services.
Keep visiting seeklinux for more
information and updates.
Post a Comment