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:
|
|
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
|
|
Examples:
|
|
Reinstall a Package
If a package is already installed but broken or corrupted:
|
|
3. Removing Packages
|
|
Tip: Always prefer
purgeoverremovewhen you are done with a package for good. Leftover config files fromremovecan cause confusion if you reinstall later.
4. Upgrading Your System
|
|
Upgrading a Single Package
|
|
5. Removing Unused Dependencies
When you remove a package, its dependencies are not automatically cleaned up. Over time these accumulate as orphaned packages:
|
|
6. Cleaning the Package Cache
APT caches downloaded .deb files in /var/cache/apt/archives/. This can grow large on a busy system:
|
|
7. Searching for Packages
|
|
apt show gives you the package version, maintainer, dependencies, description, installed size, and the homepage — useful before committing to an install.
8. Listing Packages
|
|
9. Checking Package Information
|
|
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)
|
|
Removing a PPA
|
|
11. Pinning — Holding a Package at a Specific Version
Prevent a package from being upgraded automatically:
|
|
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:
|
|
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.
