Discussion about handling orphaned packages

You could easily make a Pacman hook to remove orphans, but it is not a good idea because removing the package is only one way to deal with an orphaned package. The other option is to mark the package as explicitly installed and keep it.

All orphans should be carefully reviewed before you remove them to make sure a needed or desired package is not being removed. Keep in mind, an orphan is just a package that was installed as a dependency, but is no longer required by any package. It doesn’t necessarily mean the package is no longer useful. It is up to the user to determine whether the package should be removed, or instead marked as explicitly installed.

Further to this, it is good to be aware that the command suggested in the ArchWiki for removing orphans (here) is very aggressive. A major drawback of recursively removing orphans with this method is it can include packages that are optional dependencies of other packages.

A much safer option is to run sudo pacman -R $(pacman -Qdtq) a few times in a row (until pacman -Qdtg no longer returns anything) as mentioned in this discussion from another forum: How to delete orphaned packages - Pacman vs. Pamac - Pacman - EndeavourOS

From that same discussion, another user has created a function designed to remove orphans with this safer removal method in mind:

orph() {
	while [[ $(pacman -Qdtq) ]]
	 do	sudo pacman -R $(pacman -Qdtq)
	done
}

To circle back to the point, the TL;DR would be: no, removing orphans should not be automated because removal is not always the correct choice for dealing with an orphaned package.

4 Likes