We are in springtime and usually in springtime you make some cleaning. Today I decided to clean my old desktop that is running the same Arch Linux installation since 2007.
Warning: this whole task requires a bit of knowledge about what a package does and why it is installed on your system. You could break something, but IMHO in the worst case you will re-install it later ;-)
So, I started by listing any package I didn’t install:
$ pacman -Sqg base base-devel | sort -u > /tmp/essentials
$ pacman -Qqe | sort > /tmp/explicit
$ comm -13 /tmp/essentials /tmp/explicit > /tmp/unknown
Read /tmp/unknown and mark as “installed as dependence” any package you didn’t install or simply you don’t know. This last step requires a knowledge of what a package do;
pacman -Qi and
pacman -Ql are your friend here!
To mark a package as dependence run:
# pacman -D --asdeps <pkg>.
Now, the harmful part! Run
# pacman -Rscn $(pacman -Qqtd). It will remove any package installed as dependence plus the packages needed by it because installed as dependence that are no more required without it. Do not rush and read the packages you are going to remove!
In my case, even after all those years I only got 14 packages…I’m too careful. I always mark as dependence the package I don’t use anymore and I periodically check the output of
Now, you could also remove the orphaned files on your system by using
lostfiles (download from AUR). In fact,
# lostfiles relaxed > /tmp/lostfiles will produce a list of files that are owned by no package, but it also excludes something from that list which makes things easier for your brain.
Update: an user suggested to also check the output of
pacman -Qqttd (note the extra ‘t’); this one also lists optional dependencies. Thanks!