Skip to content

Arch Linux Pacman

Clearing Package Cache

Packages downloaded by Pacman are stored in "/var/cache/pacman/pkg". The downloaded packages are not cleared over time even when a package is uninstalled.

With the use of "paccache" script provided by the "pacman-contrib" package, it allows for deletion of all cached versions of installed and uninstalled packages. By default the most recent 3 cached versions will be kept.

Solution: Manual

  1. First install the required package.
    # pacman -Sy pacman-contrib
    
  2. Remove all except the most recent 3 cached versions.
    # paccache -r
    
  3. Remove all except the most recent 2 cache versions with verbose output.
    # paccache -rk2v
    
  4. Remove all cached versions for uninstalled packages.
    # paccache -ruk0
    

Solution: Automatic

Default behaviour is to run weekly to clear unused packages.

  1. Install required package.
    # pacman -Sy pacman-contrib
    
  2. Edit interval as desired.
    # nano /etc/systemd/system/paccache.timer
    
    [Unit]
    Description=Discard unused packages weekly
    
    [Timer]
    OnCalendar=weekly
    AccuracySec=1h
    Persistent=true
    
    [Install]
    WantedBy=timers.target
    
  3. Enable paccache Timer
    # systemctl enable paccache.timer
    

Last update: August 9, 2020