apt-get Command Reference: Flags, Usage & CI Examples
apt-get is the scriptable package manager for Debian and Ubuntu.
apt-get installs, upgrades, and removes packages from APT repositories. It is the stable, script-friendly front end (over the interactive apt) used in Dockerfiles and CI images.
Common flags and usage
- update: refresh the package index (run before install)
- install <pkg...>: install packages
- -y / --yes: assume yes to prompts
- --no-install-recommends: skip recommended extras
- remove / purge / autoremove: delete packages and config
- DEBIAN_FRONTEND=noninteractive: suppress configure prompts
Example
shell
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y --no-install-recommends ca-certificates curl postgresql-client
rm -rf /var/lib/apt/lists/*In CI
Always run apt-get update first, then install with -y and DEBIAN_FRONTEND=noninteractive so no prompt hangs the job. Add --no-install-recommends and clean /var/lib/apt/lists to keep image layers small.
Key takeaways
- Run apt-get update before install so the index is current.
- -y plus DEBIAN_FRONTEND=noninteractive prevents prompts in CI.
- --no-install-recommends and cleaning lists shrink images.
Related guides
dpkg Command Reference: Flags, Usage & CI ExamplesReference for dpkg: -i, -r, -l, -L, -S, --configure, and a CI example that installs a local .deb and fixes de…
apt-key Command Reference: Usage, Deprecation & CI ExamplesReference for apt-key: add, adv, the modern signed-by keyring replacement, and a CI example that installs a r…
yum Command Reference: Flags, Usage & CI ExamplesReference for yum: install, -y, remove, makecache, clean all, and a CI example that installs packages noninte…