Clean cached packages and journal logs on Arch

The Arch installation on my laptop is now three years old and some dust have collected over the years. Running sudo du -shc /* --exclude=/home | sort -h shows that my /var/ folder has grown to 24G. Closer examination (ncdu) revealed that 19G was from /var/cache/pacman/pkg/ and 4G from /var/journal/log/.

Clean the pacman cache

By default, pacman caches old versions of packages in case you want to downgrade a package. It is possible to manually delete all this files, but it is preferable to use the script paccache, which comes with pacman. This script gives you more fine grained control over what to keep. I decided to keep the last two versions of currently installed software (paccache -rk 2) and remove all versions of uninstalled package (paccahce -ruk 0). This brought the total cached package count (ls -l /var/cache/pacman/pkg | wc -l) down from 4076 to 2642 and the size went from 19G to 8.5G.

Clean old journal entries

By default, systemd keeps all journal records. You can manually delete records either based on their age (journalctl --vacuum-time=20d) or their total size (journalctl --vacuum-size=500M). To enable automatic cleaning of logs, set the parameter MaxSizeUse or MaxRetentionSec in /etc/systemd/journald.conf. See man journal.conf for more details. Only keeping logs created in the last 30 days saved me 3.5G.

Resources

Post-doctoral teaching fellow

Developmental biology researcher and data science educator