How to rebuild package cache?

My pacman cache (and other caches?) got wiped out due to a system restore, and I want to rebuild it.
My system is working, I just want to have all installed packages in the cache.
This would include pacman packages and also AUR packages.
What’s the way to rebuild the cache for all installed packages?

You can redownload your packages with:

sudo pacman -Syuw $(pacman -Qqn)

(Note, that pacman can only download non-AUR packages.)

2 Likes

To add to that for aur packages it may depend on your preferred helper, and what exactly you want for the cache (some aur helpers have different syntax, or allow you to download to PKGBUILD alone, etc).
For a simple ‘reinstall all foreign packages using the aur helper (here paru)’:

paru -S $(pacman -Qmq)
2 Likes

I installed most of my aur packages via Pamac.

pamac build $(pacman -Qmq)
2 Likes

@cscs That last one is probably the answer, but I couldn’t test it, as I already ran the other commands. (Instead of paru, I used yay, but it worked just the same.)
When running that last snippet

pamac build $(pacman -Qmq)

the only output I got was

Error: target not found: libsidplay
Error: target not found: brpcfax-bin

I know that I installed brpcfax-bin from a local package, so no wonder it couldn’t be downloaded.

You can exclude them with sed:

pamac build $(pamac list --foreign --quiet | sed '/^(libsidplay|brpcfax-bin)/d') 

(However, this also installs the package. With pamac there is no possibility to build without installing.)

1 Like

These appear to not exist in the repos or aur.
(though libsidplayfp does exist in the repos)