Disable APT cache to conserve disk space on a small Debian based embedded system or a custom-built live USB system that can be easily booted.

This blog post is now obsolete.

Inspect APT cache configuration

By default, cache files are located in /var/cache/apt/ directory and its sub-directories. Downloaded packages are stored in the archives directory, including incomplete files kept in the partial sub-directory.

Cache lookup information is stored using pkgcache.bin and srcpkgcache.bin files.

$ file /var/cache/apt/{,src}pkgcache.bin
/var/cache/apt/pkgcache.bin:    APT cache data, version 11.0, little-endian, 65552 packages, 65557 versions
/var/cache/apt/srcpkgcache.bin: APT cache data, version 11.0, little-endian, 65551 packages, 65556 versions

You can verify these configuration options using the following command.

$ apt-config dump | grep "^Dir\( \|::Ca\)"
Dir "/";
Dir::Cache "var/cache/apt";
Dir::Cache::archives "archives/";
Dir::Cache::srcpkgcache "srcpkgcache.bin";
Dir::Cache::pkgcache "pkgcache.bin";
Dir::Cache::Backup "backup/";

Disable package and source cache lookup files

You can disable the package cache file (by default pkgcache.bin), which is used as a primary cache for all operations and source cache file (by default srcpkgcache.bin), which refers to the source packages.

Disable package and source cache lookup files.

$ sudo tee /etc/apt/apt.conf.d/00_disable-cache-files <<EOF
Dir::Cache::pkgcache "";
Dir::Cache::srcpkgcache "";
Dir::Cache::pkgcache "";
Dir::Cache::srcpkgcache "";

Remove package and source cache lookup files.

$ sudo rm /var/cache/apt/pkgcache.bin
$ sudo rm /var/cache/apt/srcpkgcache.bin

Notice that APT will need to reparse all of the package version information during its operations, so it can make things slightly slower.

Disable package cache

Depending on the installed packages, this can free up a lot of space as every package is downloaded and stored in the cache archive.

Disable package cache.

$ sudo tee /etc/apt/apt.conf.d/00_disable-cache-directories << EOF
Dir::Cache "";
Dir::Cache::archives "";
Dir::Cache "";
Dir::Cache::archives "";

Remove downloaded packages.

$ sudo rm /var/cache/apt/archives/partial/*
$ sudo rm /var/cache/apt/archives/*

Simple as that.