Pacman: orphans, cache, holds

arch / published / guide #10 / ≈ 3 min read

pacman is the Arch package manager. It's fast and capable, but over the months a few habits keep an Arch install tidy. This is the maintenance side of pacman — not new tricks, just hygiene.

Find packages nobody is using anymore

When you install software, pacman pulls in dependencies. When you remove the software, the dependencies are sometimes left behind — they become orphans. Find them:

pacman -Qdt

The flags: -Q query installed packages, -d only those installed as dependencies, -t only those not required by anything anymore. Remove them in one go:

sudo pacman -Rns $(pacman -Qdtq)

The inner pacman -Qdtq prints just the names; -Rns means "remove, including config files and unused dependencies of these packages too."

Caveat: some packages you actually want are listed as orphans because they were installed as a dependency once. Read the list before pressing y.

Clean the cache

Every package pacman has ever downloaded sits in /var/cache/pacman/pkg. Over time this adds up — gigabytes, easily.

sudo pacman -Sc         # remove cached versions you don't have installed
sudo pacman -Scc        # nuke everything (no rollback after this)

A nicer middle ground, if you install pacman-contrib:

sudo paccache -rk1      # keep only the most recent cached version of each package

This lets you downgrade a single package if an update goes wrong.

Hold a package back from updates

Sometimes you want to keep an exact version — for example, the kernel after you set up a tricky driver. Edit pacman's config:

sudo nano /etc/pacman.conf

Find the IgnorePkg line and uncomment/add to it:

IgnorePkg = linux linux-headers
IgnoreGroup = nvidia

From now on pacman warns you when ignored packages have updates but skips them.

Read the news before -Syu

Arch publishes manual-intervention notices at archlinux.org/news. Most updates are uneventful, but every few months something requires a small change on your side. Reading the news before upgrading saves frustration.

An AUR tool called informant makes this automatic. Install it via your AUR helper of choice (see the AUR helpers guide for paru/yay setup):

paru -S informant         # or: yay -S informant

Then use it in place of plain pacman -Syu:

informant check && sudo pacman -Syu

It refuses to upgrade until you've read the news. Worth installing.

What -Syu actually does

One last orientation: sudo pacman -Syu is the upgrade command. -S sync, -y refresh the package list, -u upgrade what you have. Never partial upgrade (running pacman -S somepackage without -y first when there are pending updates) — that combination has caused most of the "Arch breaks" stories you've heard.

Auto-prune on a schedule

Running paccache by hand is fine, but the pacman-contrib package also ships a systemd timer that does it for you weekly. Turn it on once and forget about it:

sudo systemctl enable --now paccache.timer

It runs paccache -r (keep the latest 3 versions of each installed package) once a week. If three is too many for your taste, drop an override that calls paccache -rk1 instead.

One companion command, separate from the timer: clearing cached versions of packages you no longer have installed at all.

sudo paccache -ruk0       # purge ALL cached versions of uninstalled packages

-u targets uninstalled packages only, and -k0 keeps zero versions of them. Worth doing once after a big -Rns spree to reclaim the space those abandoned downloads were holding.

← back to index