RHEL 9 Package Management Guide: How to Install, Update & Remove Packages

RHEL Package Management Guide: How to Install, Update and Remove Packages

1. Introduction to RHEL Package Management
Efficient package management in Linux is crucial for keeping your Linux (RHEL 9) 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 knowing when to use them is 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 9, manage repositories and troubleshoot the common issues. All the commands are tested on a RHEL 9.4 system. At the end, you'll have a solid understanding of RHEL 9 package management.


2. Overview of RHEL 9 Package Managers: DNF, YUM and RPM

Red Hat Enterprise Linux (RHEL 9) 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, By Default in RHEL 9)

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. For most administrators DNF is sufficient but knowing RPM is essential for debugging and manual installation.


3. Prerequisites for RHEL 9 Package Management
  • System with RHEL 9.4  installation
  • Terminal access with root or a user with sudo privileges
  • Active Red Hat subscription
4. Register RHEL 9 System with Red Hat (Required for DNF/YUM)

Red Hat subscription and registration is mandatory 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, registration help is a valuable tool for administrators. It provides instant help in command execution and to rectify any mistakes in the syntax of the command.
Subscription-manager --help
Red Hat registration help illustration showing steps to register a RHEL system for software updates and support.

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.

subscription-manager register command to register with Red Hat for Download packages and Updates.

Registration Status
To check the status, system is registered or not command is
#subscription-manager status
Subscription-manager Status command to check the registration status of System

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
Subscription-manager attach auto command is used to attach available customer subscription automatically.

5. How to Update Packages in RHEL 9 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 --version command is used to check the installed version of DNF packag manager on RHEL.version of

Dnf Help
The primary purpose of help is to display the available commands and options of DNF.
#sudo dnf --help
DNF help displays the available options and commands of DNF.

How to Check Updates 
This command is used to check whether updates are available or not
#sudo dnf check-updatednf check-update command is used to check the available package updates for Red Hat Enterprise System.

How to Update All Packages
To update every package on your system to the latest version.
#sudo dnf update -y

The -y flag automatically answers "yes" to prompts.
This ensures your system receives the latest security patches.

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. Always run updates in the staging environment first before applying to production servers.

#sudo dnf update nginx
DNF command to update software package on RHEL system.

Apply Only Security Update
Red Hat provides security metadata, allowing you to install only the critical patches
#sudo dnf update --securityApplying only security updates in RHEL 9 using dnf --security option

View Update History
Want to confirm what was updated or roll back a change? Use:
#sudo dnf historyTerminal displaying "sudo dnf history" command to view update history in RHEL 9

Rollback to Previous Package Version
If a new update causes issues, you can revert to a previous version:
#sudo dnf downgrade nginx
Terminal showing "sudo dnf history rollback" command to return to a previous package state in RHEL 9

Pro Tip: On production servers, many admins prefer to run updates during maintenance windows. You can automate this using a cron job.

With these update strategies, you’ll keep your RHEL 9 system secure while maintaining control over when and how changes are applied.

Difference between DNF Update and Upgrade
In RHEL 9, dnf update and dnf upgrade are functionally the same. However, upgrade removes obsolete packages while update keeps them. For most Admins, they behave identically.

6. How to Search Packages in RHEL 9

Software searching is one of the most common tasks when working with RHEL 9. Instead of guessing the package names, the DNF command gives you several ways to explore what's available in your repositories. Below are the practical examples you can use in real-world scenarios.

Basic Search
If you are not sure of the exact package name, use the search command to find the exact package name.
#sudo dnf search nginx
How to search a package on RHEL system.

This command will list all packages related to nginx, whether the word appears in the name or description.

Search Installed vs Available Package 
You can check if any package is already installed or only available in the repos.
#dnf list --installed nginx
#dnf list --available nginxSearching for installed versus available packages in RHEL 9 with dnf list installed and dnf list available commands

Search With Wildcards
Wildcards help when you are not sure of the complete package name.
#sudo dnf search ‘httpd*’Example of using wildcard characters in RHEL 9 to find related software packages with dnf search

Combine with Grep for Filtering
A faster way to refine search results, pipe the output with grep
#sudo dnf list --installed | grep gccTerminal showing package search in RHEL 9 using dnf list combined with grep filter

This is useful when you have a large number of packages installed and only need a specific one.

Tip: Before searching, refresh your repository metadata with dnf makecache to get accurate results.
By using these variations, you can quickly find the right packages, discover dependencies and troubleshoot software issues on the RHEL 9 system. 
 
7. How to List Packages in RHEL 9
When you already know the package name but want the details, such as version and repository.  To list a package or group of packages, the command is
#sudo dnf list nginx
How to list packages on RHEL system with DNF.

8. How to Install a Package in RHEL 9
To install a package or packages the command is
#sudo dnf install nginx
How to install a package on RHEL system with DNF command.

Press y to install or press n to cancel the installation.

9. How to Verify the Installation in RHEL 9
To confirm the installed packages, the command is
#sudo dnf list installed nginx
How to Verify the package installation on RHEL

10. How to Remove or Uninstall Packages in RHEL 9
To remove or uninstall a package, the command is
#sudo dnf remove nginx
DNF command to remove or uninstall software packages from an RHEL system.

Remove Multiple Packages at Once
You can remove more than one package in a single command:
Removing multiple software packages at the same time in RHEL 9 with dnf remove command

Check Which Packages Depend on the One You’re Removing
Before uninstalling, it’s good practice to see what else depends on that package:
#sudo dnf repoquery --whatrequires nginx
Checking which packages depend on the one being removed in RHEL 9 using dnf remove with dependency details

This prevents you from accidentally breaking other applications.

Remove Package Groups
RHEL 9 allows group-based removal (e.g., Desktop Environment, Development Tools):
#sudo dnf groupremove “Development Tools”
Terminal showing removal of a package group in RHEL 9 using dnf groupremove

This removes all packages associated with that group if they are installed.

Simulate a Removal (Dry Run)
Worried about breaking dependencies? You can simulate the removal process before applying it:
#sudo dnf remove nginx --assumeno
Running a dry run of package removal in RHEL 9 with dnf remove --assumeno to preview changes without uninstalling

Tip: On production systems, always double-check before removing packages. Use the dry run option (--assumeno) to preview changes, and make sure you don’t remove libraries that critical applications depend on.

11. How to Reinstall a Package in RHEL 9
To reinstall the already installed package for any reason, the command is
#sudo dnf reinstall nginx
How to reinstall a package on RHEL system.

12. How to Auto-Remove Packages in RHEL 9
Remove all unneeded packages that were installed as dependencies. The command is
#sudo dnf autoremove 
How to auto-remove packages from RHEL system.

13. How to Clean Cache in RHEL 9
To remove cache data, the command is
#sudo dnf clean expire-cache or all
How to clean cache on Red Hat Enterprise Linux system.

Managing RHEL 9 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
This command lists all the available repos for RHEL 9 as shown in the screenshot. It helps to get Repo ID, Repo Name, Repo URL and the status of the repo like Enabled or Disabled.
#sudo subscription-manager repos --listHow to list available repos with subscription manager command on RHEL system.

The DNF command is also showing the same information as repo Id, repo name and status.

#sudo dnf repolist --allHow to list repos with dnf command on RHEL system.


1. How to Check Enabled Repositories

This command is used to check the enabled repositories in RHEL 9 as shown in the screenshot.

#sudo dnf repolist

How to check enabled repositories with dnf on RHEL system.

2. How to Enable or Disable a Repository
To enable the specific repository in RHEL 9 using the subscription manager command is
#sudo subscription-manager repos --enable=lvms-4.16-for-rhel-9-x86_64-debug-rpms
How to enable a repository with subscription manager command on RHEL system.
DNF command is also used to enable repositories but the command syntax is different than subscription manager.
#sudo dnf config-manager --set-enable amq-textonly-1-for-middleware-rpms
How to enable a repository with dnf command on RHEL system.

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
How to disable a repository with subscription manager command on RHEL system.
The same action is performed using the DNF command to disable the repository as shown in the screenshot.
#sudo dnf config-manager --set-disable amq-textonly-1-for-middleware-rpms
How to disable a repository with dnf command on RHEL system.

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.

Managing Packages with RPM in RHEL 9
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 --versionHow to check the installed rpm version on RHEL system.
2. RPM Help
RPM help shows all available options and switches that can be used with the RPM command. Help is handy in removing instant errors in command syntax, execution and instructs to use the correct format.
#sudo rpm --help
How to get rpm help for available commands and options on RHEL system.

3. How to Install a Package
 The rpm -ivh command is used to install the package as shown in the screenshot. It is also showing that two versions of at package are installed and the file /usr/bin/at is conflicting with the two package versions. This issue can be resolved by removing the lower version of the package.
#sudo rpm -ivh at-3.1.23-12.el9_6.x86_64.rpm
How to install a package with RPM command on RHEL system.

  • -i install
  • -v verbose
  • -h show progress with hash marks

