Correctly reinstall packages uninstalled with yay -Rsu option

In the arch wiki the following command is listed to remove all unneeded packages:

In some cases the method above will not detect all possible unneeded packages. E.g. dependency cycles (also known as “circular dependencies”), excessive dependencies (fulfilled more than once), some non-explicit optionals etc.

They can be deleted using:

$ pacman -Qqd | pacman -Rsu -

I used this command and it worked fine. Later I used the same command with yay: $ yay -Qqd | yay -Rsu -. It didn’t do what I expected. It removed several needed packages like for example ca-certificates-mozilla.

(luckily I also have chromium installed so I was able to download and reinstall it, otherwise pacman -S with other packages wouldn’t even have worked)

What did happen here? Were ca-certificates-mozilla and all the other removed packages really not required by any other package. Why weren’t they removed by pacman but by yay?

First, orphans aren’t packages which are not needed. They are packages that were installed as dependencies but no longer have anything depending on them.

Second, be aware that the command you are using is extreme and will often remove important packages with pacman and yay both.

Third, yay has a better way to remove orphans, yay -Yc. This is what I would recommend doing.

Lastly, you need to be more specific about where you are using yay in that command.

For me, both pacman and yay would remove ca-certificates-mozilla. As well as most of the other optional dependencies I have installed.

1 Like

First, orphans aren’t packages which are not needed. They are packages that were installed as dependencies but no longer have anything depending on them.

I don’t really understand the difference between orphanded and unneeded. I know what an orphaned package is but according to the pacman manual the --unneded option does the following:

“Removes targets that are not required by any other packages.”

Isn’t that the same as “dependencies that no longer have anything depending on them” under the condition that I pipe the names of all dependencies into the command?

Third, yay has a better way to remove orphans, yay -Yc. This is what I would recommend doing.

Thanks. I’ll use it the next time.

Lastly, you need to be more specific about where you are using yay in that command.

I replaced “pacman” by “yay” in both commands.

If you do not want to use yay (for example, you use paru like me), and you want to remove orphans, use sudo pacman -Qdtq | sudo pacman -Rsc -.

While you are certainly free to do anything you like on your own install, this is not a safe command to recommend to others. Using -Rsc is risky in most situations but it is way too aggressive to use for orphan removal.

paru has a similar command, paru -c