dnf-clean
Remove DNF cached package data
TLDR
Remove cache files generated from the repository metadata
Mark the repository metadata as expired
Remove repository metadata
Remove any cached packages from the system
Clean up all DNF repository specific metadata and cached files (all of the above)
SYNOPSIS
dnf [options] clean [mode]
Available modes: all | packages | metadata | expire-cache | dbcache | plugins | binaries | debuginfo-packages | oldheaders
PARAMETERS
all
Removes all cached files, including packages, metadata, and database cache.
packages
Removes all cached package files from the system, typically located in /var/cache/dnf/.
metadata
Removes all cached repository metadata. DNF will re-download this data on the next update or installation.
expire-cache
Marks the current cache as expired, forcing DNF to check with repositories for newer metadata on the next transaction without actually deleting the files.
dbcache
Removes the sqlite cache used by DNF for various operations. This also gets rebuilt on the next DNF command.
plugins
Removes cached data specifically generated by DNF plugins.
binaries
Removes cached binary files.
debuginfo-packages
Removes cached debuginfo packages.
oldheaders
Removes old package headers which are no longer needed.
DESCRIPTION
dnf clean is a vital subcommand of the DNF package manager, used to remove various types of cached files from the system. These cached files, while useful for speeding up subsequent DNF operations, can accumulate over time, consuming significant disk space. Additionally, a corrupted cache can sometimes lead to issues with package installations or updates. By utilizing dnf clean, users can free up disk space and resolve potential caching-related problems.
The command offers different cleaning modes, allowing users to target specific types of cached data, such as downloaded packages, repository metadata, or database caches. Running dnf clean frequently can increase the time taken for DNF to perform its next operation (e.g., dnf update or dnf install) as it will need to re-download necessary metadata or packages. However, it's a powerful tool for system maintenance and troubleshooting.
CAVEATS
Cleaning metadata (using metadata or all) will force DNF to re-download all repository metadata during the next DNF operation, which can slow down the initial process, especially on slower internet connections. While dnf clean helps free up disk space, it does not remove installed packages from the system; it only targets cached downloaded packages and metadata. Use dnf remove for uninstalling packages.
COMMON USE CASES
dnf clean is frequently used to:
1. Free up disk space on systems where DNF has accumulated a large cache.
2. Resolve issues with DNF not being able to find packages or exhibiting strange behavior, often due to corrupted or outdated metadata.
3. Ensure that DNF is working with the freshest possible repository information before performing critical updates.
HISTORY
The clean functionality was inherited by DNF from its predecessor, YUM. With the transition from YUM to DNF as the default package manager in Fedora and later RHEL/CentOS, dnf clean effectively replaced yum clean, offering similar capabilities with DNF's improved performance and dependency resolution. Its development is tied directly to the evolution of the DNF project itself, aiming to provide robust and efficient package management for RPM-based Linux distributions.
SEE ALSO
dnf(8), dnf.conf(5)


