apt — Manage Packages on Debian and Ubuntu

Practical guide to apt — install, update, upgrade and remove packages on Debian and Ubuntu with the user-friendly high-level package-management frontend.

apt is the user-friendly, high-level frontend for package management on Debian and Ubuntu – it folds the most-used parts of apt-get and apt-cache into one tidy, readable command. Instead of remembering several tools, you install, update, search and remove packages with a single command, complete with automatic dependency resolution and a coloured progress bar. This guide walks you through the commands you actually reach for daily, from refreshing the package index to cleaning up orphaned dependencies.

Update & Upgrade

apt update — Update the package index (fetch latest package lists).

sudo apt update

apt upgrade — Upgrade all installed packages to their latest versions.

sudo apt upgrade

apt full-upgrade — Upgrade packages, adding/removing dependencies as needed.

sudo apt full-upgrade

apt update && apt upgrade -y — Update index and upgrade all packages (non-interactive).

sudo apt update && sudo apt upgrade -y

Install & Remove

apt install <package> — Install a package.

sudo apt install nginx

apt install <pkg1> <pkg2> — Install multiple packages.

sudo apt install curl wget git

apt install <package>=<version> — Install a specific version.

sudo apt install nginx=1.24.0-1

apt install -y <package> — Install without confirmation prompt.

sudo apt install -y docker-ce

apt reinstall <package> — Reinstall a package.

sudo apt reinstall openssh-server

apt remove <package> — Remove a package (keep config files).

sudo apt remove nginx

apt purge <package> — Remove a package including config files.

sudo apt purge nginx

apt autoremove — Remove unused dependencies (orphan packages).

sudo apt autoremove

Search & Info

apt search <query> — Search for packages by name or description.

apt search nodejs

apt show <package> — Show detailed info about a package.

apt show nginx

apt list --installed — List all installed packages.

apt list --installed

apt list --upgradable — List packages with available upgrades.

apt list --upgradable

apt depends <package> — Show dependencies of a package.

apt depends nginx

apt rdepends <package> — Show packages that depend on a package (reverse deps).

apt rdepends libssl3

Hold & Pin

apt-mark hold <package> — Hold a package at its current version (prevent upgrades).

sudo apt-mark hold linux-image-generic

apt-mark unhold <package> — Remove a hold (allow upgrades again).

sudo apt-mark unhold linux-image-generic

apt-mark showhold — List all held packages.

apt-mark showhold

apt-mark auto <package> — Mark a package as automatically installed (dependency).

sudo apt-mark auto libfoo

apt-mark manual <package> — Mark a package as manually installed.

sudo apt-mark manual nginx

Cleanup & Cache

apt clean — Delete all cached .deb packages.

sudo apt clean

apt autoclean — Delete cached .deb packages that can no longer be downloaded.

sudo apt autoclean

apt autoremove --purge — Remove unused dependencies and their config files.

sudo apt autoremove --purge

Repositories

add-apt-repository <ppa> — Add a PPA repository.

sudo add-apt-repository ppa:ondrej/php

add-apt-repository --remove <ppa> — Remove a PPA repository.

sudo add-apt-repository --remove ppa:ondrej/php

apt edit-sources — Edit the sources.list file.

sudo apt edit-sources

Conclusion

apt takes much of the friction out of package management on Debian and Ubuntu: one command, a consistent syntax and automatic dependency resolution – for everyday work you rarely need more than update, upgrade, install and search. Keep in mind, though, that write operations require sudo and touch your system: remove, purge and especially autoremove delete packages and sometimes configuration files too, and autoremove occasionally takes more than you expect – review the preview before you confirm. full-upgrade can also remove packages to resolve conflicts. Only add repositories and keys you trust (sources.list, PPAs), since they may install arbitrary software on your machine.

Further Reading

  • apk – Alpine Linux package manager
  • apt-get – the classic low-level package-management frontend
  • brew – the Homebrew package manager for macOS and Linux