apt autoremove
apt autoremove removes packages that were installed automatically as dependencies of other packages and are no longer needed by any installed package. On Debian and Ubuntu it frees space after programs are removed and after kernel updates, when older kernel packages are no longer required.
1Manual and automatic packages
APT marks every package as manually installed (you asked for it) or automatically installed (pulled in as a dependency). When nothing depends on an automatic package any more, apt lists it as 'no longer required'. apt-mark showmanual and apt-mark showauto show the two groups.
2Old kernels
On Ubuntu, older kernel packages become removable after newer kernels are installed. The running kernel and the newest ones are kept, so a fallback kernel remains in the boot menu.
3Keeping a package
If autoremove lists a package you use, sudo apt-mark manual <package> marks it as manually installed and autoremove will keep it.
How to use autoremove safely
- Preview what would be removed:
apt-get -s autoremove - Read the list; mark anything you use as manual:
sudo apt-mark manual <package> - Remove the rest:
sudo apt autoremove - To also delete their configuration files:
sudo apt autoremove --purge
Cautions
- Removing a package you installed by hand as a dependency can break scripts that use it; check the list first.
- Do not remove the running kernel;
uname -rshows which one it is.
Related articles
- APT package cache (apt clean and autoclean)Where APT keeps downloaded .deb files, how apt clean, autoclean and autoremove differ, and what is safe to remove on Debian and Ubuntu.
- 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.
- Finding large and old files with findHow to use find to list big or old files on Linux, preview them safely and delete only what you checked.
Sources
- apt-get(8) manual page (Ubuntu) manpages.ubuntu.com
- apt-mark(8) manual page (Debian) manpages.debian.org
Note: RainServer offers monitoring and safe cleanup for Linux servers; it shows what will change and asks first.
Last reviewed: