Mastering Software Package Management with Yum and DNF on CentOS and RHEL
Introduction
Software package management is an essential skill for any system administrator working with Linux distributions such as CentOS and RHEL (Red Hat Enterprise Linux). Managing software efficiently ensures that your system remains secure, up-to-date, and optimized for performance.
CentOS and RHEL utilize two primary package managers: Yum (Yellowdog Updater, Modified) and DNF (Dandified Yum). While Yum has been the default package manager in older versions (CentOS/RHEL 7 and earlier), DNF replaces Yum starting from CentOS 8 and RHEL 8, offering improved performance, dependency resolution, and better memory management.
In this guide, we will explore every aspect of software package management using Yum and DNF, from installing, updating, and removing packages to managing repositories and handling dependencies.
Understanding Yum and DNF
What is Yum?Yum (Yellowdog Updater, Modified) is a package management tool that helps users install, update, and remove software packages on CentOS and RHEL systems. It manages software dependencies automatically, ensuring that required libraries and dependencies are installed along with the package.
What is DNF?DNF (Dandified Yum) is the next-generation package manager introduced in CentOS 8 and RHEL 8. It provides faster package management, better memory efficiency, and improved dependency resolution compared to Yum. Although Yum is still available in newer versions, it acts as a symbolic link to DNF.
Key advantages of DNF over Yum:
-
Improved performance and speed
-
Reduced memory usage
-
Better dependency management
-
Enhanced security and modularity
Checking and Updating Package Repositories
Before installing or updating software, it is good practice to ensure that the system package repositories are up to date.
Using Yum (CentOS/RHEL 7 and Earlier)
yum check-update
yum update
Using DNF (CentOS/RHEL 8 and Later)
dnf check-update
dnf update
The update
command refreshes package lists and ensures that installed software is up to date.
Installing Software Packages
Software packages can be installed from official or third-party repositories.
Using Yum
yum install package-name
Using DNF
dnf install package-name
Example:
dnf install httpd -y # Installs Apache web server
The -y
flag automatically confirms the installation without user intervention.
Removing Software Packages
If a package is no longer needed, you can remove it to free up system resources.
Using Yum
yum remove package-name
Using DNF
dnf remove package-name
Example:
dnf remove httpd -y # Removes Apache web server
Searching for Software Packages
If you do not know the exact package name, you can search for it in the repository.
Using Yum
yum search package-name
Using DNF
dnf search package-name
Example:
dnf search nginx # Searches for Nginx packages
Listing Installed Packages
To list all installed packages on the system, use the following commands.
Using Yum
yum list installed
Using DNF
dnf list installed
Example:
dnf list installed | grep httpd # Check if Apache is installed
Viewing Detailed Package Information
To retrieve detailed information about a package, such as version, repository, and description:
Using Yum
yum info package-name
Using DNF
dnf info package-name
Example:
dnf info vim # Get information about the Vim text editor
Managing Software Groups
Some software packages are grouped together for easier installation.
List Available Groups
dnf group list
Install a Group
dnf group install "Development Tools" -y
Remove a Group
dnf group remove "Development Tools" -y
Handling Package Dependencies
Checking Dependencies
dnf deplist package-name
Removing Unused Dependencies
dnf autoremove
This command removes orphaned dependencies that are no longer required by installed packages.
Clearing Package Cache
To free up disk space or resolve repository issues, clear the package cache.
Using Yum
yum clean all
Using DNF
dnf clean all
Enabling and Disabling Repositories
To enable or disable a repository temporarily:
dnf --enablerepo=repository-name install package-name
dnf --disablerepo=repository-name install package-name
To permanently enable or disable a repository, edit the repository files in /etc/yum.repos.d/
.
Using DNF Transaction History
DNF keeps track of all transactions, making it easy to undo changes.
View Transaction History
dnf history
Undo a Transaction
dnf history undo transaction-id
Rollback to a Previous State
dnf history rollback transaction-id
Installing Local RPM Files
To manually install a package using a .rpm
file:
yum localinstall package.rpm
Using DNF
dnf install package.rpm
Checking and Applying Security Updates
Check Available Security Updates
dnf updateinfo list security
Apply Security Updates Only
dnf update --security
Conclusion
Managing software packages efficiently is crucial for system administrators using CentOS and RHEL. While Yum has been a trusted package manager for years, DNF provides significant improvements in performance and security. By mastering these commands, you can efficiently install, update, and manage software packages, ensuring the stability and security of your Linux system.
George Whittaker is the editor of Linux Journal, and also a regular contributor. George has been writing about technology for two decades, and has been a Linux user for over 15 years. In his free time he enjoys programming, reading, and gaming.