How to clear the Yum cache

July 5, 2024 / Servers, Hosting & Email

This guide explains how to clear the YUM cache on RHEL-based systems. When packages are downloaded, installed, or removed, cached files may remain on the server. Over time, these cached files can consume disk space or cause issues during package updates.

Clearing the YUM cache helps free up disk space and ensures your system saves fresh package data from repositories.

When Should You Clear the YUM Cache?

You should consider cleaning the YUM cache in the following situations:

  • When disk space is running low.
  • Before or after installing or updating packages.
  • If you face repository or package installation errors.
  • After removing large packages that may have left cached data behind.

Benefits of Clearing the YUM Cache

  • Frees up unused disk space
  • Prevents issues caused by outdated or corrupted metadata
  • Confirms YUM fetches the latest package information
  • Improves reliability during package installations and updates

How to Clear the YUM Cache?

Log in to the server as the root user and run the appropriate command based on your requirement.

  1. Remove Cached Packages Only
    This deletes downloaded RPM packages but keeps metadata.

    yum clean packages
  2. Remove Cached Headers
    This clears old package header information.

    yum clean headers
  3. Remove Cached Metadata
    This deletes repository metadata stored locally.

    yum clean metadata
  4. Remove All Cached Data (Recommended)
    This clears all cached packages, headers, and metadata.

    yum clean all

Important Note About DNF

While YUM is still used on older RHEL and CentOS versions (such as CentOS 7), DNF is the modern package manager used on newer systems like RHEL 8/9, AlmaLinux, Rocky Linux, and CentOS Stream.

DNF supports the same cache-cleaning commands. For example:

dnf clean all

The behaviour and benefits remain the same when using DNF.

Clearing the YUM (or DNF) cache is a simple maintenance task that can help recover disk space and avoid package management issues. It is safe to perform and does not affect installed software.

Was this guide helpful?
If you encounter any issues or need assistance, please contact our support team.

Discover our guide on Installing Updates on Unmanaged Servers.

Spread the love