Skip to main content

Working with Package Management (RHEL/CentOS)

1. Checking for Updates

Command Description Notes
yum check-update Checks for available updates for all installed packages Shows only packages with newer versions available
yum check-update <package> Checks for updates for a specific package Useful to verify if a particular package has an update available
dnf check-update Checks for available updates using DNF (newer package manager) Replaces yum in newer RHEL/CentOS versions (8+)

Example: Checking for updates for a specific package

yum check-update httpd
Note: On systems where yum is not available, use dnf as the command-line tool for package management.

2. Upgrading Packages

Command Description Notes
yum update Updates all installed packages to the latest versions available in repositories. May upgrade dependencies if needed
yum update <package_name> Updates a specific package to the latest version. Useful for targeted updates
yum update --security Upgrades only packages with security updates. Recommended for production systems
yum update --bugfix Upgrades only packages with bug fixes. Useful for stability improvements

Example: Update a specific package

yum update httpd

Example: Update all packages with security fixes

yum update --security
Note: Before upgrading packages, ensure that the system is backed up or that you have a rollback plan in case of issues.

3. Installing Packages

Command Description Example
yum install Installs one or more packages yum install httpd
yum install <package> <package> Installs multiple packages yum install httpd php mysql
yum install <package> --assumeno Checks what would be installed without actually installing yum install httpd --assumeno

Example: Install Apache Web Server

yum install httpd
Note: Ensure the system is up to date before installing packages using yum update.

4. Removing Packages

Command Description Notes
yum remove Removes specified packages and their dependencies Use with caution as it removes all dependencies that are not required by other packages
yum erase Alias for yum remove Functionally identical to yum remove
dnf remove Removes packages using DNF package manager (RHEL 8+) Default package manager in RHEL 8 and newer

Example: Removing a Package with YUM

yum remove httpd

Example: Removing a Package with DNF

dnf remove httpd
Note: Use yum autoremove or dnf autoremove to remove orphaned dependencies after package removal.
Warning: Removing core system packages can lead to system instability or breakage. Always verify package dependencies before removal.

5. Searching for Packages

Command Description Example
dnf search Searches for packages matching a keyword dnf search httpd
dnf search --all Searches all package metadata for a keyword dnf search --all python
dnf search name:package Searches for packages by name only dnf search name:vim
dnf search description:package Searches for packages by description only dnf search description:web

Example: Search for packages containing "node"

dnf search node

Example: Search all package metadata for "mysql"

dnf search --all mysql
Note: The dnf search command searches in the package name, summary, description, and URL fields.

6. Showing Package Information

Command Description Example
rpm -qi Display information about an installed package rpm -qi vim
rpm -ql List files installed by a package rpm -ql vim
rpm -qf Find which package owns a file rpm -qf /etc/passwd
rpm -qpi Display information about a local RPM file rpm -qpi /path/to/package.rpm
rpm -qpl List files in a local RPM file rpm -qpl /path/to/package.rpm
dnf info Display detailed information about a package dnf info vim
dnf list installed List all installed packages dnf list installed | grep vim
dnf search Search for packages by name or description dnf search vim

Example: Displaying package information

dnf info vim

Example: Listing files in a package

rpm -ql vim

Example: Finding package owner of a file

rpm -qf /etc/passwd

7. Listing Installed Packages

Command Description Example
rpm -qa List all installed RPM packages rpm -qa | grep -i "httpd"
rpm -q Query specific package details rpm -q httpd
yum list installed List all installed packages using YUM yum list installed | grep -i "httpd"
dnf list installed List all installed packages using DNF (RHEL 8+) dnf list installed | grep -i "httpd"
rpm -qa | grep python
Note: On RHEL 8 and later, dnf is the preferred package manager over yum.

8. Cleaning Package Cache

Use dnf clean to remove cached package data, freeing up disk space and ensuring you're working with the latest package information.

Command Description Notes
dnf clean all Removes all cached data including metadata, packages, and headers. Useful for a complete cleanup before updating the system.
dnf clean packages Removes only cached package files (.rpm files). Keeps metadata and headers for faster updates.
dnf clean metadata Removes only cached metadata (repomd.xml, primary.xml, etc.). Keeps downloaded packages, useful for updating without re-downloading packages.
dnf clean expire-cache Expires the cache and forces metadata refresh on next command. Does not delete any files, just marks cache as expired.

Example: Cleaning package cache

# Clean all cached data
sudo dnf clean all

# Clean only package files
sudo dnf clean packages

