brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: apt-get autoclean keeps the cache but drops .deb files that are out of date

Apt
~/tips/tip-apt-get-autoclean

sudo apt-get -s autoclean

Removes only cached package files that can no longer be downloaded.

apt clean empties the whole package cache. autoclean is the gentler version: it keeps what is still current and deletes the rest.

Run it after an upgrade, with -s first if you want to see what goes:

sudo apt-get -s autoclean
sudo apt-get autoclean
du -sh /var/cache/apt/archives

It removes .deb files that your repositories no longer offer, which in practice means the old versions replaced by an upgrade. Packages that are still the current version stay in the cache.

Why keep them at all? A cached current version lets you reinstall a package without downloading it again, for example with apt install --reinstall when a file got damaged, or on a machine with a slow or capped connection. I’d use autoclean on such machines and plain clean on servers where disk space matters more.

apt can also do this on a timer. On Ubuntu, APT::Periodic::AutocleanInterval in /etc/apt/apt.conf.d/ sets how many days pass between automatic autocleans, and 0 turns it off.

Don’t expect miracles. On a server with a fast connection the cache is often small anyway, because apt removes downloaded files after installing when Binary::apt::APT::Keep-Downloaded-Packages is false, which is the default for the apt command. apt-get keeps them. Check with du before you bother.

Further reading: apt-get(8) manual page, apt.conf(5) manual page

More Apt tips sudo apt-mark minimize-manual apt list '~c' grep -E ' (install|upgrade|remove) ' /var/log/dpkg.log | tail -o Dpkg::Options::="–force-confold" upgrade sudo apt-get -d -y full-upgrade All Apt tips (42) All topics

Link