Skip to content
Latchkey

apt-get install -y --no-install-recommends in CI

apt-get install -y --no-install-recommends installs packages unattended without pulling in optional extras.

This is the workhorse install line for Debian and Ubuntu CI images. The flags below keep it non-interactive and the image small.

What it does

apt-get install resolves and installs the named packages plus their dependencies. -y answers prompts automatically and --no-install-recommends skips packages marked Recommends, which are optional and often large.

Common usage

Terminal
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y --no-install-recommends \
  git curl ca-certificates
# pin an exact version
apt-get install -y --no-install-recommends nginx=1.24.0-1ubuntu1

Options

FlagWhat it does
-y / --yesAssume yes; never prompt
--no-install-recommendsDo not install Recommends packages
pkg=versionInstall an exact version
--allow-downgradesPermit installing an older version than present
--reinstallReinstall a package that is already present
-o Dpkg::Options::="--force-confold"Keep existing config files on upgrade

In CI

Set DEBIAN_FRONTEND=noninteractive so no package (tzdata, dialog) stops for a prompt. Pin versions for reproducible builds, add --no-install-recommends to shrink images, and always apt-get update first in the same layer.

Common errors in CI

"E: Unable to locate package <X>" means the index is stale or the repo providing X is not enabled; run apt-get update or add the repo. "E: Could not get lock /var/lib/dpkg/lock-frontend ... resource temporarily unavailable" means another apt process holds the lock (unattended-upgrades on hosted runners); wait or disable it. "E: Version '<v>' for '<pkg>' was not found" means the pinned version is no longer in the index.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →