Pi stores its downloaded packages in
/var/cache/pacman/pkg/ and does not remove the old or uninstalled versions automatically. This has some advantages:
- It allows to
downgrade a packagewithout the need to retrieve the previous version through other means, such as the
Arch Linux Archive.
- A package that has been uninstalled can easily be reinstalled directly from the cache folder, not requiring a new download from the repository.
However, it is necessary to
deliberately clean up the cache periodically to prevent the folder to grow indefinitely in size.
The paccache script, provided within the
pacman-contrib package, deletes all cached versions of installed and uninstalled packages, except for the most recent 3, by default:
Enable and start
paccache.timer to discard unused packages weekly.
You can create a
hook to run this automatically after every pi transaction.
For more options aboout
paccache use :
Pacman also has some built-in options to clean the cache and the leftover database files from repositories which are no longer listed in the configuration file
However, Pacman does not offer the possibility to keep a number of past versions and is, therefore, more aggressive than paccache default options.
To remove all the
cached packages that are not currently installed, and the
unused sync database, execute:
To remove all files from the cache, use the clean switch twice, this is the most aggressive approach and will leave nothing in the cache folder:
One should avoid deleting from the cache all past versions of installed packages and all uninstalled packages unless one desperately needs to free some disk space. This will prevent downgrading or reinstalling packages without downloading them again.
Automatically clean the package cache.
If you are too lazy to clean the package cache manually, you can automate this task using Pacman hooks. The Pacman hook will automatically clean the package cache after every Pacman transaction.
To do so, create a file /etc/pacman.d/hooks/clean_package_cache.hook:
sudo mkdir /etc/pacman.d/hooks
sudo nano /etc/pacman.d/hooks/clean_package_cache.hook
Add the following lines:
[Trigger] Operation = Upgrade Operation = Install Operation = Remove Type = Package Target = * [Action] Description = Cleaning pacman cache... When = PostTransaction Exec = /usr/bin/paccache -r
Save and close the file. From now on, the package cache will be cleaned automatically after every Pacman transactions (like an upgrade, install, remove). You don’t have to run paccache command manually every time.