When you remove packages from Debian/Ubuntu systems, their dependencies may become orphaned. APT warns you about these unused packages that can be safely removed to free up disk space.
This message appears after updating or removing packages in Debian/Ubuntu systems. APT automatically installs dependencies when you install a package, but when you remove the main package, those dependencies may no longer be needed. APT identifies these orphaned packages and warns you about them, allowing you to reclaim disk space by removing them safely.
Use the --dry-run flag to see which packages will be removed without actually removing them. This is the safest approach to verify you're not removing anything important:
sudo apt autoremove --dry-runReview the list of packages carefully to ensure none of them are critical for your system.
Once you've reviewed the list and confirmed it's safe, execute the autoremove command to remove the unused packages and free up disk space:
sudo apt autoremoveYou may be prompted to confirm the removal. Press 'y' and Enter to proceed.
If you want to also remove configuration files associated with the removed packages, use the --purge flag:
sudo apt autoremove --purgeThis is optional but recommended for a complete cleanup.
If APT marks a package as auto-removable but you want to keep it, mark it as manually installed:
sudo apt-mark manual package-nameThis prevents the package from being removed in future autoremove operations.
To see all packages currently marked as automatically installed on your system:
apt-mark showautoYou can pipe this to grep to filter for specific packages if needed.
APT tracks package installation status in /var/lib/apt/extended_states. When a package is marked as 'Auto', it means APT installed it as a dependency and not by explicit user request. Running 'apt autoremove' periodically (especially after major system updates) helps maintain a clean system and recovers disk space. The command is safe because APT only removes packages that are not depended upon by any other installed package, protecting your system stability. Some systems like Debian testing may have different behavior, and you should always review what will be removed before confirming.
E: Cannot set to hold: package 'package-name' is not installed
How to fix "Cannot set to hold" error when package is not installed in APT
debconf: unable to initialize frontend: Dialog
How to fix "debconf: unable to initialize frontend: Dialog" in APT
E: Could not connect to proxy server
Could not connect to proxy server
dpkg: serious warning: files list file for package 'package-name' contains empty filename
How to fix "files list file contains empty filename" in APT
E: Package 'package:i386' has no installation candidate
How to fix "Package package:i386 has no installation candidate" in apt