Reduce Cache Size Arch Linux
To reduce the size of the pacman
cache, you can remove old and unneeded package files. pacman
caches all downloaded packages in /var/cache/pacman/pkg
, which can accumulate over time and consume a significant amount of disk space.
Here are some steps to manage and clean up the pacman
cache:
1. Remove Uninstalled Packages from the Cache
You can remove all packages from the cache that are not currently installed using the following command:
sudo pacman -Sc
This will prompt you to confirm the removal of uninstalled packages. This command is a safe way to clean up the cache while keeping the latest versions of installed packages.
2. Remove All Cached Packages
If you want to free up more space and are willing to re-download packages if needed, you can remove all cached packages. This will delete everything in the cache directory:
sudo pacman -Scc
This command will prompt you to confirm the removal of all cached packages, including those that are currently installed. Be aware that this means pacman
will need to download packages again if you need to reinstall them or perform rollbacks.
3. Use a Cache Cleaner Utility
Alternatively, you can use a utility like paccache
, which is included in the pacman-contrib
package. This utility provides more granular control over the cache. For example, you can keep only the latest three versions of each package in the cache:
First, install pacman-contrib
if it’s not already installed:
sudo pacman -S pacman-contrib
Then, run paccache
to keep only the latest three versions of each package:
sudo paccache -r
If you want to keep fewer versions, you can specify the number with the -k
option. For example, to keep only the latest version:
sudo paccache -r -k 1
4. Regular Maintenance
It’s a good practice to regularly clean the pacman
cache to prevent it from growing too large. You can create a cron job or a systemd timer to run paccache
periodically.
Using systemd Timer
Create a service file /etc/systemd/system/paccache.service
:
[Unit]
Description=Clean up old pacman packages
[Service]
Type=oneshot
ExecStart=/usr/bin/paccache -r -k 1
Create a timer file /etc/systemd/system/paccache.timer
:
[Unit]
Description=Run paccache periodically
[Timer]
OnCalendar=monthly
Persistent=true
[Install]
WantedBy=timers.target
Enable and start the timer:
sudo systemctl enable paccache.timer
sudo systemctl start paccache.timer
This setup will run paccache
once a month, keeping only the latest version of each package.
By following these steps, you should be able to significantly reduce the size of your pacman
cache and maintain it at a manageable level.