4

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 Answers2

6

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.

0xC0000022L
  • 5,870
-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 .

JSBach
  • 1,425