Skip to content
Latchkey

dnf makecache: Prebuild the Metadata Cache

dnf makecache downloads and builds the repository metadata so later install commands do not pause to fetch it.

Prebuilding the cache is useful in Docker layers and to surface a broken repo early. It also pairs with dnf clean all to control image size.

What it does

dnf makecache fetches the metadata (repomd.xml, primary, filelists) for each enabled repository and stores it under /var/cache/dnf. Subsequent install and search commands then use the cache instead of downloading metadata again.

Common usage

Terminal
dnf makecache
# force a refresh even if the cache looks current
dnf makecache --refresh
# clean it out afterward to shrink the image
dnf clean all && rm -rf /var/cache/dnf

Options

Command / FlagWhat it does
dnf makecacheDownload and build the metadata cache
--refreshRefresh even if metadata is within its expiry
--timerRun in the low-priority background mode
dnf clean allRemove all cached metadata and packages
dnf clean metadataRemove only cached metadata

In CI

Run dnf makecache early in a Dockerfile so a broken or slow repo fails fast, then dnf clean all in the final install layer so the cache does not bloat the image. --refresh forces a fresh pull when you suspect stale metadata.

Common errors in CI

"Failed to download metadata for repo '<id>': Cannot download repomd.xml" means the repo URL is unreachable or the mirror is down. "Status code: 404 for <url>" means the release version in the repo path no longer exists. "GPG key retrieval failed" or "Public key ... is not installed" means the repo GPG key is missing; import it with rpm --import.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →