NB: all of the following was tested on Ubuntu 14.04.
Up front: don't remove any directories, just files inside of the directories. Also make sure no apt-related processes are running (or could get auto-started during your cleanup).
/var/cache/apt/archives/*
The files in /var/cache/apt/archives
, i.e. the downloaded packages, can be cleaned using apt-get clean
. This is the method that is linked in the other answer.
/var/cache/apt/*.bin
As long as you ensure that no apt-related process is running the index files /var/cache/apt/pkgcache.bin
and /var/cache/apt/pkgcache.bin
can also be cleaned out. Unless they are leftover, there should not be any other files that would match /var/cache/apt/*.bin
, but you can remove them using that pattern as long as no apt-related process is running.
The next run of apt-get update
will regenerate these files.
Unfortunately this question asking about the index files was closed as duplicate, although it isn't a duplicate at all.
/var/lib/apt/lists/*
You can also remove the cached package lists, but might want to leave the lock file untouched.
Yes, the file lock
can also be removed, provided no apt-related processes are running or would start during cleanup. But I mentioned that already once or twice.
Rationale
I wondered about this possibility to be able to create a template archive to use for creation of containers (LXC, Docker). In such a case you usually want to trim down the system as much as possible before packaging.
Turns out it is harmless to remove the files. In my particular case I can be sure no apt-related processes are running, as the "system" - after the chroot
part finishes - isn't actually running.
Potential apt-related processes
cron-apt
, but also unattended-upgrades
and similar would be examples apt-related processes that you don't want to run during a cleanup.