How to disable the APT cache

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.

Inspect APT cache configuration

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

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 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.

$ echo -e 'Dir::Cache::pkgcache "";\nDir::Cache::srcpkgcache "";' | sudo tee /etc/apt/apt.conf.d/00_disable-cache-files
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 these two files are relatively small and 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.

$ echo -e 'Dir::Cache "";\nDir::Cache::archives "";' | sudo tee /etc/apt/apt.conf.d/00_disable-cache-directories
Dir::Cache "";
Dir::Cache::archives "";

Remove downloaded packages.

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

Simple as that.

Milosz Galazka's Picture

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system.

Gdansk, Poland https://sleeplessbeastie.eu