You are not logged in.
$ pacman --version
.--. Pacman v7.1.0 - libalpm v16.0.1
/ _.-' .-. .-. .-. Copyright (C) 2006-2025 Pacman Development Team
\ '-. '-' '-' '-' Copyright (C) 2002-2006 Judd Vinet
'--'
This program may be freely redistributed under
the terms of the GNU General Public License.How to remove all packages that
are not explicitly installed, and
are not a required or optional (recursive) dependency of any explicitly-installed package?
Thought the way to do this was -
$ sudo pacman -Rsn $(pacman -Qdtq)
checking dependencies...
Packages (1) clang-22.1.8-1
Total Removed Size: 254.42 MiB
:: Do you want to remove these packages? [Y/n]
:: Processing package changes...
(1/1) removing clang [#####################################] 100%
:: Running post-transaction hooks...
(1/1) Arming ConditionNeedsUpdate...But it isn't complete -
$ pacman -Qdt
llvm 22.1.8-1
openmp 22.1.8-1
$ sudo pacman -Rsn $(pacman -Qdtq)
checking dependencies...
Packages (2) llvm-22.1.8-1 openmp-22.1.8-1
Total Removed Size: 132.97 MiB
:: Do you want to remove these packages? [Y/n] Only after this second removal does pacman -Qdt output become empty.
Have seen this before - and the previous instance was also when clang was no longer a dependency of any explicitly-installed package. Tried adding -c and -u options to the initial removal, but neither one seemed to make any difference.
What are the necessary pacman option(s) to remove all recursive no-longer-used-dependency packages in one pacman command?
Thanks for any insight.
Last edited by archaea (2026-07-17 23:08:56)
Offline
https://gitlab.archlinux.org/pacman/pac … _items/191
https://gitlab.archlinux.org/pacman/pac … _items/189
The problem is that llvm and openmp are optional dependencies of clang and as such not removed by -Rs
Once clang is gone, they're no longer dependencies of anything.
-Qdtt will also list packages that are only optional dependencies (and could be removed without breaking package dependencies) but nb. that this might easily list packages you'd like to keep (for their features)
Also see https://gitlab.archlinux.org/pacman/pac … k_items/74
Offline
https://gitlab.archlinux.org/pacman/pac … _items/191
https://gitlab.archlinux.org/pacman/pac … _items/189The problem is that llvm and openmp are optional dependencies of clang and as such not removed by -Rs
Once clang is gone, they're no longer dependencies of anything....
Also see https://gitlab.archlinux.org/pacman/pac … k_items/74
Thanks seth for the thorough answer. Sounds like solving this will require scripting something myself based around https://crates.io/crates/alpm-db
Offline
If you're scripting you could just loop "pacman -Rsn $(pacman -Qdtq)" until pacman -Qdtq is empty?
Offline
If you're scripting you could just loop "pacman -Rsn $(pacman -Qdtq)" until pacman -Qdtq is empty?
IIUC the issue links indicate that approach could miss some edge cases e.g. an optional dependencies loop?
Offline
https://gitlab.archlinux.org/pacman/pac … k_items/74 is about interdependent packages
If A depends on B and B depends on A (ie. they're virtually the same package, split maybe to allow variants of one of them eg. B-gtk and B-qt both provide B) they will never be found as orphan dependency, even if there's no outer consumer that actually needs the both.
This isn't directly related to your situation and was rather FYI what else to keep in mind.
Offline