This post was originally published on go2linux.org on March 13, 2008. The domain is no longer mine, but I am the original author. I am republishing it here on garron.me with corrections and improvements.

Introduction

Both apt-get and aptitude are front-ends for the APT package management system on Debian-based distributions. They can install, remove, and upgrade packages, but they handle dependency cleanup differently.

The orphan package problem

When you install a package, APT also installs any required dependencies. When you later remove the main package, those dependencies may be left behind — wasting disk space and cluttering the system. These leftover packages are called orphans.

apt-get and autoremove

apt-get remove only removes the package you specify. It leaves orphaned dependencies behind and tells you about them:

The following packages were automatically installed and are no longer required:
  libxvidcore4 libamrnb3 libx264-57 ...
Use 'apt-get autoremove' to remove them.

To remove both the package and its orphaned dependencies at once, use autoremove:

sudo apt-get autoremove mplayer

Or, after a plain remove, run autoremove separately to clean up all accumulated orphans:

sudo apt-get autoremove

aptitude

aptitude tracks which packages were installed manually versus automatically. When you remove a package, it automatically marks the orphaned dependencies for removal — no extra step needed:

sudo aptitude remove mplayer

apt — the modern command

Since Ubuntu 16.04 and Debian 9, the apt command is the recommended tool for interactive use. It merges the most common apt-get and apt-cache operations into a single, friendlier interface with progress bars and colored output:

sudo apt install mplayer
sudo apt remove mplayer
sudo apt autoremove
sudo apt update && sudo apt upgrade
sudo apt search keyword
sudo apt show mplayer

apt-get and apt-cache remain the standard in scripts because their output format is guaranteed stable across releases.

apt-mark — controlling automatic/manual status

You can explicitly control whether APT treats a package as manually or automatically installed. This affects whether autoremove will remove it:

sudo apt-mark manual mplayer     # keep it — autoremove will never touch it
sudo apt-mark auto mplayer       # mark as auto — autoremove may remove it
apt-mark showmanual              # list all manually installed packages
apt-mark showauto                # list all automatically installed packages

This is useful when you want to protect a dependency from being removed, or when you want to clean up a package you no longer need but installed manually long ago.

Which to use today

  • Day-to-day interactive use: apt
  • Shell scripts: apt-get (stable output)
  • Complex dependency resolution: aptitude

Quick reference

| Task | apt | apt-get | |---|---|---| | Install | apt install pkg | apt-get install pkg | | Remove | apt remove pkg | apt-get remove pkg | | Remove + clean orphans | apt autoremove pkg | apt-get autoremove pkg | | Update package lists | apt update | apt-get update | | Upgrade all packages | apt upgrade | apt-get upgrade | | Full upgrade | apt full-upgrade | apt-get dist-upgrade | | Search | apt search term | apt-cache search term | | Show package info | apt show pkg | apt-cache show pkg |