How to Clear Linux Package Manager Cache

Over time, Linux package managers accumulate downloaded package files (.deb, .rpm, or .pkg.tar.zst), metadata, and temporary archives in local cache directories, consuming gigabytes of disk space. This guide outlines the straightforward terminal commands required to safely clear this cache across major Linux distributions, including Debian and Ubuntu (APT), Fedora and RHEL (DNF/YUM), Arch Linux (Pacman), and openSUSE (Zypper).

Debian, Ubuntu, and Linux Mint (APT)

APT stores downloaded .deb files in /var/cache/apt/archives/. You can remove these files using two primary commands.

To remove all cached package files completely:

sudo apt clean

To remove only the cached packages that are obsolete and can no longer be downloaded:

sudo apt autoclean

To also remove orphaned dependencies that are no longer required by any installed software:

sudo apt autoremove --purge

Fedora, RHEL, and CentOS (DNF / YUM)

Modern Fedora and Red Hat-based distributions use DNF, while older systems use YUM. Both store metadata and package RPMs in cache directories.

To remove all cached packages and metadata using DNF:

sudo dnf clean all

If you are using an older distribution running YUM:

sudo yum clean all

Arch Linux and Manjaro (Pacman)

Pacman maintains its cache at /var/cache/pacman/pkg/ and does not automatically clean old versions.

To remove cached packages that are not currently installed:

sudo pacman -Sc

To completely delete the entire package cache, including versions currently installed:

sudo pacman -Scc

For a safer automated approach, use the paccache script (available via the pacman-contrib package) to retain only the last two versions of each package:

paccache -r

openSUSE (Zypper)

Zypper caches downloaded RPMs in /var/cache/zypp/packages/.

To clean both the local repository caches and downloaded packages:

sudo zypper clean --all

If you only want to remove downloaded package archives while keeping repository metadata intact:

sudo zypper clean --packages

Flatpak and Snap (Universal Packages)

If you use universal package formats, they also retain unused runtime files and old revisions.

To remove unused Flatpak runtimes:

flatpak uninstall --unused

For Snap, clear disabled package revisions using this bash command:

sudo snap set system refresh.retain=2