Kiến Thức Linux

How to Clean YUM Cache

How to Clean YUM Cache

Introduction

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

Prerequisites

  • 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.

Conclusion

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.

Đăng ký liền tay Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !

Add Comment

Click here to post a comment

Đăng ký liền tay
Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !