Skip to content
Latchkey

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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →