A convenient way to "purge" useless packages?
As many of you I guess, after a long time without reinstalling we have thousands of packages Installed, few days ago I ran out of storage in my root partition and needed to expand it. Is there a way to purge this thing ? I could think something like a list of packages which are not dependencies and haven't been used for a long time, is there a way to get such a list ? Thanks in advance
About this post
- Posted
- Archived
- Score
- 128 · 96% up
- Kind
- Text
- ID
- ig8ism
33 comments
Are you deleting the older packages from the pacman cache?
If you don't delete them it just keeps using space with the new versions, you can install pacman-contrib for the paccache script for a quick way to delete them.
As to packages that are no longer used you can check for orphans with this:
https://wiki.archlinux.org/index.php/Pacman#Querying_package_databases
Thanks, no I wasn't doing anything like that, bit what I meant by none used packages was packages that aren't needed by any other and haven't been launched in a while, like maybe I have 5 or 6 terminals in my system, tested them all and then only run termite last 3 months but forgot to delete them and want them to be listed
There's no way to list packages that you haven't launched, no.
You can use
pacman -Qeto list all explicitly installed packages though, and just go through the list removing anything you don't use anymore.You might want to check your package cache size too and clear out old packages. You can use
pacman -Scor you can check outpaccachefrom pacman-contrib.This.
Once I got my root partition full. Whith
duI found out the cache was using several GB.My favorite command is
du -hxd2 --time / | sort -rh | head.does this distinguish packages I installed myself vs. packages pulled as dependency?
can I list all packages installed myself and perhaps unmark them somehow, so they'll seen as orphans?
take a look at
man pacmanif you haven't (search for keywords with / and nN). For instance under-Qfor all the flags available for the query operation, which can be combined for a variety of use cases.Packages you installed (explicitly installed) will not show up under
pacman -QdtYou can list all explicitly installed packages withpacman -QeTo mark explicitly installed packages as dependencies (i.e unmark them):pacman -D --asdeps *package_name*(as sudo or root) *Edit: Markdown syntaxpacman -Rns $(pacman -Qtdq)
Let me see if I understand this.
-Q queries the package database
-t prints packages neither required nor optionally required by any installed packages.
-d lists packages that are installed as dependencies, and combined with -t lists orphans.
-q is just to print less info.
So pacman -Qtdq lists packages that were installed as dependencies but are no longer.
Wrapping it with -Rns will remove packages that are found in the sync database (-n) and all their dependencies (-s), using the output of -Qtdq as the package list.
Thanks.
The -q is needed to only print the names, otherwise the versions would be printed as well and pacman -Rns wouldn't work.
It should be noted though, that yay has a wrapper for this. Just do yay -c. If you're using a different helper (or none at all) just alias it
yay -c
Came here to say the same.
Here's a gist that does just that - https://gist.github.com/mtekman/9769fa3eb28dd0dbdd1e8ce802157e95
It was linked on an old post of mine, which you and others may still find interesting - https://www.reddit.com/r/archlinux/comments/dsnu81/hear_ye_archers_share_your_pacman_hooks/
I saved your post, definitely gonna check, thanks
BACKUP your system before do any of this.
list orphans (dependencies not required by any other packages, including the packages that installed during building the package from aur, set them to explicitly installed if you want to exclude them from orphans): pacman -Qdt
remove orphans ('q' mean show less info i.e name of package only): pacman -Rns $(pacman -Qdtq)
list of explicitly installed packages (remove 'q' to see more info of package i.e version/build). select and remove undesired packages (search on the internet to see if the selected packages is required by the system, if not, remove them at you own risk): pacman -Qenq
to remove package: pacman -Rns <package_name>
clear cache: pacman -Scc
see arch wiki for more.
Just yesterday I got back 5Gb from clearing the cache.
It’s worth removing dependencies (d) that aren’t needed anymore (t):
Take a look at the packages you installed (not dependencies) - unfortunately, I don’t know how to sort by date.
Most importantly, look around the file system. Spotify will build a multi-gig cache pretty quickly, for example. This is my favorite command:
Also try
ncdu. It's interactive.This....won't tell you about dangling packages but if you have anything else taking up space (VMs, cache, config, etc) this will find it.
Regarding the pacman cache, it's often in people's best interests to not wipe the cache entirely and instead keep like 1 or 2 old versions (just in case something breaks and you want to do a quick downgrade). See the wiki for how to use `paccache` for this.
https://wiki.archlinux.org/index.php/Pacman#Cleaning_the_package_cache
As others have said, pacman cache is worth clearing out.
Also, depending on what you use your system for, some digging around with
dumight be worthwhile. Maybe it's not installed software filling your disk but something else.Clearing the cache will give you more room.
Try this:
[Trigger]Operation = UpgradeOperation = InstallOperation = RemoveType = PackageTarget = *Description - Cleaning pacman cache...When = PostTransationExec = /usr/bin/paccache -rk2You need to fix step one. You don't want to create a directory called clean_package_cache.hook
Will you elaborate?
I wrote this 5 years ago, it should still be valid: https://scarpino.dev/posts/cleaning-an-arch-linux-installation.html
I thought it would be interesting to check the file in each package which was most recently accessed to see if there were any packages that I haven't used in a while. I'm learning python so I wrote this. Feel free to try it. For each package, it finds the most recently accessed file and prints the days since it was last accessed, the package, and the file name.
run it with python. No arguments will check all installed packages. Or you can give it some package names. Pipe it to sort -n to organize the results.
I don't think there's an easy way to find useless packages in the way you mean it because nothing is explicitly keeping track of when you're using the contents of a package. The other answers have already noted some ways in which you can get rid of useless packages, but here's another tip:
Sort the packages by size and consider whether you actually need the largest ones. Most are pretty small so this shouldn't take long. See here on how to do it.
Checking the atime of each file of each package would do this, right?
There's a pacman hook that will also delete old cached packages save the most recent 1-2, can help you automatically keep space free. See this thread