Safeguard
Developer Tools•

Should scripts and CI use apt or apt-get?

Use apt-get and apt-cache in scripts and CI. The apt manual says apt may change behaviour between versions, so apt suits terminals, not pipelines.

Safeguard Security Team
4 min read

Use apt-get and apt-cache in scripts, Dockerfiles and CI. The apt manual notes that the apt command may change behaviour between versions and recommends apt-get and apt-cache for scripts because they try harder to stay backward compatible. Keep plain apt for interactive use.

Why it matters for security work

Patch automation is code. If a script that applies security updates silently changes behaviour after an operating system upgrade, you may stop patching without noticing. Pipeline stability is a security property here.

What the manual says

The apt manual describes apt as a command line tool for people, with commands such as update, upgrade, full-upgrade and list. It states that the tool may change behavior between versions, and that for scripts you should use apt-get and apt-cache.

In practice, you will see the difference in output formatting. Plain apt prints a progress bar and a warning when its output is piped, which is a hint that it does not promise a stable machine readable format.

Quick mapping

TaskInteractiveScript or CI
Refresh package listsapt updateapt-get update
Install updatesapt upgradeapt-get upgrade
Install updates, allowing removalsapt full-upgradeapt-get dist-upgrade
Install a packageapt installapt-get install
Show candidate versionsapt policyapt-cache policy
List what can be upgradedapt list with the upgradable optionapt-get with the simulate option

The upgrade versus full-upgrade difference is explained in apt upgrade versus full-upgrade.

Make scripts safe to run unattended

Package prompts can hang a pipeline. Set the environment for non interactive runs, pass the assume yes flag, and keep the update and install steps together. Docker's build guidance recommends exactly that combination in a Dockerfile, because a separate cached update step can leave stale lists. See how to run apt-get in a Dockerfile.

export DEBIAN_FRONTEND=noninteractive
apt-get update && apt-get install -y --no-install-recommends package-name

Check what your pipeline would do

Before putting an upgrade step on a schedule, simulate it and read the output:

apt-get -s upgrade

The Debian unattended upgrade tool has a dry run option for the same reason, covered in how to preview security updates before you install them.

Build checks around it

  1. Fail the pipeline if the upgrade step exits non zero.
  2. Log which packages changed.
  3. Scan the result, since a successful upgrade does not prove the image is clean.
  4. Pin the runner or base image version so tool behaviour changes only when you decide.

A short script review checklist

When you review a patching script or pipeline step, ask five questions.

  1. Does it use apt-get and apt-cache rather than plain apt?
  2. Does it run non interactively, so a prompt cannot hang the job?
  3. Does it fail loudly if the upgrade returns an error?
  4. Does it record what changed, so you can show it later?
  5. Does it end with a scan or a restart check, so you know the fix is in effect?

A script that passes all five is easy to defend in an audit and easy to debug at night. One that fails any of them tends to fail quietly.

Quick check

Is apt deprecated?

No. The manual describes it as a tool for interactive use, and says to prefer apt-get and apt-cache in scripts.

Why does this matter for security?

If scripted patching changes behaviour silently, updates can stop applying without an alert.

Safeguard watches for advisories against the packages your builds produce, so a quietly failing update step shows up as an open finding. Try the free scan at gold.safeguard.sh/scan.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.