๐ŸŽ New User? Get 20% off your first purchase with code NEWUSER20 ยท โšก Instant download ยท ๐Ÿ”’ Secure checkout Register Now โ†’
Menu

Categories

apt-get Command

Beginner Package Management man(1)

Low-level package handling for Debian systems

๐Ÿ‘ 126 views ๐Ÿ“… Updated: Apr 29, 2026
SYNTAX
apt-get [OPTION]... COMMAND [PACKAGE]...

What Does apt-get Do?

apt-get is the traditional Debian/Ubuntu package management command. It handles package installation, removal, upgrading, and dependency resolution. While apt is now preferred for interactive use, apt-get remains the standard for scripts.

apt-get has stable, parseable output that does not change between releases, making it reliable in automated scripts, CI/CD pipelines, and Dockerfiles. Its behavior is well-documented and predictable.

apt-get preceded the apt command and provides the same core functionality with a more scriptable interface.

Options & Flags

OptionDescriptionExample
update Update package lists sudo apt-get update
upgrade Upgrade packages sudo apt-get upgrade -y
dist-upgrade Smart upgrade (handles dependencies) sudo apt-get dist-upgrade -y
install Install packages sudo apt-get install -y nginx
remove Remove packages sudo apt-get remove nginx
purge Remove with config files sudo apt-get purge nginx
autoremove Remove unused dependencies sudo apt-get autoremove -y
--no-install-recommends Skip recommended packages sudo apt-get install --no-install-recommends nginx

Practical Examples

#1 Install in Docker

Standard Dockerfile pattern: update, install, cleanup.
$ RUN apt-get update && apt-get install -y --no-install-recommends curl wget && rm -rf /var/lib/apt/lists/*

#2 Non-interactive install

Installs without interactive prompts (for scripts).
$ DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata

#3 Install specific version

Installs a specific version of a package.
$ sudo apt-get install nginx=1.24.0-1

#4 Download only

Downloads packages without installing.
$ sudo apt-get install -d nginx

#5 Fix broken dependencies

Attempts to fix broken package dependencies.
$ sudo apt-get install -f

Tips & Best Practices

Use in scripts, apt for terminal: apt-get has stable output for scripts and automation. apt has nicer output for interactive use.
Dockerfile pattern: Always combine update and install in one RUN command in Dockerfiles, and clean up /var/lib/apt/lists/* to reduce image size.
-y flag in scripts: Always use -y in scripts to auto-confirm. Without it, apt-get waits for input that never comes.

Frequently Asked Questions

When should I use apt-get vs apt?
Use apt interactively (nicer output). Use apt-get in scripts, Dockerfiles, and automation (stable output format).
How do I fix broken packages?
sudo apt-get install -f attempts to fix broken dependencies. sudo dpkg --configure -a fixes interrupted installations.
How do I install without recommended packages?
sudo apt-get install --no-install-recommends package. Reduces installed dependencies โ€” useful in Docker/minimal systems.

Download Package Management Cheat Sheet

PDF Package Management
View all 31 Linux command cheat sheets โ†’

Master Linux with Professional eBooks

Curated IT eBooks covering Linux, DevOps, Cloud, and more

Browse Books โ†’