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 updateapt upgrade — Upgrade all installed packages to their latest versions.
sudo apt upgradeapt full-upgrade — Upgrade packages, adding/removing dependencies as needed.
sudo apt full-upgradeapt update && apt upgrade -y — Update index and upgrade all packages (non-interactive).
sudo apt update && sudo apt upgrade -yInstall & Remove
apt install <package> — Install a package.
sudo apt install nginxapt install <pkg1> <pkg2> — Install multiple packages.
sudo apt install curl wget gitapt install <package>=<version> — Install a specific version.
sudo apt install nginx=1.24.0-1apt install -y <package> — Install without confirmation prompt.
sudo apt install -y docker-ceapt reinstall <package> — Reinstall a package.
sudo apt reinstall openssh-serverapt remove <package> — Remove a package (keep config files).
sudo apt remove nginxapt purge <package> — Remove a package including config files.
sudo apt purge nginxapt autoremove — Remove unused dependencies (orphan packages).
sudo apt autoremoveSearch & Info
apt search <query> — Search for packages by name or description.
apt search nodejsapt show <package> — Show detailed info about a package.
apt show nginxapt list --installed — List all installed packages.
apt list --installedapt list --upgradable — List packages with available upgrades.
apt list --upgradableapt depends <package> — Show dependencies of a package.
apt depends nginxapt rdepends <package> — Show packages that depend on a package (reverse deps).
apt rdepends libssl3Hold & Pin
apt-mark hold <package> — Hold a package at its current version (prevent upgrades).
sudo apt-mark hold linux-image-genericapt-mark unhold <package> — Remove a hold (allow upgrades again).
sudo apt-mark unhold linux-image-genericapt-mark showhold — List all held packages.
apt-mark showholdapt-mark auto <package> — Mark a package as automatically installed (dependency).
sudo apt-mark auto libfooapt-mark manual <package> — Mark a package as manually installed.
sudo apt-mark manual nginxCleanup & Cache
apt clean — Delete all cached .deb packages.
sudo apt cleanapt autoclean — Delete cached .deb packages that can no longer be downloaded.
sudo apt autocleanapt autoremove --purge — Remove unused dependencies and their config files.
sudo apt autoremove --purgeRepositories
add-apt-repository <ppa> — Add a PPA repository.
sudo add-apt-repository ppa:ondrej/phpadd-apt-repository --remove <ppa> — Remove a PPA repository.
sudo add-apt-repository --remove ppa:ondrej/phpapt 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
- Debian Wiki: Apt – introduction to package management with apt
- Ubuntu Server docs: Package management – official Ubuntu guide to installing and managing software