Share your love
2 Best Steps To Clear DNF and Yum Cache

This guide intends to show you How To Clear DNF and Yum Cache on Centos / AlmaLinux / Rocky Linux. When you operate such as (yum install package or dnf install package), both Yum and DNF download the packages to install into the Yum or DNF cache. The cached packages are located in a subdirectory structure from /var/cache/yum and /var/cache/dnf that reflects the architecture, the distribution release, and the repository from where the packages were downloaded.
You can clean easily Clear DNF and Yum Cache to reclaim the disk space. To do this, follow the guide steps on the Orcacore website to Clear DNF and Yum Cache on Centos / AlmaLinux / Rocky Linux.
Table of Contents
Clear DNF and Yum Cache on Centos / AlmaLinux / Rocky Linux
To Clear DNF and Yum Cache, you must log in to your server as a root or non-root user with sudo privileges. Then, proceed to the following steps to complete this guide.

Step 1 – Clean Yum Cache on Centos
As you may know, the packages installed by Yum have a local repository cache. In this step, we want to show you how to Clean Cached YUM Packages.
To remove any cached packages, you can easily run the command below:
sudo yum clean packages
Also, you can delete the package headers with the command below:
sudo yum clean headers
Another way is to clean Metadata for Enabled Repositories. To do this, you can easily run the command below:
sudo yum clean metadata
Clean all Yum Cache Repo
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.
Note: To clean the cache for a specific repository, you can use the following command:
yum –enablerepo=<reponame> clean all
Step 2 – Clean DNF Cache on AlmaLinux / Rocky Linux
As you must know, the cached packages with DNF are located in a subdirectory structure from /var/cache/dnf.
The packages that are installed with DNF have database caches. You can easily clean Cached Database Files with the command below:
sudo dnf clean dbcache
Same as the Yum, DNF has metadata for enabled repositories. You can easily clean metadata for enabled repositories with the command below:
sudo dnf clean metadata
Also, you can remove the unwanted cache left out by the DNF package manager with the command below:
sudo dnf clean packages
Clean all DNF Cache Repo
At this point, you can clear the cache for all enabled DNF repositories, including any untracked repositories. To do this, run the following command:
dnf clean all
That’s it, you are done.
Conclusion
At this point, you have learned to Clear DNF and Yum Cache. Clearing the DNF and Yum caches is an essential step for any CentOS, or RHEL system like AlmaLinux and Rocky Linux. By clearing the caches, you not only free up space but also ensure that you’re working with the latest packages and updates.
Hope you enjoy it. You may also 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
Install Gnome Desktop on Fedora Linux
Add Essential Software Repositories on Fedora Linux
FAQs
What is the purpose of the DNF and Yum cache?
The cache stores downloaded package files and metadata for faster access during installations or updates. It helps reduce download times and provides information about available packages, but it can accumulate unnecessary files over time.
Is it safe to clear DNF and Yum cache?
Yes, it is safe to clear the cache. The system will simply re-download necessary files the next time you install or update software.