APT package cache (apt clean and autoclean)
The APT package cache is the folder /var/cache/apt/archives, where apt and apt-get keep downloaded .deb package files on Debian, Ubuntu and related distributions. apt-get clean removes all cached packages, apt-get autoclean removes only those that can no longer be downloaded, and apt autoremove removes packages that nothing needs any more.
1What each command does
clean removes everything except the lock file from /var/cache/apt/archives and its partial folder. The packages remain installed; only the downloaded copies go.
autoclean deletes cached package files that are no longer available in the repositories, which keeps the cache from growing forever.
autoremove uninstalls packages that were installed automatically as dependencies and are no longer required, such as old kernels on Ubuntu.
2Seeing the size
du -sh /var/cache/apt/archives shows how much space the cache uses.
How to clean the APT cache
- Check the size:
du -sh /var/cache/apt/archives - Remove all cached packages:
sudo apt-get clean - Review what would be removed:
apt-get -s autoremove - If the list looks right:
sudo apt autoremove
Cautions
- Read the autoremove list before confirming: a package you use can be listed if it was installed only as a dependency.
- Keep at least one older kernel you know boots.
Related articles
- Disk usage with du and ncduHow to find what fills a Linux disk with du and the interactive ncdu, with options that stay on one file system.
- df (disk free)How to read df output, why Use% can reach 100% before Avail is zero for normal users, and how to check inodes with df -i.
- journalctl and the systemd journalHow to read logs with journalctl, check how much space the journal uses and shrink it safely with --vacuum options.
Sources
- apt-get(8) (Debian) manpages.debian.org
- apt(8) (Debian) manpages.debian.org
Last reviewed: