8.4.7. Working with Yum Cache
By default, yum deletes downloaded data files when they are no longer needed after a successful operation. This minimizes the amount of storage space that yum uses. However, you can enable caching, so that the package files downloaded by yum stay in cache directories. By using cached data, you can carry out certain operations without a network connection, you can also copy packages stored in the caches and reuse them elsewhere.
Yum stores temporary files in the
/var/cache/yum/$basearch/$releasever/
directory, where $basearch
and $releasever
are Yum variables referring to base architecture of the system and the release version of Red Hat Enterprise Linux. Each configured repository has one subdirectory. For example, the directory /var/cache/yum/$basearch/$releasever/development/packages/
holds packages downloaded from the development repository. You can find the values for the $basearch and $releasever variables in the output of the yum version
command.
To change the default cache location, modify the
cachedir
option in the [main]
section of the /etc/yum.conf
configuration file. See Section 8.4, “Configuring Yum and Yum Repositories” for more information on configuring yum.
Enabling the Caches
To retain the cache of packages after a successful installation, add the following text to the
[main]
section of /etc/yum.conf
.
keepcache = 1
Once you enabled caching, every yum operation may download package data from the configured repositories.
To download and make usable all the metadata for the currently enabled yum repositories, type:
yum
makecache
This is useful if you want to make sure that the cache is fully up to date with all metadata. To set the time after which the metadata will expire, use the
metadata-expire
setting in /etc/yum.conf
.
Using yum in Cache-only Mode
To carry out a yum command without a network connection, add the
-C
or --cacheonly
command-line option. With this option, yum proceeds without checking any network repositories, and uses only cached files. In this mode, yum may only install packages that have been downloaded and cached by a previous operation.
For instance, to list packages that use the currently cached data with names that contain “gstreamer”, enter the following command:
yum
-C
list
gstreamer*
Clearing the yum Caches
It is often useful to remove entries accumulated in the
/var/cache/yum/
directory. If you remove a package from the cache, you do not affect the copy of the software installed on your system. To remove all entries for currently enabled repositories from the cache, type the following as a root
:
yum
clean
all
There are various ways to invoke
yum
in clean
mode depending on the type of cached data you want to remove. See Table 8.3, “Available yum
clean
options” for a complete list of available configuration options.
Option | Description |
---|---|
expire-cache | eliminates time records of the metadata and mirrorlists download for each repository. This forces yum to revalidate the cache for each repository the next time it is used. |
packages | eliminates any cached packages from the system |
headers | eliminates all header files that previous versions of yum used for dependency resolution |
metadata | eliminates all files that yum uses to determine the remote availability of packages. These metadata are downloaded again the next time yum is run. |
dbcache | eliminates the sqlite cache used for faster access to metadata. Using this option will force yum to download the sqlite metadata the next time it is run. This does not apply for repositories that contain only .xml data, in that case, sqlite data are deleted but without subsequent download |
rpmdb | eliminates any cached data from the local rpmdb |
plugins | enabled plugins are forced to eliminate their cached data |
all | removes all of the above |
The
expire-cache
option is most preferred from the above list. In many cases, it is a sufficient and much faster replacement for clean
all
.