Linux

apt autoremove: How to Properly Remove Unnecessary Packages in Linux

This guide explains what apt autoremove is and how to use it safely to remove automatically installed dependencies that are no longer needed. Learn to clean your system without risking removal of critical components.

Updated at February 16, 2026
5-10 minutes
Easy
FixPedia Team
Применимо к:Debian 11/12Ubuntu 20.04/22.04/24.04Linux Mint 21+Kali Linux

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:

  1. Were installed automatically (not explicitly by the user).
  2. 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 firefox will leave many dependencies behind).

Requirements / Preparation

  1. Operating System: A Debian/Ubuntu-based distribution (Debian, Ubuntu, Linux Mint, Kali, Pop!_OS, etc.).
  2. Access Permissions: Superuser (root) privileges are required. You will use sudo.
  3. Network: Not strictly necessary for autoremove itself, but recommended for a subsequent apt clean or if you wish to update the package list first (sudo apt update).
  4. 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.

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:

  1. Note the freed space: The apt autoremove output included a line like After this operation, ... will be freed. Remember this value.
  2. Check current disk usage: Use df -h to see free space on the / partition or du -sh /var/cache/apt/archives before and after apt 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 autoremove might propose removing a package you consider core system software (e.g., libc6 or systemd). This is almost always an error or a sign of serious dependency problems. Do not confirm such a removal. In this case:

  1. Stop the process (press n).
  2. Investigate why the package is marked as "automatically installed" and "no longer needed". Possibly some package you installed declared dependencies incorrectly.
  3. Try to fix broken dependencies: sudo apt --fix-broken install.
  4. 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 autoremove will not propose to remove it.

F.A.Q.

Can apt autoremove remove something important?
How does autoremove differ from purge?
Is it necessary to run autoremove after every update?
What to do if autoremove wants to remove a package I need?

Hints

Check what will be removed
Run the removal
Additional cleanup (optional)
FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community