Understanding Yum and Rpm in CentOS
Introduction to Yum and Rpm
Yum (Yellowdog Updater, Modified) and Rpm (Red Hat Package Manager) are essential tools for software package management in Linux systems, particularly in CentOS and other Red Hat-based distributions.
Rpm Package Manager
Rpm serves as the fundamental package management tool in Red Hat and its derivative distributions like CentOS and Fedora. It enables administrators to manage software packages on the local system, facilitating installation, upgrading, querying, and removal of packages. Rpm packages contain binary files, configuration settings, documentation, and other necessary components for software operation.
Yum: An Advanced Package Management Solution
Yum represents a higher-level package management tool built on top of Rpm. It streamlines the process of software package installation and updates by automatically resolving dependencies and fetching required packages from configured repositories. Yum simplifies system administration by handling the complex task of dependency resolution automatically.
Relationship Between Yum and Rpm
The relationship between Yum and Rpm is hierarchical and complementary:
- Yum utilizes Rpm-formatted packages as its foundation for installations and updates
- Yum downloads Rpm packages from configured repositories and employs Rpm commands for installatoin
- Yum extends Rpm's capabilities with features like dependency resolution, repository management, and group operations
Essentially, Yum acts as an advanced wrapper around Rpm, providing enhanced functionality and convenience for system administrators.
Essential Yum Commands
Here are the most frequently used Yum commands for package management:
# Package installation and removal
yum install package_name # Install a specific package
yum remove package_name # Remove a specific package
# System updates
yum update # Update all packages on the system
yum update package_name # Update a specific package
yum check-update # List all available updates
# Package information and search
yum list # Display available packages
yum list installed # Show installed packages
yum search keyword # Search for packages containing a keyword
yum info package_name # Display detailed package information
# Cache management
yum clean all # Clear all yum caches
yum makecache # Regenerate package metadata cache
# Repository management
yum-config-manager --enable repository_name # Activate a repository
yum-config-manager --disable repository_name # Deactivate a repository
yum repolist # List all configured repositories
yum deplist package_name # Show package dependencies
Installing Local Rpm Packages
The Yum localinstall command allows adimnistrators to install Rpm packages directly from local file systems rather than downloading from remote repositories:
yum localinstall /path/to/package.rpm
During installation, Yum attempts to resolve package dependencies. If dependencies are unavailable, the process may fail with appropriate error messages.
Updating Packages While Excluding the Kernel
In certain scenarios, administrators may want to update all packages while preserving the current kernel version. This can be achieved through two methods:
Method 1: Using Command Line Exclusion
yum --exclude=kernel* --exclude=centos-release* -y update
Method 2: Modifying Configuration File
Edit the /etc/yum.conf file and add the following lines under the [main] section:
exclude=kernel*
exclude=centos-release*
Distinguishing Between Yum Update and Yum Upgrade
By default, yum update and yum upgrade perform identical functions, updating all packages (including regular software, system versions, and kernels) to the latest versions available in repositories. The key difference lies in handling obsolete packages:
- Yum upgrade removes obsolete packages during the update process
- Yum update retains obsolete packages by default (though this behavior can be modified)
The upgrade functionality is equivalent to running yum update with the obsoletes option enabled. In standard CentOS configurations, obsoletes is enabled by default in /etc/yum.conf, making both commands behave identically regarding kernel updates.
For environments requiring strict compatibility, administrators should prefer yum update with obsoletes disabled in /etc/yum.conf (set to 0) to prevent removal of potentially critical packages. However, caution is advised when modifying update behavior in production environments.
Managing Yum Cache
Yum stores downloaded packages in the /var/cache/yum directory by default. Understanding cache management commands is essential for maintaining efficient system operations:
yum clean all # Remove all cached packages, metadata, and other data
yum clean packages # Only remove cached packages, preserving other data
yum makecache # Regenerate package metadata and repository information
Yum Configuration File Example
The primary Yum configuration file is located at /etc/yum.conf. Below is an annotated example of its main sections:
[main]
cachedir=/var/cache/yum/$basearch/$releasever
# Specifies the directory for storing downloaded packages
# $basearch is replaced with system architecture (e.g., x86_64)
# $releasever is replaced with the CentOS version number
keepcache=0
# Determines whether to retain downloaded packages after installation
# 0 = delete after installation, 1 = retain
debuglevel=2
# Sets the verbosity of debugging information
# Higher values produce more detailed logs
logfile=/var/log/yum.log
# Path to the Yum log file
exactarch=1
# Requires exact architecture matching for packages
# 1 = enforce exact match, 0 = allow compatible architectures
obsoletes=1
# Controls handling of obsolete packages during updates
# 1 = remove obsolete packages, 0 = preserve them
gpgcheck=1
# Enables GPG signature verification for packages
# 1 = verify signatures, 0 = skip verification
plugins=1
# Enables Yum plugins
# 1 = enable plugins, 0 = disable plugins
installonly_limit=5
# Maximum number of installed versions of a package
# Particularly relevant for kernel packages
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
# URL for the CentOS bug tracking system
distroverpkg=centos-release
# Package name that contains distribution version information