pacman - Arch Linux's package manager - is a great application, and one I probably use every single day, which - given Arch's rolling release principle - I'm sure is the case of many others as well.
Whenever pacman downloads a package, whether because you install something new,
or when you do an update, said packages will be stored in its cache (usually in
/var/cache/pacman/pkg). And then, nothing.
pacman will never remove anything from its cache (*), and it's a good thing because should you e.g. ever want to downgrade some package to a previous version for one reason or another, your cache is probably the best place to find what you're looking for.
(*) Actually, it can, but only if you ask him to. See below.
But if your cache keeps growing and only ever growing, over time it'll get pretty fat. And while keeping old versions is good, there's no point to keep every single version of everything you ever installed.
Now, you can actually do some cleaning through pacman and its
but this will be pretty basic: either remove every packages but the ones
currently installed, or just remove everything. (Note: this is assuming you use
default options (
CleanMethod = KeepInstalled), you could also used
KeepCurrent to keep any packages present in a sync database.)
When I noticed my pacman's cache kept growing, I wondered if I couldn't trim it
a little bit. Not get rid of everything, and keep more than what a
would do, but still remove unneeded packages. And so I made PkgClip.
Find a reason for your action
PkgClip is a little helper utility that will scan pacman's cache, and classify every package into different groups, also called "reasons." Reasons, because they'll be used to determine whether a package should be kept, or removed. (Well, to determine the recommended action, up to you to go with it or not, of course.)
Note: All packages usually have a version number, that of the installed
software, alongside a package release number. That is, package
would be for foobar v1.2.3; and it is the fourth package release for that
For each package, PkgClip will check whether or not it is installed on the system. The test will determine whether this version of the package is installed, or another one. Based on this, each package will fall under one of the following :
- Package of a version more recent than the one currently installed; Marked to Keep.
- Package of the currently installed version; Marked to Keep
- Package of the same version but a previous package release (pkgrel); Marked to Remove
- Package of an older version. You can define how many of those you'd like to keep. As many will be marked to Keep, any other (i.e. the oldest ones, of course) will be marked to Remove
- Package for which no version is currently installed; Marked to Remove
As a result, you might have quite a few packages marked to be removed, but still
keep a few more than what
pacman -Sc would do. Of course you can tweak this
- You can define how many older versions to keeping
- You can set not to remove old package releases, that is a package of the same
version but a previous package release will simply be treated as an old
- Finally, all of this only defines the recommended/default values for each
packages. You can obviously then review the list and manually add/remove
packages to be removed as you wish.
Actual removal of the files: PolicyKit required
As you probably know, you cannot actually just run
pacman -Sc from your
terminal, if you're logged in as a regular user. Because those files belong to
root and therefore root privileges are required to do anything.
PkgClip is not intended to be run as root of course, and will rely on PolicyKit to ensure correct authorization has been granted. Obviously it requires you to have PolicyKit installed, but also (assuming default configuration) a PolicyKit agent, which is the one in charge of asking for your/root password and making sure you don't just press random keys and whatnot.
That's about it. Everything should be pretty straight-forward; hopefully this might be useful to some. As hinted above, DBus and PolicyKit are required for PkgClip to work. It also requires libalpm 7 (pacman 4) and GTK3.
PkgClip is released under GNU GPL v3+ The source code is available on this BitBucket repository.
For Arch Linux users, you can also find a PKGBUILD in the AUR.
And of course bug reports, suggestions or any other form of constructive criticism is very much welcome.