Introduction / Why This Is Needed
When working with the APT package manager in Debian, Ubuntu, and derivative systems, packages that were automatically installed as dependencies for other programs but are no longer needed by anything accumulate over time. These can be libraries, modules, or utilities.
The sudo apt autoremove command is a safe and standard way to clean this "junk" from your system. It analyzes dependencies and removes packages that:
- Were installed automatically (not explicitly by the user).
- Are not required by any currently installed packages.
Regular use of autoremove helps:
- Free up disk space (especially relevant for SSDs).
- Simplify package management — shorten the list in
apt list --installed. - Reduce security risks — remove code that is unused and not updated.
- Maintain system cleanliness after removing major applications (e.g.,
sudo apt remove firefoxwill leave many dependencies behind).
Requirements / Preparation
- Operating System: A Debian/Ubuntu-based distribution (Debian, Ubuntu, Linux Mint, Kali, Pop!_OS, etc.).
- Access Permissions: Superuser (root) privileges are required. You will use
sudo. - Network: Not strictly necessary for
autoremoveitself, but recommended for a subsequentapt cleanor if you wish to update the package list first (sudo apt update). - Backup (Optional): As a precaution if you are removing packages with important configurations. Usually not critical for autoremove.
Step-by-Step Guide
Step 1: Preview (Super Important!)
Never run removal commands without understanding what will be deleted. Use simulation:
sudo apt autoremove --dry-run
Or the short form:
sudo apt autoremove -s
What you will see: At the end of the output, there will be a block starting with the line The following packages will be REMOVED:. This list contains the packages apt plans to remove. Check it carefully. If the list includes anything familiar that seems important (e.g., python3, libc6, openssl), stop and investigate.
Step 2: Perform the Removal
If the list from --dry-run is acceptable (usually libraries like libxxx, packages named xxx-common or xxx-doc), run the actual removal:
sudo apt autoremove
APT will show the same list and ask for confirmation:
The following packages will be REMOVED:
libfoo1 libbar2 baz-common
0 upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
After this operation, 45.3 MB of additional disk space will be freed.
Do you want to continue? [Y/n]
Press Y (or Enter, since Y is the default) to confirm.
Step 3: Clean Package Cache (Optional but Recommended)
After removing packages, their downloaded .deb files may still occupy space in the APT cache (/var/cache/apt/archives). To delete them:
sudo apt clean
This command removes all files from the cache. If you want to keep already downloaded files for potential reinstallation without re-downloading, use sudo apt autoclean (removes only obsolete files).
Step 4: Verify the Result
You can confirm that space was freed in two ways:
- Note the freed space: The
apt autoremoveoutput included a line likeAfter this operation, ... will be freed. Remember this value. - Check current disk usage: Use
df -hto see free space on the/partition ordu -sh /var/cache/apt/archivesbefore and afterapt clean.
Also verify the packages were removed:
dpkg -l | grep -E "(libfoo|libbar|baz-common)"
(replace with the actual package names from your list). The command should produce no output if the packages were removed.
Potential Issues
⚠️ Important:
apt autoremovemight propose removing a package you consider core system software (e.g.,libc6orsystemd). This is almost always an error or a sign of serious dependency problems. Do not confirm such a removal. In this case:
- Stop the process (press
n).- Investigate why the package is marked as "automatically installed" and "no longer needed". Possibly some package you installed declared dependencies incorrectly.
- Try to fix broken dependencies:
sudo apt --fix-broken install.- If the problem persists, search for the specific package online or on bugs.debian.org / launchpad.net.
💡 Tip: If you are unsure about a specific package in the list, you can temporarily prevent its removal by marking it as "manually installed":
sudo apt-mark manual <package_name>After this,
apt autoremovewill not propose to remove it.