The cachedir specifies the directory where yum stores downloaded packages, although with keepcache set to 0, yum does not store these packages after installing them. Consider a case where the /var filesystem where yum cache is located is full and there is no diskspace for yum to download the system updates. Also, you do not have set the keepcache variable to 0. The “yum install” command would end up with the error like:
insufficient space in download directory /var/cache/yum/rhel-x86_64-server-6/packages
You always have an option to clean the yum cache using the below post.
But, if you do not want to go that way and want to change the default cache location itself, then follow the steps outlined below.
Changing the location of yum cache from the default /var/cache/yum
1. The yum cache location is configured in /etc/yum.conf file as cachedir option in the [main] section and can be changed:
# cat /etc/yum.conf [main] cachedir=/var/cache/yum/$basearch/$releasever
As per the man page for yum.conf:
# man yum.conf [main] OPTIONS The [main] section must exist for yum to do anything. It consists of the following options: cachedir Directory where yum should store its cache and db files. The default is `/var/cache/yum'.
2. Let’s assume that you want the yum cache location to be a new directory called /yum_cache. Make appropriate changes to the /etc/yum.conf file as shown below for changing the default cache location.
# cat /etc/yum.conf [main] cachedir=/yum_cache/$basearch/$releasever
Although you can change the location of yum cache anytime, it is recommended to check and clean /var volume, or, in case all the files on it are needed, to increase the volume size.