pacman -R: removing packages the right way
To remove a package together with the dependencies that nothing else needs, run sudo pacman -Rns <package>. Plain sudo pacman -R <package> removes only the package you name and leaves its dependencies behind.
sudo pacman -Rns <package>
-R- --remove — remove installed packages
-n- --nosave — remove the configuration files too instead of keeping them as .pacsave
-s- --recursive — also remove dependencies that nothing else needs any more
Needs root.
What it does. Remove the package, the dependencies nothing else needs, and the configuration files instead of keeping them as .pacsave copies.
Watch out. n deletes configuration you may have edited by hand; drop it and use -Rs if you want those kept.
Step by step
- Check what depends on it
The query operation prints a Required By field. If other packages are listed there, removing this one will be refused unless you also remove them.
routinepacman -Qi <package> - Remove it with its dependencies
The s modifier takes the dependencies that were installed for this package and that nothing else requires; n removes the configuration files rather than renaming them.
cautionsudo pacman -Rns <package> - Sweep up anything left orphaned
Removals over time leave dependencies behind. Listing them first, and only then removing them, keeps the step reversible in your head.
routinepacman -Qdt
-R, -Rs, -Rn, -Rns and the rest
Each letter adds one thing, and they combine:
| Command | What it removes | Danger |
|---|---|---|
sudo pacman -R <package> | Only the named package. Its dependencies stay installed and become orphans | routine |
sudo pacman -Rs <package> | The package plus the dependencies that nothing else requires — names you did not type are deleted too | caution |
sudo pacman -Rss <package> | The same, and the doubled s lets it reach dependencies that were installed explicitly once nothing needs them | caution |
sudo pacman -Rn <package> | The package and its configuration files, rather than leaving them as .pacsave copies | caution |
sudo pacman -Rns <package> | All three: the package, the unneeded dependencies, and the configuration files | caution |
sudo pacman -Rc <package> | The package and everything that depends on it, which can be a long list | caution |
sudo pacman -Rdd <package> | Only the named package, with every dependency check skipped | risky |
A .pacsave file is the copy pacman leaves behind of a configuration file that belongs to a package being removed, so that a file you edited is not lost with the package.
-Rdd is the one to be careful with. It removes the package without checking what depends on it, so a library other programs are linked against can be taken out from under a running system. There are repair scenarios where it is the right tool; reaching for it to silence a dependency complaint is not one of them.
How far each flag reaches
The letters are easier to hold on to against a worked example. Six packages, two of them chosen by the person and four pulled in as dependencies:
| Command on that system | Packages removed | What is left behind |
|---|---|---|
sudo pacman -R app-main | 1 | The dependencies it pulled in stay, and become orphans |
sudo pacman -Rs app-main | 3 | libbar stays: other-app still requires it |
sudo pacman -Rns app-main | 3 | The same packages, and their edited configuration files are deleted rather than kept as .pacsave |
sudo pacman -Rc libbar | 3 | Everything that required libbar goes with it, which is the other direction |
sudo pacman -Rdd libbar | 1 | 2 packages that required libbar stay installed and stop working |
The orphans the first row leaves behind are the subject of the orphan page, which is where the sweep and its rounds are described.
Orphans
An orphan is a package that was installed to satisfy a dependency and that no installed package requires any more.
They accumulate quietly, because -R leaves dependencies behind. List them
first:
pacman -Qdtd restricts the list to packages installed as dependencies, t to packages nothing requires. Read-only.
The removal is then the usual command with that list as its targets. Adding q
makes the list bare names, which is what makes it usable as an argument:
sudo pacman -Rns $(pacman -Qdtq)The $(…) is the shell filling in the names before pacman starts, so this is not one pacman command and the explainer will not put a level on it. The pacman half is -Rns, which the table above rates for you. If there are no orphans the inner command prints nothing, pacman receives no targets and stops with an error — that is the expected outcome, not a failure to fix.
This one line hands pacman a list you have not read. Run pacman -Qdtq on its own first and look at what comes back: -Rns deletes the configuration files of everything in it, and takes their unneeded dependencies as well.
When a removal is refused
pacman stops rather than breaking a dependency. If something else needs the package, it says so and names it. The three ways forward are, in the order worth trying:
| Option | Command | What it costs |
|---|---|---|
| Remove the dependents too | sudo pacman -Rs <package> <dependent> | You name each package that goes, though -s still takes their unneeded dependencies with them |
| Cascade | sudo pacman -Rc <package> | pacman picks the dependents for you; read the list it prints carefully |
| Skip the checks | sudo pacman -Rdd <package> | The dependents stay installed and stop working |
Common questions
How do I remove a package with pacman?
Run sudo pacman -Rns followed by the package name. That removes the package, the dependencies that nothing else needs, and the configuration files. Use sudo pacman -R if you want only the named package removed.
What is the difference between -R, -Rs and -Rns?
-R removes only the package you name. -Rs also removes dependencies that nothing else requires. -Rns does that and removes the configuration files as well, instead of leaving them behind as .pacsave copies.
How do I remove orphan packages?
List them with pacman -Qdt, which restricts the query to packages installed as dependencies that nothing requires. Removing them is the usual removal command with that list as its targets.