apt-get — The Classic Debian/Ubuntu Package Tool
Practical guide to apt-get — the stable, low-level APT tool for Debian and Ubuntu: ideal for scripts, CI and Docker thanks to its predictable output.
apt-get is the classic, script-stable low-level tool of the APT package management system on Debian and Ubuntu. While the newer apt is optimised for a polished, interactive terminal experience, apt-get keeps a stable output format and a fixed set of options across versions – which is exactly why you should prefer it over interactive apt in scripts, CI pipelines and Dockerfiles. This guide walks you through the commands you reach for daily: from updating the package index and installing or removing packages to the options for fully automated, non-interactive runs.
Update & Upgrade
apt-get update — Update the package index.
sudo apt-get updateapt-get upgrade — Upgrade all packages (never removes packages).
sudo apt-get upgrade -yapt-get dist-upgrade — Smart upgrade: may add/remove packages to satisfy dependencies.
sudo apt-get dist-upgradeInstall & Remove
apt-get install <package> — Install a package.
sudo apt-get install -y nginxapt-get install --no-install-recommends <package> — Install without recommended packages (smaller footprint).
sudo apt-get install --no-install-recommends php8.3apt-get install -f — Fix broken dependencies.
sudo apt-get install -fapt-get remove <package> — Remove a package (keep config).
sudo apt-get remove nginxapt-get purge <package> — Remove a package and its config files.
sudo apt-get purge nginxapt-get autoremove — Remove unused dependencies.
sudo apt-get autoremove -yDownload & Source
apt-get download <package> — Download a .deb package without installing.
apt-get download nginxapt-get source <package> — Download the source package.
apt-get source nginxapt-get build-dep <package> — Install build dependencies for a source package.
sudo apt-get build-dep nginxapt-get install --reinstall <package> — Reinstall a package.
sudo apt-get install --reinstall openssh-serverCache & Cleanup
apt-get clean — Delete all cached .deb packages from /var/cache/apt/archives.
sudo apt-get cleanapt-get autoclean — Delete obsolete cached packages.
sudo apt-get autocleanapt-get check — Verify that there are no broken dependencies.
apt-get checkScripting Options
apt-get install -y <package> — Auto-confirm (assume yes to all prompts).
sudo apt-get install -y curl wgetapt-get install -q <package> — Quiet mode (less output, good for scripts).
sudo apt-get install -qq -y nginxapt-get install --dry-run <package> — Simulate install without making changes.
apt-get install --dry-run docker-ceDEBIAN_FRONTEND=noninteractive apt-get install -y <package> — Fully non-interactive install (for Docker/CI).
DEBIAN_FRONTEND=noninteractive sudo apt-get install -y tzdata Conclusion
apt-get is the reliable choice wherever machines rather than humans manage the packages: in scripts, Dockerfiles and CI pipelines you get stable, predictable output and an option set that has stayed constant for years. For interactive use at the terminal, the more modern apt is often more convenient – but for automation, apt-get remains the first choice. Be careful with remove, purge and autoremove: they delete packages, and purge additionally removes the configuration files. dist-upgrade can remove packages too in order to resolve dependencies – use --dry-run first to see what would actually happen. Writing commands need root privileges (sudo); read-only commands like check or download do not.
Further Reading
- APT – Debian Wiki – overview of the APT tools and how to use them
- apt-get(8) – manual page – complete reference of all options