And I don't just mean libraries that used to be dependencies, Fedora has rpmreaper which is perfect for this. What's a good rpmreaper equivalent for Arch?
I am always using
sudo pacman -Rsn $(pacman -Qdtq)
Use this command all the time, no worries for years now.
Could you give a quick description of what it does
pacman -Qdtq = list all installed packages[Q] that are depends[d] and also not required by any package [t], also dont list extra version info [q].
pacman -Rsn = remove this package(s)[R] recursively[s], meaning it will do this all again for unreq packages, and remove confs[n].
so together it lists all unrequired packages and then recursively uninstalls them, which just does the same thing for the orphaned packages.
man pacman or
pacman -Rh &
pacman -Qh would tell you this.
Just for clarity: It does not remove optional dependencies, which might delete additional features to programs?
Just packages that really aren't needed anymore?
It keeps them. For them to be removed, you'd need -Qdttq.
It still wants to delete things like
dkms. Did I install that for nothing or... should I be a bit more cautious?
You should be. It often removes things you do need, but it doesn't notice it.
Ok, now I'm confused. People say this command is safe and doesn't remove dependencies, but now it still does?
So... is there a safe command to delete really unneeded packages or how to approach it?
It doesn't remove needed depends, but programs marked as depends you may need.
No, some amount of your involvement is required to make sure that pacman doesn't try to remove packages you actually need.
Pacman can become confused because a package was installed with the "wrong" installation reason. If you notice pacman trying to remove something you need installed, reinstall it as an explicit package and not as a dependency.
Aaaaaah, so for example:
I get the
pacman -Qdtq and it would list and remove
cmake - but I need it.
pacman -S cmake and on the next
pacman -Qdtq it wouldn't be listed?
EDIT: Tested it quickly myself. Yes, this works. :)
So I'll now
pacman -Qdtq, look which packages I'd need. Uninstall them and reinstall needed ones everytime?
Maybe you don't need them?
Shouldn't I need them when using the AUR?
Also erm... what if I'll miss them? :(
Install them again :D
Obvious solution. :D
Will yaourt/the-build-process ask for given packages or will it error out and I have to see what's missing?
Because if it's asking anyway... trash them packages!
The arch wiki has a few commands that you might find interesting for package cleanup.
pkgbrowser (AUR) is a graphical tool that lets you see what packages you have installed, if they're orphans, theire dependecies, and so on
Thanks, this is very close to what I was hoping for. This plus just using pacman to do the actual uninstall works great.
Why would I build a tool from the AUR when I can run one command and it's done?
for the GUI
Because the dependency graph is complex and this is a perfect case where just a plain text list of packages in response to a single query just doesn't cut it. If you're ever using a RHEL based distro try rpmreaper and you'll see exactly what I mean. It's hard to display things like circular dependency chains using just pacman.
I just cleaned up a bunch of packages with
pacaur -Syau. I didn't finish the command. I just looked through the list and removed most of what it says "is not present in AUR." I figured these were packages that were removed from the repos and not placed on the AUR.
true qdtq i get it but i installed a shit load of dependecies? how about those
What do you consider to be "unneeded"? On one extreme, you don't need anything except what comes in
base. You can uninstall everything outside of
base like this:
$ comm -23 <(pacman -Qqt | sort) <(pacman -Qgq base | sort) | sudo pacman -Rns -
On the other extreme, maybe you need everything that you explicitly installed (and their dependencies), but not orphans. You can unstall those like this:
$ pacman -Qqdt | sudo pacman -Rns -
For any in-between case, you're going to have to intervene: pacman doesn't "know" what's needed or unneeded, because there's no strict definition of "unneeded". Your best bet is to study
man pacman and pacman tips and tricks to learn how to query your packages. For example, at some point you probably want to list all explicitly installed packages outside of
base-devel, etc. and cherry-pick what you want to uninstall, e.g. programs you no longer use.
Well specifically a faster way to cull old packages that were explicitly installed. Also, it needs to cover circular dependencies and not just show leaf nodes. What I was hoping for was some graphical or curses based UI to show the package graph. rpmreaper works amazing on RHEL based distros and I already manually cleaned up a bunch of unneeded packages using pacman but just having a plaintext list of packages to work with is a major pain. I figured surely I must be missing something, I guess I'm just spoiled.
On one extreme, you don't need anything except what comes in base.
Not quite right, I need grub or my PC won't boot.
AFAIK grub is better suited for legacy BIOS booting.
That's not true, if it's a vm you really don't need anything at all other than base. You can tell QEMU to boot a kernel from the host and just give it the root device of the guest.
Not talking about VMs though.
He's still right though. Even some of the stuff in base isn't strictly necessary.
pacman -Qdtq | sudo pacman -Rns -or
pacman -Qdttq | sudo pacman -Rns -. The first removes all unneeded packages, but leaves optional dependencies intact, while the second removes optional dependencies as well.
That's quite scary ! I ran the first command and pacman says there are 304 package 2G in total needs to be removed.
I usually do this, but instead of streaming it directly I throw the result of -Qdtq to a file
Read the file in order to ensure I'm not removing something I need, and then remove all the packages in the file
It's asking anyway and I could back out. And I usually know already what gets removed.
How "safe" is running the first command? As in, how big is the probability of breaking something? I'm relatively new to Arch and not entirely 100% confident yet.
Let's disect this:
So it returns all unneeded dependencies (and only their name), and then feeds that into the removal command. The second command with the two ts can (or rather will) potentially remove features from programs, because it also outputs optdepends. But you can't break anything that way.
Thank you, that explains it perfectly!
Thank you for the explanation. :)
But what about the dash after
Rns, as in
-Rns -? I have not seen that before.
The dash takes the output from the first command. Without it, the output from the first command wouldn't be piped to the second.
The dash is a convenient, used by many programs, to read from stdin.
Could do the same thing with
This commands now gives me an error:
-> translated ->
Used it normally like 3-4 weeks ago... hm. *chin-scratching emoji
If there is nothing to remove, it gives an error, because you just ran a pointless command.
Oh. Ok :) Thank you.