76

I have recently installed Arch Linux and found that I am eating away at a lot of storage relatively quickly. For whatever reason I have already used 17GB in just about 2 weeks. I do not have a great deal of software installed so I am led to believe that all of the old packages are maintained somewhere.

To support this, I have noticed that if I installed a package, remove that package, and then re-install it that pacman merely unpacks and re-installs the software without having to re-download it.

After I installed my base system, before extra software, I used about 2GB or so maybe. I have since only installed Matlab, Skype, Wine, and a few other small programs. Of course I have also installed missing libraries and the like, but not nearly 15GB worth.

Am I completely wrong here or does Arch never delete old packages when downloading/upgrading to new versions?

If so, how do I delete these un-used packages?

Also, when I remove installed packages I use pacman -R ...

1
  • 1
    It's probably a good idea to set up paccache as a regular cron or systemd job.
    – Sparhawk
    Commented Jun 17, 2014 at 7:31

4 Answers 4

96

No, pacman doesn't remove old packages from your cache (/var/cache/pacman/pkg) so, over time, it can fill up.

You can adopt two approaches to clearing the cache: the brute force one with pacman -Sc:

-c, --clean
Remove packages that are no longer installed from the cache as well as currently unused sync databases to free up disk space. When pacman downloads packages, it saves them in a cache directory. In addition, databases are saved for every sync DB you download from, and are not deleted even if they are removed from the configuration file pacman.conf(5). Use one --clean switch to only remove packages that are no longer installed; use two to remove all files from the cache. In both cases, you will have a yes or no option to remove packages and/or unused downloaded databases.

Or, for a more nuanced approach, you can use one of the utilities that ships with pacman-contrib, paccache:

paccache is a flexible pacman cache cleaning utility, which has numerous options to help control how much, and what, is deleted from any directory containing pacman package tarballs.

By default, paccache -r will remove all but the last three versions of an installed package, but you can change this number with the -k, --keep switch. There is also a -d, --dryrun switch to preview your changes. You can also use the -m, --move <dir> option to move the packages to a separate directory of your choice. See paccache -h or paccache --help for all the switches.

There are a number of utilities in the pacman-contrib package to assist with package management, it is worth looking though them all and gaining an understanding of how they work and can make running Arch much easier. You can see the full list with:

pacman -Ql pacman-contrib | awk -F"[/ ]" '/\/usr\/bin/ {print $NF}'
5
  • jasonwryan said it :) Also be really careful with the double --clean switch: that forbids easily reverting to the working package, in case any issue happens with the latest version (eg new package relies on an older lib or Python release; same with hardware and latest kernel). I find setting the pacman cache elsewhere than / a much better solution (just set the path in /etc/pacman.conf).
    – tuk0z
    Commented Jul 28, 2015 at 16:19
  • 4
    If you don't have paccache you can get it by installing the pacman-contrib package.
    – pfrenssen
    Commented Jun 1, 2018 at 6:43
  • +1, but I suggest $ pacman -Ql pacman-contrib | awk -F"[/ ]" '/\/usr\/bin\/./ {print $NF}' to avoid a blank line in results ? ;-)
    – Cbhihe
    Commented Sep 27, 2018 at 16:31
  • 1
    Welp, rm -rf /var/cache/pacman/pkg was the wrong thing to do
    – Post Self
    Commented Oct 10, 2018 at 6:38
  • relevant page the ArchWiki: wiki.archlinux.org/index.php/pacman#Cleaning_the_package_cache
    – Trevor
    Commented Jan 30, 2019 at 7:23
17

Your package cache is in /var/cache/pacman/pkg/.

NOTE: pacman packages were updated in 2018 and additionally require installing pacman-contrib to use scripts/tools like paccache described below.

Do:

paccache -d

To do a -dryrun and see what a run of that utility might remove when you next do:

paccache -r

To remove cached packages. 17gbs does sound steep. Make sure you haven't got some run-away logs. Do:

du -h /var/log

Or even just:

du -h /var

For a more general idea of what's going on.

11

I strongly suggest the use of paccache instead of pacman -Sc. There is even a very effective flag for removing selectively the versions of uninstalled packages -u. The flags of paccache I recommend are (as part of paccache v5.0.2):

  • -d, --dryrun: perform a dry run, only finding candidate packages
  • -r, --remove: remove candidate packages
  • -u, --uninstalled: target uninstalled packages only
  • -k, --keep <num>: keep "num" of each package in the cache (default: 3)

Example: Check for remaining cache versions of uninstalled packages

paccache -dvuk0
5
  • 1
    How does this add to the existing answers, other than printing out the options?
    – jasonwryan
    Commented Oct 25, 2017 at 23:18
  • 1
    If you removed a lot of unused big packages, you want to remove them from pacman's cache. This is possible with the flag -u of paccache. Examples of big packages are e.g. Gnome, KDE, or Texlive to give you an idea.
    – strpeter
    Commented Oct 26, 2017 at 9:53
  • 1
    Yes, I am familiar with the flag. My point is just adding more flags to the answer doesn't change the fact that it just replicates what is already here.
    – jasonwryan
    Commented Oct 26, 2017 at 14:55
  • the -k flag was new to me and not very well explained in the help dialog, so its usage here was useful.
    – hLk
    Commented Sep 17, 2019 at 6:04
  • +1 for paccache -dvuk0, just what I needed for easy and safe cleanup of my pacman cache. Use paccache -rvuk0 to apply. Commented Nov 8, 2022 at 21:52
8

pacman -Scc does what you're asking, but it's not recommended. From the Wiki

It is also possible to completely empty the cache folder with pacman -Scc, but doing it is considered bad practice, as, in addition to the above, it also prevents from reinstalling a package directly from the cache folder in case of need, thus forcing to redownload it. You should never use it unless there is a desperate need for more disk space.

As an aside, when I uninstall packages, I prefer to use pacman -Rnsc, since it also removes package dependencies as well as packages that depend on this one. As always, read carefully which packages are being removed, since you could very easily leave our system in an unusable state.

2
  • That's cool - so it's equivalent to rm /var/cache/pacman/pkg/* then? Or - it as at least by default, I guess. I've relocated my pkg cache to /tmp on most machines a long time ago and let squid handle a single central cache at the router. Not as easy as pacman -Scc though.
    – mikeserv
    Commented Jun 16, 2014 at 4:27
  • @mikeserv A central Pacman package cache at your router? How did you set it up, I like the sound of it since I have both an Arch desktop and laptop.
    – severen
    Commented Feb 13, 2016 at 9:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .