Flag to skip removing optional dependencies

I typically use -Rcns when removing a package to check for dependencies and if there are any issues, I stop and use -Runs. This works most of the time however I’m running into an issue where I want to remove proton-ge-custom but avoid removing some/all of the optional dependencies used by other programs.

I’ve searched and searched and can’t seem to find a flag to accomplish this. Any tips or tricks to skip/avoid removing optional dependencies used by other programs?

I found someone asking the same question here but no answer was provided.

I think you could just use -R to remove the package in question.
Then mark any leftover dependencies you want to keep as explicitly installed:

–asexplicit

Install packages explicitly; in other words, fake their install reason to be explicitly installed. This is useful if you want to mark a dependency as explicitly installed so it will not be removed by the –recursive remove operation.

https://man.archlinux.org/man/pacman.8

Or do it the other way around. Mark first the dependencies you want to keep as explicit and then remove the package along with those dependencies you don’t want with -Rs.

This is a side effect of using pacman -Rs. It removes optional dependencies of other packages.

I usually avoid this by using pacman -Rc to remove packages and then just cleaning up orphans occasionally.

As a side note, using pacman -Rcs with or without the n is really dangerous and not a good practice.

2 Likes

Thanks for the suggestion. This would achieve what I’m after but I foresee an issue where these optional dependencies will then not be removed in future when removing those programs for which they are optional dependencies of. I’d like to try to avoid that scenario.

I always use just -R (or -Rc if necessary) to remove a package. Then I manually clean up the orphans, marking what I want to keep as explicitly installed. I find this gives me the most control over packages and avoids any accidental removal of packages that I wish to keep.

Gotcha. Thanks for this clarification. I thought it was specifically for dependencies and did not necessarily included optional dependencies. It would be nice if there was an operation to avoid optdeps when removing a package.

It would be nice indeed.

Unless you are removing something complicated, like entire desktop environments, you’ll rarely have more than 5-6 orphans, it’s not that difficult to manually check them and decide if you need them or not. If you are not sure if you need something, then it’s probably fine to remove it, you can always install it later if you need it.

Can you elaborate on how pacman -Rc helps avoid this problem? On it’s face, it looks like a more aggressive version of pacman -Rs because it does not check if it is removing explicitly installed packages, or packages that are dependencies of other packages like pacman -Rs does.

-c, --cascade

Remove all target packages, as well as all packages that depend on one or more target packages. This operation is recursive and must be used with care, since it can remove many potentially needed packages.

-s, --recursive

Remove each target specified including all of their dependencies, provided that (A) they are not required by other packages; and (B) they were not explicitly installed by the user. This operation is recursive and analogous to a backwards –sync operation, and it helps keep a clean system without orphans. If you want to omit condition (B), pass this option twice.

It isn’t that at all. pacman -Rc removes dependencies in the opposite direction of pacman -Rs

In plain English, -Rc means “Remove this package and any dependency that would stop it from being removed.”

While -Rs means “Remove this package and all it’s dependencies(Unless they are hard dependencies of other packages)”

That is why pacman -Rcs is so dangerous. It not only removes dependencies in both directions, but because -Rs is so greedy, it removes the dependencies of every one of those packages including optional dependencies of other packages. If you hit the wrong string of dependencies, it can easily remove over half your packages when removing some seemingly innocuous looking package.

To be 100% clear. pacman -Rc isn’t the solution to this problem, it is simply the command I personally use to remove packages.

1 Like

In spite of this perfectly lucid explanation, I still did not understand what you were saying. Reading the man page over and over wasn’t getting me anywhere either. I finally just took a look at an actual example:

sudo pacman -Rs thunar
checking dependencies...
error: failed to prepare transaction (could not satisfy dependencies)
:: removing thunar breaks dependency 'thunar' required by thunar-archive-plugin
:: removing thunar breaks dependency 'thunar' required by thunar-media-tags-plugin
:: removing thunar breaks dependency 'thunar' required by thunar-volman
:: removing thunar breaks dependency 'thunar' required by xfdesktop

sudo pacman -Rc thunar
checking dependencies...

Packages (5) thunar-archive-plugin-0.5.1-1  thunar-media-tags-plugin-0.4.0-1  thunar-volman-4.18.0-1  xfdesktop-4.18.1-1  thunar-4.18.7-1

Total Removed Size:  13.05 MiB

:: Do you want to remove these packages? [Y/n] 

The -Rc option removes the packages which depend on Thunar. That’s what you meant by “the opposite direction”. I’m not sure why I wasn’t understanding that.

Sorry to derail the conversation. Thanks for being patient with the explanation. :slightly_smiling_face: