Updated: 28 September 2026 · Applies to: dnf 4.14 to 4.20 on AlmaLinux and Rocky Linux 9 and 10 and RHEL 9 and 10 (yum is an alias of dnf); dnf5 on Fedora
dnf keeps repository metadata and, if configured, downloaded packages in a cache under /var/cache/dnf. Cleaning it frees disk space and fixes errors caused by outdated or damaged metadata, such as checksum mismatches or "Cannot download repomd.xml". On current systems yum clean runs dnf clean, so both names work. The old yum clean headers option no longer exists.
Clean the cache
dnf clean all # everything: metadata and packages dnf clean packages # only cached package files dnf clean metadata # only repository metadata dnf clean dbcache # only the solver cache files
After cleaning, dnf downloads fresh metadata on the next command. To do that straight away:
dnf makecache
Check how much space the cache uses with du -sh /var/cache/dnf.
Keep downloaded packages
By default dnf deletes packages after installing them. To keep them, for example to install the same versions on other servers, add this to the [main] section of /etc/dnf/dnf.conf:
keepcache=True
Cached packages then stay in /var/cache/dnf/*/packages/ until you run dnf clean packages. To collect packages without installing them, use dnf download instead; see downloading RPM packages with dependencies.
When a clean fixes errors
- "Cannot download repomd.xml" or "Failed to download metadata for repo": run
dnf clean alland try again. If it still fails, test the network and DNS (curl -I https://repo.almalinux.org/), or disable a broken third-party repository withdnf config-manager --set-disabled REPOID. - "Checksum doesn't match" or "Package does not match intended download": a mirror was out of date while you downloaded. Clean the cache and try again later.
- Old package versions offered after a repository changed:
dnf clean metadataforces fresh metadata.
On Ubuntu and Debian
apt keeps downloaded packages in /var/cache/apt/archives. apt clean deletes them all; apt autoclean deletes only those that can no longer be downloaded.
Official documentation: DNF command reference (clean and makecache) and DNF configuration reference.
Ucartz services for this topic
- KVM VPS hosting: NVMe SSD and full root access, with Free Basic Managed Support.
- Unmanaged dedicated servers: full root access and free IPMI KVM, with Free Basic Managed Support.
- Linux server management: hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.
