APT (Advanced Package Tool) is the front-end package management system used on Debian, Ubuntu, Linux Mint, and all their derivatives. Once you get comfortable with it, you will wonder how you ever managed software any other way. This guide walks through everything you need — from the basics to the commands most users never discover.


What Is APT?

APT sits on top of dpkg, the low-level Debian package tool. Where dpkg installs a single .deb file, APT resolves dependencies, fetches packages from remote repositories, and keeps your system consistent — automatically. Under the hood, the two main commands you will use are:

Command Purpose
apt Modern interactive CLI — recommended for everyday use
apt-get Older, script-friendly variant — use in shell scripts

For interactive terminal work, apt is cleaner and shows progress bars. For automation and scripts, prefer apt-get because its output format is stable across versions.


1. Keeping the Package Index Up to Date

Before installing or upgrading anything, sync your local package index with the remote repositories:

1
sudo apt update

This does not install or upgrade any packages — it only refreshes the list of what is available. Run this every time before installing something new.


2. Installing Packages

1
sudo apt install <package-name>

Examples:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Install a single package
sudo apt install curl

# Install multiple packages at once
sudo apt install git vim htop

# Install a specific version
sudo apt install nginx=1.24.0-1

# Install without the confirmation prompt (useful in scripts)
sudo apt install -y curl

Reinstall a Package

If a package is already installed but broken or corrupted:

1
sudo apt reinstall <package-name>

3. Removing Packages

1
2
3
4
5
6
7
8
# Remove the package but keep its configuration files
sudo apt remove <package-name>

# Remove the package AND its configuration files (clean uninstall)
sudo apt purge <package-name>

# Remove multiple packages at once
sudo apt purge nginx curl vim

Tip: Always prefer purge over remove when you are done with a package for good. Leftover config files from remove can cause confusion if you reinstall later.


4. Upgrading Your System

1
2
3
4
5
6
7
8
# Upgrade all upgradable packages (safe — will not remove packages)
sudo apt upgrade

# Full upgrade — may remove packages to resolve conflicts
sudo apt full-upgrade

# One-liner: update index then upgrade everything
sudo apt update && sudo apt upgrade -y

Upgrading a Single Package

1
sudo apt install --only-upgrade <package-name>

5. Removing Unused Dependencies

When you remove a package, its dependencies are not automatically cleaned up. Over time these accumulate as orphaned packages:

1
2
3
4
5
# Remove all automatically installed packages no longer needed
sudo apt autoremove

# Remove them without the confirmation prompt
sudo apt autoremove -y

6. Cleaning the Package Cache

APT caches downloaded .deb files in /var/cache/apt/archives/. This can grow large on a busy system:

1
2
3
4
5
# Delete cached packages that are no longer needed (safe)
sudo apt autoclean

# Delete ALL cached package files (frees more space)
sudo apt clean

7. Searching for Packages

1
2
3
4
5
6
7
8
# Search by name or description
apt search <keyword>

# Example — find all packages related to nginx
apt search nginx

# Show full information about a specific package
apt show nginx

apt show gives you the package version, maintainer, dependencies, description, installed size, and the homepage — useful before committing to an install.


8. Listing Packages

1
2
3
4
5
6
7
8
# List all installed packages
apt list --installed

# List packages with available upgrades
apt list --upgradable

# List all versions available in repositories
apt list --all-versions <package-name>

9. Checking Package Information

1
2
3
4
5
6
7
8
# What files does this package install?
dpkg -L <package-name>

# Which package does this file belong to?
dpkg -S /usr/bin/curl

# Show package status and details from the dpkg database
dpkg -s <package-name>

10. Managing Repositories (sources.list)

APT pulls packages from sources defined in:

  • /etc/apt/sources.list — main sources file
  • /etc/apt/sources.list.d/ — additional source files (one per repo)

Format of a source entry:

deb [signed-by=/usr/share/keyrings/repo.gpg] https://repo.example.com/apt stable main

Adding a PPA (Ubuntu)

1
2
sudo add-apt-repository ppa:owner/ppa-name
sudo apt update

Removing a PPA

1
2
sudo add-apt-repository --remove ppa:owner/ppa-name
sudo apt update

11. Pinning — Holding a Package at a Specific Version

Prevent a package from being upgraded automatically:

1
2
3
4
5
6
7
8
# Hold a package at its current version
sudo apt-mark hold <package-name>

# Release the hold (allow upgrades again)
sudo apt-mark unhold <package-name>

# List all held packages
apt-mark showhold

This is especially useful for kernel packages or database servers where you need to control upgrade timing carefully.


12. Fixing Broken Packages

Sometimes a failed installation or network interruption leaves the package system in an inconsistent state:

1
2
3
4
5
6
7
8
# Attempt to fix broken dependencies
sudo apt install -f

# Or with apt-get
sudo apt-get install --fix-broken

# Force-configure any packages left in an unconfigured state
sudo dpkg --configure -a

Quick Reference Cheat Sheet

Task Command
Refresh package index sudo apt update
Install a package sudo apt install <pkg>
Remove a package sudo apt remove <pkg>
Remove + config files sudo apt purge <pkg>
Upgrade all packages sudo apt upgrade
Full system upgrade sudo apt full-upgrade
Remove unused deps sudo apt autoremove
Clean package cache sudo apt autoclean
Search for a package apt search <keyword>
Show package details apt show <pkg>
List installed packages apt list --installed
List upgradable packages apt list --upgradable
Hold a package version sudo apt-mark hold <pkg>
Fix broken installs sudo apt install -f

Good Habits to Build

Always run apt update before installing. Repositories change and packages get updated. Skipping the update step means you may install an outdated version or hit dependency errors that would not exist with a fresh index.

Use purge when removing. Left-over configuration files from removed packages are a common source of confusion, especially with services like Apache or MySQL where old configs may conflict with a fresh install.

Audit autoremove before confirming. Glance at the list of packages autoremove wants to remove. Occasionally a package you care about gets flagged as a dependency orphan if you manually installed something it depends on.

Use apt-mark hold before major upgrades. If you are running a production server and a specific kernel or service version is known-good, hold it before running a full system upgrade.


APT is one of those tools that rewards the time you invest in learning it. The commands above cover the vast majority of real-world situations — bookmark this page and you will rarely need to reach for a GUI package manager again.