How to Safely Clean Pacman Package Cache in CachyOS and Arch Linux
In CachyOS and Arch Linux environments, the Pacman package manager never automatically purges downloaded .pkg.tar.zst archive binaries from /var/cache/pacman/pkg/. Over time, this directory routinely swells to 20GB-50GB, triggering low storage warnings on root partitions.
Quick Diagnostics
sudo paccache -ryay -Sc --aur or purge ~/.cache/yayIn CachyOS and Arch Linux environments, the Pacman package manager never automatically purges downloaded .pkg.tar.zst archive binaries from /var/cache/pacman/pkg/. Over time, this directory routinely swells to 20GB-50GB, triggering low storage warnings on root partitions.
Step-by-Step Solution
-
1
Step 1: Measure Current Pacman Cache Footprint
Evaluate exact disk utilization:
BASH# Inspect storage footprint of the Pacman cache du -sh /var/cache/pacman/pkg/ -
2
Step 2: Prune Obsolete Versions Safely Using paccache
The official
paccacheutility (frompacman-contrib) clears obsolete revisions while preserving safety rollbacks:BASH# 1. Ensure pacman-contrib is installed sudo pacman -S pacman-contrib --noconfirm # 2. Retain only the 2 most recent package versions sudo paccache -r -k 2 # 3. Purge cached files for uninstalled packages sudo paccache -ruk0 -
3
Step 3: Comprehensive Cache Flush (For Emergency Space Reclamation)
When immediate disk recovery is mandatory:
BASH# Purge uninstalled package archives sudo pacman -Sc --noconfirm # Purge ALL cached archives completely sudo pacman -Scc --noconfirm -
4
Step 4: Clear AUR Build Repositories (Yay / Paru)
AUR helpers compile binaries inside user home directories:
BASH# If using Yay: yay -Sc --aur --noconfirm rm -rf ~/.cache/yay/* # If using Paru: paru -Scc --noconfirm
❓ Frequently Asked Questions (FAQ)
Why does Pacman retain all downloaded tarballs?
To allow instant offline package downgrades (pacman -U /var/cache/pacman/pkg/pkgname-old.pkg.tar.zst) if an upstream package update introduces regressions.
Is paccache.timer safe for production machines?
Yes. The service runs weekly in the background, keeping the 3 most recent package versions intact for stability.
Prevention Advice
Recommended security practices:
- Enable automated systemd cache cleanup: Activate the built-in systemd timer for automated weekly pruning:
- Prune orphaned dependencies regularly: Remove detached packages via
sudo pacman -Rns $(pacman -Qtdq).