Are you looking for a clean and efficient solution on how to clean YUM cache on CentOS? This guide has all the details you need.
YUM is an open-source package that is used as a command-line utility to manage packages in CentOS. YUM cache is stored in the system to keep information about the downloaded, installed, and removed packages from the system. We will discuss how we can clean the YUM cache.
We will briefly introduce YUM and talk about RPM, why clearing the cache is essential, and how to disable the cache in YUM. We will then discuss various ways of removing the YUM cache from the system. Furthermore, we’ll end the article with a brief discussion of how we can change the location of the YUM cache.
Introduction to YUM
YUM stands for Yellowdog Updater, Modified. It is a command line and open-source utility available for Linux platforms such as CentOS, RHEL, Fedora, etc. It uses RPM package manager in the backend. There are other package management utilities, such as advanced packaging tools (apt), that are available from Debian.
Like apt, YUM works with software repositories and uses rpm under the hood. YUM has been developed in Python programming language with minimal implementation to serve as a command line utility. However, graphical user interface (GUI) based versions are available such as YUMex.
What is RPM?
Before we move the discussion ahead, we briefly discuss RPM, the standard YUM uses. RPM is a packaging standard with the following features:
- It is used for digitally disseminating apps to end users.
- To verify the authorship and integrity of the apps, it uses hashes and digital signatures.
- It doesn’t impose any proprietary restrictions on the copying of packages by users.
Why Learning How to Clean YUM cache is Essential?
Whenever you download and install a package using YUM, the package may still be stored in the cache. Note that the YUM cache is stored in /var/cache/YUM, which keeps the logs and temporary files.
This cache reflects the architecture, distribution release, and repository from which the package is downloaded. Normally, after the successful installation, the packages are deleted from the cache. It is also dependent on the keepcache setting in /etc/YUM.conf file (as discussed in the next section).
As mentioned earlier, sometimes, the package may not be removed from the cache. With the passage of time, the size of the cache becomes very large and can take a significant amount of resources that may slow the system’s performance. You may get the following error on your system:
insufficient space in download directory /var/cache/YUM/rhel-x86_64-server-6/packages
This error occurs when the /var file system is full. The
/var stores the cache, and there is no space in the file system to download the system updates. Therefore, it is essential to learn how to clean YUM cache so that the system can use the available space.
Disabling caching for YUM
You can always disable caching for YUM. By default, YUM is set to cache the downloaded packages, headers, and metadata. The configuration information for setting is stored in /etc/YUM.conf. The name of the configuration is “keepcache”. To change the configuration, set this value to 0, i.e.
How to Clean YUM cache on CentOS
We will now discuss the various steps for partially or completely removing the YUM cache. To perform the steps below, you should have a system with CentOS installed. In addition, you should have an account with root privileges. Now follow the steps below.
Reclaim the disk space due to corrupt metadata files
To clear the YUM cache and reclaim the disk space occupied by the corrupt metadata files, follow the steps below:
Open your Terminal by clicking on the System menu and selecting Terminal. Next, type the command below on the Terminal:
# YUM clean packages
It will take a while before the cache is cleared. You may get the following output:
Remove the old package information completely
To remove the old package information completely, use the following command on the Terminal:
#YUM clean headers
Delete the metadata from the enabled repository
To delete the metadata from the enabled repository, type the following command on the Terminal:
#YUM clean metadata
Remove the package headers
To clear the package headers, use the command below on the terminal:
# YUM clean headers
Clear all the cache
Finally, you can clear all the cache with the help of the following command:
#YUM clean all
The above command will remove all the files from the YUM cache.
Changing the default location of the YUM cache
We close the discussion by briefly mentioning how we can change the default location of the YUM cache. The YUM cache location is configured in the /etc/YUM.conf file. It is mentioned as cachedir in the [main] section. You can open the file using your favorite editor and change the value as follows:
YUM Cache Maintenance Tips
In this short section, we will provide a few quick tips for efficient YUM cache maintenance:
- Regular Cache Clean-up: Automate cache cleaning using cron jobs to ensure that your system remains clutter-free without manual intervention.
- Monitor Cache Size: Keep an eye on the cache directory size using the ‘du’ command to avoid disk space issues.
- Set Cache Retention Policy: Configure cache retention policies in /etc/yum.conf to manage cache more effectively.
By following these tips, you can maintain an efficient and clean YUM cache on your CentOS system.
In this article, we have discussed how to clean YUM cache in CentOS. YUM is a package management utility for CentOS. We briefly discussed YUM and the process of disabling YUM. Then, we discussed how we could remove the YUM cache from the system. Finally, we also discussed how we could change the location of the YUM cache in CentOS.
If this guide helped you, please share it.