Reinstalling a package
pacman has no separate reinstall operation. Naming a package that is already installed is the reinstall: it fetches the package again and writes its files back over the ones on disk.
sudo pacman -S firefox
-S- --sync — install packages from the repositories and upgrade the system
Needs root.
What it does. Install the package again, replacing the files it owns with fresh copies from the repository or the cache.
Watch out. Reinstalling replaces the files a package owns and leaves your edited configuration alone, so it repairs less than people expect it to.
Putting one package back
sudo pacman -S firefoxpacman prints a line saying the package is up to date and reinstalling it, then does so.
The opposite of this is --needed, which skips packages that are already at the
requested version. It is the flag to add when a command names several packages
and you want only the missing ones:
sudo pacman -S --needed base-develChecking before reinstalling
Reinstalling is a reasonable guess when a program has stopped working, but the cheaper move is to ask pacman whether the files it owns are still the files on disk:
| Command | What it checks | Level |
|---|---|---|
pacman -Qk firefox | That each file the package owns is present | routine |
pacman -Qkk firefox | The same, and more of each file's recorded properties | routine |
pacman -Qo <path> | Which package owns a given path, so you know which one to reinstall | routine |
A check that comes back clean means a reinstall would change nothing, and the problem is somewhere else: configuration, a dependency, or the mismatch described on the partial upgrade page.
<package>: 0 total files, 0 altered filesThe shape of a clean answer. A count other than zero names the files that no longer match what the database records.
What a reinstall does not put back
A reinstall replaces the files the package owns. A configuration file you edited is handled the same way it is handled during an upgrade: yours is kept and the packaged one lands beside it as a .pacnew. Reinstalling is therefore not a way to get a default configuration back, and the .pacnew page covers what to do with the copy that appears.
Rebuilding a whole set
After a disk problem, or after files were deleted by something other than pacman, it is sometimes easier to put back a group than to find the pieces. Two useful groups:
sudo pacman -S $(pacman -Qnq)A shell substitution rather than one pacman command, so it carries no level here. -Qnq lists the names of installed packages that came from a repository, which is the set pacman can fetch again.
sudo pacman -S $(pacman -Qmq)-Qmq lists the packages that did NOT come from a repository, so this one fails by design: pacman has nowhere to fetch them from. It is here as the check to run first, not as a command to copy.
That second line is worth running as pacman -Qm on its own before anything else: the
names it prints are the packages a reinstall cannot reach, which on most machines
means the ones built from the AUR. The AUR page
covers rebuilding those.
Common questions
How do I reinstall a package with pacman?
Name it again: sudo pacman -S followed by the package name. pacman has no separate reinstall operation, so installing a package that is already installed is what puts its files back.
How do I reinstall every package on Arch Linux?
Hand pacman the list of installed packages that came from a repository, which pacman -Qnq prints. Packages that did not come from a repository, listed by pacman -Qmq, cannot be fetched again this way.
Does reinstalling reset the configuration file?
No. A configuration file you edited is kept and the packaged version lands beside it with a .pacnew suffix, exactly as it would during an upgrade. Reinstalling is not a way to get the default file back in place.
What does --needed do?
It skips any package already at the version being asked for. Without it, naming an installed package reinstalls it, which is the behaviour you want for a repair and not the one you want in a long list.