# Clean only metadata
sudo dnf clean metadata
Note: Running dnf clean all will remove all local cache files, including downloaded RPMs and metadata. This can be useful to free up disk space or resolve issues with outdated package information.

9. Managing Repositories

Repository Type Description Command Notes
Base Repository Primary repository for the OS yum install <span class="highlight">base</span> Usually included in RHEL/CentOS by default
EPEL Extra Packages for Enterprise Linux yum install <span class="highlight">epel-release</span> Provides additional packages not included in base repos
Custom Repository Manually added repository yum-config-manager --add-repo <span class="highlight">URL</span> Useful for third-party software or internal packages

Example: Adding a Custom Repository

yum-config-manager --add-repo https://example.com/repo.repo
Note: After adding a repository, run yum clean all to refresh the cache.

Workflow: Enable a Repository

  1. Use yum repolist all to view all repositories
  2. Enable desired repository with yum-config-manager --enable <repo-name>
  3. Verify with yum repolist enabled

Comparison: YUM vs DNF

  • YUM: Older package manager, still used in CentOS 7 and RHEL 7
  • DNF: Newer, faster, and more feature-rich package manager in CentOS 8+ and RHEL 8+

10. Installing RPM Packages

Command Description Example
yum install Installs one or more RPM packages sudo yum install httpd
yum install <package> --assumeno Simulates installation without actually installing sudo yum install httpd --assumeno
yum install <package> --enablerepo=<repo-name> Installs from a specific enabled repository sudo yum install package-name --enablerepo=epel

Example: Installing a Package

sudo yum install nginx
Note: Ensure you have sufficient privileges (typically root or sudo) to install packages.
Warning: Installing packages may require internet access or local repository configuration.

11. Querying RPM Packages

Command Description Example
rpm -q package_name Query installed packages rpm -q httpd
rpm -ql package_name List files in a package rpm -ql httpd
rpm -qi package_name Display package information rpm -qi httpd
rpm -qf file_path Find which package owns a file rpm -qf /etc/httpd/conf/httpd.conf
rpm -qg group_name List packages in a group rpm -qg "Web Server"
rpm -qa List all installed packages rpm -qa | grep httpd

Example: Find package that owns a file

rpm -qf /etc/passwd
# Output:
# shadow-utils-4.8.1-2.el8.x86_64

Example: List all files in a package

rpm -ql httpd
# Output:
# /etc/httpd/
# /etc/httpd/conf/
# /etc/httpd/conf.d/
# /etc/httpd/conf.modules.d/
# /etc/httpd/conf/httpd.conf
# /etc/httpd/conf/extra/
# /etc/httpd/conf/extra/httpd-ssl.conf
# /etc/httpd/conf/extra/httpd-vhosts.conf
# /etc/httpd/conf/extra/httpd-userdir.conf
# /etc/httpd/conf/extra/httpd-info.conf
# /etc/httpd/conf/extra/httpd-languages.conf
# /etc/httpd/conf/extra/httpd-manual.conf
# /etc/httpd/conf/extra/httpd-mpm.conf
# /etc/httpd/conf/extra/httpd-multilang.conf
# /etc/httpd/conf/extra/httpd-ssl.conf
# /etc/httpd/conf/extra/httpd-userdir.conf
# /etc/httpd/conf/extra/httpd-vhosts.conf
# /etc/httpd/conf/extra/httpd-info.conf
# /etc/httpd/conf/extra/httpd-languages.conf
# /etc/httpd/conf/extra/httpd-manual.conf
# /etc/httpd/conf/extra/httpd-mpm.conf
# /etc/httpd/conf/extra/httpd-multilang.conf

12. Verifying Package Integrity

Command Description Example
rpm --verify Verifies package integrity by checking file checksums and permissions rpm --verify httpd
rpm --checksig Checks the signature of a package file against the system's GPG keys rpm --checksig httpd-2.4.6-80.el7.x86_64.rpm
rpm -K Alias for rpm --checksig, used to verify package signatures rpm -K httpd-2.4.6-80.el7.x86_64.rpm

Example: Verifying Package Integrity

After installing a package, you can verify its integrity using:

rpm --verify httpd

This command compares installed files with the package's original checksums and reports any discrepancies.

Example: Checking Package Signature

To ensure a package is signed by a trusted source:

rpm --checksig httpd-2.4.6-80.el7.x86_64.rpm

If the signature is valid, it will output something like:

httpd-2.4.6-80.el7.x86_64.rpm: rsa sha1 (md5) pgp md5 OK

Was this article helpful?