I use Arch, btw. The pacman package manager is one of the major unique features of Arch Linux. pacman keeps the system up-to-date by synchronizing package lists with the master server. This model also allows the user to download/install packages with a simple command, complete with all required dependencies.
Pacman also stores its downloaded packages in /var/cache/pacman/pkg/ and does not remove old versions automatically. This lets for packages to be downgraded/rolled back without having to download the previous version.
However, since the old packages are not cleaned up, this cache can grow indefinitely, and to a large extent. Pacman comes with some additional flags that can help prune this cache - most notably, you’ll see references commands like below
pacman -Rns $(pacman -Qdtq)
or
pacman -Scc
Having to do this repeatedly can be an annpoying thing and I wanted an automated way. Doing a bit of search, I came across paccache-hook - a simple utility that hooks into pacman’s post-transaction hooks to clean up the cache automatically.
paccache installs a hook to cleanup the pacman package cache using paccache whenever you run pacman. This ensures the pacman cache is cleaned up whenever you use pacman regularly.
Here’s an example output of the hook running automatically and cleaning up the cache:
:: Running post-transaction hooks...
(1/2) Arming ConditionNeedsUpdate...
(2/2) Removing old packages from pacman cache...
Removing old installed packages...
==> finished: 136 packages removed (disk space saved: 2.57 GiB)
Removing old uninstalled packages...
==> finished: 23 packages removed (disk space saved: 4.24 MiB)
If you’re not happy with the default configuration, you can edit the conf file located in /etc/paccache-hook.conf to change the settings to your liking. This works with a pacman helper like yay as well, I haven’t tried with paru yet.
I hope this helps.