4. How to Upgrade a Package
The rpm -Uvh command is used to update the installed package. It will update the installed package if the update of that package is available and replace it with the newer one. As shown in the screenshot, it is installing the latest version of at and removing the old package.
#sudo rpm -Uvh at-3.1.23-12.el9_6.x86_64.rpmHow to upgrade a package with RPM command on RHEL system.

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, as shown in the screenshot. Command is
#sudo rpm -qaHow to verify all package with RPM command on RHEL system.

6. How to Verify a Specific Package
To verify a specific package same command is used but following the package name as shown in the screenshot.
#sudo rpm -q at
How to verify a specific package with RPM command on RHEL system.

7. How to List Files Installed by a Package
To list files installed by the package, -l or --list is used with the rpm command as shown in the screenshot the list of files that are installed by at package.
#sudo rpm -ql at
How to list files installed by a package with RPM command on RHEL system.

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
How to query a file to know from which package it belongs.

9. How to View a Package Detail
If you don’t know what the package does. Use this command to find the detailed information about this package as shown in the screenshot. It is showing the name of the package at, its version, release, its architecture, size and description about this package for what purpose it is used.
#sudo rpm -qip at-3.1.23-12.el9_6.x86_64.rpm
How to view a package detail with RPM command on Red Hat Enterprise Linux system.

10. How to List All Keys
To display the list of all keys that are installed for the RPM verifications as shown in the screenshot. command is
#sudo rpm -qa gpg-key*
How to list all keys for installed package verification with RPM command on RHEL system.

11. Check GPG Signature before Installation
If you have downloaded .rpm file manually, verify its signature first with this command for the validity and security as shown in the screenshot signature is ok.
#sudo rpm --checksig at-3.1.23-12.el9_6.x86_64.rpm
How to check package signatures before installation with RPM command on RHEL system.
12. Verifying File Integrity
RPM can check if any files from a package have been modified or corrupted:
#sudo rpm –V at

If files differ, it shows output like 5 (checksum mismatch) or T (timestamp mismatch).
Example use case: after a system compromise or accidental file edits, you can verify whether critical packages were altered.

13. 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
How to remove a package with RPM command on RHEL system.

When to Use RPM vs DNF
  • Use DNF for daily installs, updates, and dependency management.
Use RPM when you:
  • Install packages not available in repos (third-party .rpm files).
  • Need detailed queries about files/config.
  • Verify integrity or troubleshoot file issues.
Troubleshooting Common RHEL 9 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. First, clean the all cache, then run makecache to rebuild the package cache. These commands free up space and refresh the metadata.
#sudo dnf clean allHow to clean cache with RPM command on Red Hat Enterprise Linux system.
#sudo dnf makecache
How to make cache with RPM command on Red Hat Enterprise Linux system.

2. Check for Missing or Conflicting Dependencies
To check missing or conflicting dependencies command is
#sudo dnf checkHow to check the missing or conflicting dependencies with dnf command on Red Hat Enterprise Linux system.
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
How to install best available package with dnf command on Red Hat Enterprise Linux system.

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
How to disable or remove a problematic repository with subscription manager on RHEL system.

Resolve GPG Key and Repository Problems in RHEL 9
An outdated and missing GPG key can block package installation.

1. Import Red Hat GPG Key
RHEL system includes gpg key. Sometimes it gives a GPG key error. to remove this error, reimport the GPG key if needed.
#sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
How to import GPG Keys with RPM command on Red Hat Enterprise Linux system.

2. Manually Add a Repository Key
If you add a third-party repository, obtain its key and import it manually.
#sudo rpm --ipmort https://example.com/key.gpg

3. Verify Repository File
Ensure .repo file in /etc/yum.repos.d/ has correct gpgcheck=1 and a valid gpgkey URL.
How to verify the repository file (.rpm) in its location on RHEL system.

Best Practices for RHEL 9 Package Management
* Regular system updates for security.
* Use the subscription manager to manage the repo cleanly.
* Keep backups before kernel or critical package upgrades.
* Monitor /var/log/dnf.log for troubleshooting.
* Cache cleaning with dnf clean all
* Verifying package sources and signatures
* Document version locks and exclusions to avoid confusion.

FAQs
1. What package manager does RHEL 9 use?
RHEL 9 uses DNF as the default package manager and RPM as a low-level tool.

2. Can I still use YUM in RHEL9?
Yes, but YUM is now just a wrapper for DNF. All commands are redirected to DNF.

3. How do I install packages without a Red Hat subscription?
You can enable third-party repositories like EPEL, but official RHEL repos require a subscription.

4. How do I check which packages are installed in RHEL9?
#dnf list installed

5. What is the difference between DNF and RPM?
DNF resolves dependencies automatically, while RPM is a low-level tool for managing individual .rpm files.

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

Previous Post Next Post