How to Clean YUM Cache

February 14, 2023


YUM (Yellowdog Updater, Modified) is a package manager for RPM-based distributions. While YUM is a powerful tool for managing packages and dependencies, the utility sometimes caches a lot of data, taking up disk space.

This tutorial explains how to clean YUM cache and keep the system running smoothly.

How to Clean YUM Cache


  • A Linux system with YUM installed (this tutorial uses CentOS 7).
  • Access to the terminal.
  • Sudo permissions.

How to Clear YUM Cache?

When a user installs a package, YUM downloads and stores it in /var/cache/yum. However, packages remain in cache even after they've been installed and removed. In time, the stored cache may take up too much disk space or cause issues due to corrupt metadata.

To reclaim disk space, use the following methods to clear the YUM cache.

1. Clean Cached YUM Packages

Run the following command to purge all cached packages from the enabled repositories cache directory:

sudo yum clean packages
sudo yum clean packages terminal output

The command lists the repos it goes through and deletes cached packages..

2. Clean Package Headers

When YUM updates the local cache, it downloads the package headers and stores them as xml metadata in /var/cache/yum.

To delete cached package headers, run:

sudo yum clean headers
sudo yum clean headers terminal output

3. Delete Metadata for Each Enabled Repository

YUM uses metadata, such as the package name, version, and dependencies, to manage and update packages.

Clean cached metadata from each enabled repository with:

sudo yum clean metadata
sudo yum clean metadata terminal output

4. Clean All Cached Files

Remove all cached files from all enabled repositories at once with:

sudo yum clean all
sudo yum clean all terminal output

The "Metadata File Does not Match Checksum" Error

Deleting YUM cache can help resolve issues with corrupt metadata. However, if you receive the "Metadata file does not match checksum" error, cleaning the YUM cache might not help resolve it. As an alternative solution, disable YUM package caching.

1. Open the /etc/yum.conf file using a text editor.

nano /etc/yum.conf 

2. Find and edit http_caching=packages to http_caching=none.

3. Save and exit the file.

Complete the YUM operation that invoked the error and revert the settings in the YUM configuration file once complete.


After reading this tutorial, you know how to clean the YUM cache with the clean command. Next, learn how to create local YUM repositories in CentOS.

Was this article helpful?
Sara Zivanov
Sara Zivanov is a technical writer at phoenixNAP who is passionate about making high-tech concepts accessible to everyone. Her experience as a content writer and her background in Engineering and Project Management allows her to streamline complex processes and make them user-friendly through her content.
Next you should read
YUM vs. APT: What's the Difference?
November 24, 2022

APT and YUM are two popular package managers. This article shows their similarities and differences, and presents examples of basic package management...
Read more
RPM vs. YUM: Learn the Difference
February 9, 2022

This article explains the difference between two Red Hat-based Linux package managers - RPM and YUM. See the key differences to help you decide which one to use...
Read more
How to List Installed Packages on CentOS with Yum or RPM
April 29, 2019

Managing a CentOS operating system often means knowing the software packages that are installed on the...
Read more
How to Uninstall or Remove Packages from CentOS
October 4, 2019

Once you have installed a package, it may be necessary to find and remove unneeded software and dependencies...
Read more