Systems & Servers

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 // RESOLUTION MATRIX

[TELEMETRY]
CAUSA
/var/lib/pacman and /var/cache/pacman/pkg directories accumulating dozens of package revisions
SOLUTION
Prune obsolete package tarballs while retaining the latest 2 versions via sudo paccache -r
CAUSA
AUR build cache bloating user directories (~/.cache/yay or ~/.cache/paru)
SOLUTION
Clean AUR cache using yay -Sc --aur or purge ~/.cache/yay

Step-by-Step Solution

  1. 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. 2

    Step 2: Prune Obsolete Versions Safely Using paccache

    The official paccache utility (from pacman-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. 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. 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).
Author • Web Designer & App Creator

Rodolfo Castro

Web designer, app developer, and founder of SoporteCero. Specializing in UI/UX architecture, digital products, and modern web environments (Pixel Digital Dz). Every tutorial and guide on SoporteCero is thoroughly tested and verified in our technical lab to ensure reliable, up-to-date solutions.