2

I am performing an apt-get update prior to installing some packages:

Get:1 http://archive.ubuntu.com trusty Release.gpg [933 B]
Get:2 http://archive.ubuntu.com trusty-updates Release.gpg [933 B]
...
...
Get:23 http://archive.ubuntu.com trusty-security/restricted amd64 Packages [40 B]
Get:24 http://archive.ubuntu.com trusty-security/universe amd64 Packages [58.0 kB]
Fetched 20.0 MB in 2min 57s (113 kB/s)

As can be seen above, apt-get has fetched 20.0 MB of indexes. After the apt-get update and the apt-get install mypackage, I would like to clean up all caches to minimise the disk space used.

Question 1: Where are the apt package indexes stored on the file system?

Question 2: How can I safely remove the indexes?

2 Answers 2

4

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.

1
  • Another note: rm -f will intentionally skip the partial subfolders. So use that instead of a potential rm -rf - see my introductory remarks at the top. Jun 1, 2015 at 16:26
-1

Have a look at /var/cache/apt folder. Both the index files and downloaded package files reside there. For cleanup, you can check an older question thread here .

1
  • The linked question does not address the index files directly under /var/cache/apt (i.e. *.bin). The alleged (but not in fact) "duplicate" of your link here asks about those index files in particular, but the answers are wrong. The index files can be safely removed (as of Ubuntu 14.04, which I tested) as the next apt-get update will regenerate those files. The files in /var/cache/apt/archives can be cleaned using apt-get clean. Jun 1, 2015 at 16:01

You must log in to answer this question.

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