Home·Terminal commands

apt-get install

Packages and runtimes

Usage

sudo apt-get install [-y] <package>...

Installs from the package list already on disk, so a stale list gives "Unable to locate package" until apt-get update runs; apt-get keeps a stable interface for scripts, while apt is the one meant for humans.

Common flags

FlagMeaning
-yanswer yes, needed in scripts and Dockerfiles
--no-install-recommendsskip recommended extras, keeping images small
-ssimulate; print the plan and change nothing
--only-upgradeupgrade it if present, do not install it new
--reinstallinstall the same version over itself
-ftry to fix broken dependencies

Examples

sudo apt-get install -y curl git

the usual line in a Dockerfile

sudo apt-get install --no-install-recommends nginx

nginx without the suggested extras

sudo apt-get install -s ffmpeg

shows what would be pulled in

The question is always what goes where: inside this project, or on the whole machine.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does apt-get install do?

Installs from the package list already on disk, so a stale list gives "Unable to locate package" until apt-get update runs; apt-get keeps a stable interface for scripts, while apt is the one meant for humans.

Q. How do I type it?

sudo apt-get install [-y] <package>... — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

6 are listed here; the full set is in man apt-get. This command sits under Packages and runtimes.

Related commands

man page: man apt-get-install