Skip to content

How to clear the APT cache

Last updated on March 13, 2019

Clear the APT cache to reclaim disk space used by the downloaded packages.

Inspect APT cache configuration

Check out the current APT cache configuration 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/";

Remove every package from the cache

Perform a simulation of the whole process.

$ sudo apt-get clean --dry-run
Del /var/cache/apt/archives/* /var/cache/apt/archives/partial/*
Del /var/lib/apt/lists/partial/*
Del /var/cache/apt/pkgcache.bin /var/cache/apt/srcpkgcache.bin

Remove retrieved package files.

$ sudo apt-get clean

Remove outdated packages from the cache

$ sudo apt-get autoclean --dry-run

Remove retrieved package files that can no longer be downloaded.

$ sudo apt-get autoclean

 

credit: https://blog.sleeplessbeastie.eu/2017/10/09/how-to-clean-the-apt-cache/

Published inLinux