How To Clear Yum Cache on Centos 7

This guide intends to show you to Clear Yum Cache on Centos 7.

When you perform an operation such as (yum install package), Yum downloads the packages to install into the Yum cache. The cached packages are located in a subdirectory structure from /var/cache/yum that reflects the architecture, the distribution release, and the repository from where the packages were downloaded.

You can clean the Yum cache to reclaim the disk space.

Steps To Clear Yum Cache on Centos 7

To complete this guide, you must log in to your server as a root or non-root user with sudo privileges. To do this, you can follow this guide on Initial Server Setup with Centos 7.

List Enabled Repositories on Centos 7

Before cleaning the Yum cache, it’s important to know which repositories are enabled on the Centos system. To list all the enabled repositories, you can use the following command:

yum repolist enabled
Output
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                     |  19 kB     00:00
 * base: mirrors.chroot.ro
 * epel: mirror.efect.ro
 * extras: mirrors.chroot.ro
 * updates: mirrors.chroot.ro
epel                                                     | 4.7 kB     00:00
(1/3): epel/x86_64/group_gz                                |  99 kB   00:00
(2/3): epel/x86_64/updateinfo                              | 1.0 MB   00:00
(3/3): epel/x86_64/primary_db                              | 7.0 MB   00:00
repo id               repo name                                           status
base/7/x86_64         CentOS-7 - Base                                     10,072
epel/x86_64           Extra Packages for Enterprise Linux 7 - x86_64      13,771
extras/7/x86_64       CentOS-7 - Extras                                      515
updates/7/x86_64      CentOS-7 - Updates                                   4,886
repolist: 29,244

From your output, you can see all the enabled repositories. Here target one of them which is the Epel repo.

Clean yum Cache Repo on Centos 7

At this point, you can clear the cache for all enabled repositories, including any untracked repositories. To do this, run the following command:

yum clean all
Output
Loaded plugins: fastestmirror
Cleaning repos: base epel extras updates
Cleaning up list of fastest mirrors

This command removes all cached data from the yum cache. It cleans the metadata and packages for all enabled repositories.

To clean the cache for a specific repository, you can use the following command:

yum –enablerepo=<reponame> clean all

Finally, you can verify your list of repositories with the command below:

yum repolist

From the output you get, you can see that untracked repositories have been removed from the system.

Conclusion

At this point, you have learned to Clear Yum Cache on Centos 7.

Hope you enjoy it. You may be interested in these articles:

Install and Configure OpenNMS on Centos 7

How To Install OpenJDK 17 on Centos 7

How To Install OpenSSL 3 on Centos 7

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Stay informed and not overwhelmed, subscribe now!