Cleaning Arch Linux: orphan packages, caches and logs
Housekeeping steps for an Arch Linux system: pacman cache with paccache, orphan packages, user caches, duplicates with rmlint, disk usage and the systemd journal.
Over time an Arch Linux system accumulates cached packages, orphaned dependencies, logs and leftover configuration files. This article summarises a set of safe housekeeping steps, based on this guide.
1. Clean the pacman package cache
Pacman keeps every downloaded package in /var/cache/pacman/pkg/ and never removes old or uninstalled versions by itself. This is deliberate: it lets you downgrade a package or reinstall a program without downloading it again (sudo pacman -U /var/cache/pacman/pkg/<package-file>). The directory can however grow indefinitely.
Manual cleaning
| Command | Effect |
|---|---|
sudo pacman -Sc |
Removes cached packages that are no longer installed |
sudo pacman -Scc |
Removes all cached packages, including installed ones |
Alternatively, move the files to another disk if you want to keep them. Removed packages can be downloaded again from the Arch Linux Archive.
Automatic cleaning with paccache
paccache deletes cached versions of installed and uninstalled packages, keeping the 3 most recent versions. It is provided by the pacman-contrib package.
sudo pacman -S pacman-contrib
paccache -h
Run it first in dry-run mode (-d) to see what would be removed, then for real (-r):
paccache -d
paccache -r
Option A: run it monthly with a systemd timer
Create /etc/systemd/system/paccache.timer:
[Unit]
Description=Clean-up old pacman pkg
[Timer]
OnCalendar=monthly
Persistent=true
[Install]
WantedBy=multi-user.target
Start the timer and check that it is active:
sudo systemctl start paccache.timer
sudo systemctl status paccache.timer
Option B: run it after every pacman transaction with a hook
Create /usr/share/libalpm/hooks/paccache.hook:
[Trigger]
Operation = Upgrade
Operation = Install
Operation = Remove
Type = Package
Target = *
[Action]
Description = Cleaning pacman cache with paccache ...
When = PostTransaction
Exec = /usr/bin/paccache -r
2. Remove orphaned packages
List the packages that were installed as dependencies and are no longer required by anything:
sudo pacman -Qtdq
Remove them together with their configuration files and unneeded dependencies:
sudo pacman -Rns $(pacman -Qtdq)
3. Clean the user cache
Check the size of the cache, then empty it:
du -sh ~/.cache/
rm -rf ~/.cache/*
4. Remove old configuration files
Per-application settings live in ~/.config/, and some data in ~/.local/share/. Browse both and delete the folders of programs that are no longer installed. Back up your files before deleting anything.
5. Remove duplicates, empty files and broken symlinks
rmlint finds duplicate files, empty files and directories, and broken symlinks.
sudo pacman -S rmlint
rmlint /home/user
It lists what it finds and generates a shell script (rmlint.sh) that performs the removal. Read the script before running it: the action is irreversible, so back up first.
sh ./rmlint.sh
6. Find the largest files and directories
ncdu is a command-line disk usage browser:
sudo pacman -S ncdu
ncdu /
Graphical alternatives are filelight (KDE Plasma) and baobab (GNOME). The Arch Wiki lists other disk usage tools.
7. Disk cleaning programs
All-in-one tools such as BleachBit can automate many of the steps above. They are not recommended on Arch Linux, because it is not always obvious what will be deleted and you lose control over your system.
8. Limit the systemd journal
Journal logs are stored in /var/log/journal/ and can use a large share of the disk. Trim them by size or by age:
sudo journalctl --vacuum-size=50M
sudo journalctl --vacuum-time=4weeks
To make the limit permanent, uncomment and set SystemMaxUse= in /etc/systemd/journald.conf:
SystemMaxUse=50M
Review pending configuration file changes
After upgrades, .pacnew files may need to be merged. The source notes checkservices and pacdiff for this purpose:
sudo checkservices
# or
sudo pacdiff
Notes
pacman -Sccandrm -rfare irreversible; back up what matters first.- The
paccachetimer in option A relies on apaccache.serviceunit being available (normally provided withpacman-contrib); verify withsystemctl status. - Free disk space helps keep the system stable and responsive.