Skip to the content
pacman-master.com

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

  1. 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>
  2. 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>
  3. 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:

CommandWhat it removesDanger
sudo pacman -R <package>Only the named package. Its dependencies stay installed and become orphansroutine
sudo pacman -Rs <package>The package plus the dependencies that nothing else requires — names you did not type are deleted toocaution
sudo pacman -Rss <package>The same, and the doubled s lets it reach dependencies that were installed explicitly once nothing needs themcaution
sudo pacman -Rn <package>The package and its configuration files, rather than leaving them as .pacsave copiescaution
sudo pacman -Rns <package>All three: the package, the unneeded dependencies, and the configuration filescaution
sudo pacman -Rc <package>The package and everything that depends on it, which can be a long listcaution
sudo pacman -Rdd <package>Only the named package, with every dependency check skippedrisky

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:

How far each removal flag reaches in one small systemSix packages drawn as a graph. app-main and other-app were chosen by the person; libfoo, libbar, libz and oldlib were pulled in as dependencies. A dashed line joins each package to what it requires, with the required one drawn lower. Underneath, three removal commands are compared on this same system, each with the number of packages it takes and the level the explainer gives it.app-mainchosenother-appchosenlibfoopulled in as a deplibbarpulled in as a deplibzpulled in as a depoldlibpulled in as a depA line joins a package to what it requires; the required one is drawn lower.sudo pacman -R app-mainroutine1packages gosudo pacman -Rs app-maincaution3packages gosudo pacman -Rc libbarcaution3packages go
-R takes the name you typed. -Rs follows what that name pulled in. -Rc goes the other way, up to whatever needs it.
Command on that systemPackages removedWhat is left behind
sudo pacman -R app-main1The dependencies it pulled in stay, and become orphans
sudo pacman -Rs app-main3libbar stays: other-app still requires it
sudo pacman -Rns app-main3The same packages, and their edited configuration files are deleted rather than kept as .pacsave
sudo pacman -Rc libbar3Everything that required libbar goes with it, which is the other direction
sudo pacman -Rdd libbar12 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:

routinepacman -Qdt

d 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:

not pacmansudo 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:

OptionCommandWhat it costs
Remove the dependents toosudo pacman -Rs <package> <dependent>You name each package that goes, though -s still takes their unneeded dependencies with them
Cascadesudo pacman -Rc <package>pacman picks the dependents for you; read the list it prints carefully
Skip the checkssudo 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.

How to check this page

Two commands on your own machine: pacman -<operation> --help lists the modifiers that operation accepts, and man pacman opens the pacman(8) manual page these descriptions are written from. Where the descriptions come from, and what this site is not, is set out on the about page.

This page was last edited on .