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 cleanTo remove only the cached packages that are obsolete and can no longer be downloaded:
sudo apt autocleanTo also remove orphaned dependencies that are no longer required by any installed software:
sudo apt autoremove --purgeFedora, 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 allIf you are using an older distribution running YUM:
sudo yum clean allArch 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 -ScTo completely delete the entire package cache, including versions currently installed:
sudo pacman -SccFor 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 -ropenSUSE (Zypper)
Zypper caches downloaded RPMs in
/var/cache/zypp/packages/.
To clean both the local repository caches and downloaded packages:
sudo zypper clean --allIf you only want to remove downloaded package archives while keeping repository metadata intact:
sudo zypper clean --packagesFlatpak 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 --unusedFor Snap, clear disabled package revisions using this bash command:
sudo snap set system refresh.retain=2