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 update

apt-get upgrade — Upgrade all packages (never removes packages).

sudo apt-get upgrade -y

apt-get dist-upgrade — Smart upgrade: may add/remove packages to satisfy dependencies.

sudo apt-get dist-upgrade

Install & Remove

apt-get install <package> — Install a package.

sudo apt-get install -y nginx

apt-get install --no-install-recommends <package> — Install without recommended packages (smaller footprint).

sudo apt-get install --no-install-recommends php8.3

apt-get install -f — Fix broken dependencies.

sudo apt-get install -f

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

sudo apt-get remove nginx

apt-get purge <package> — Remove a package and its config files.

sudo apt-get purge nginx

apt-get autoremove — Remove unused dependencies.

sudo apt-get autoremove -y

Download & Source

apt-get download <package> — Download a .deb package without installing.

apt-get download nginx

apt-get source <package> — Download the source package.

apt-get source nginx

apt-get build-dep <package> — Install build dependencies for a source package.

sudo apt-get build-dep nginx

apt-get install --reinstall <package> — Reinstall a package.

sudo apt-get install --reinstall openssh-server

Cache & Cleanup

apt-get clean — Delete all cached .deb packages from /var/cache/apt/archives.

sudo apt-get clean

apt-get autoclean — Delete obsolete cached packages.

sudo apt-get autoclean

apt-get check — Verify that there are no broken dependencies.

apt-get check

Scripting Options

apt-get install -y <package> — Auto-confirm (assume yes to all prompts).

sudo apt-get install -y curl wget

apt-get install -q <package> — Quiet mode (less output, good for scripts).

sudo apt-get install -qq -y nginx

apt-get install --dry-run <package> — Simulate install without making changes.

apt-get install --dry-run docker-ce

DEBIAN_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

  • apk – Alpine Linux package manager, lightweight for containers
  • apt – the modern, interactive APT front-end for the terminal
  • brew – Homebrew, the package manager for macOS and Linux