# apt-get — The Classic Debian/Ubuntu Package Tool

> Practical guide to apt-get — the stable, low-level APT tool for Debian and Ubuntu: ideal for scripts, CI and Docker thanks to its predictable output.

Source: https://www.jpkc.com/db/en/cheatsheets/package-managers/apt-get/

<!-- PROSE:intro -->
`apt-get` is the classic, script-stable low-level tool of the APT package management system on Debian and Ubuntu. While the newer `apt` is optimised for a polished, interactive terminal experience, `apt-get` keeps a stable output format and a fixed set of options across versions – which is exactly why you should prefer it over interactive `apt` in scripts, CI pipelines and Dockerfiles. This guide walks you through the commands you reach for daily: from updating the package index and installing or removing packages to the options for fully automated, non-interactive runs.
<!-- PROSE:intro:end -->

## Update & Upgrade

`apt-get update` — Update the package index.

```bash
sudo apt-get update
```

`apt-get upgrade` — Upgrade all packages (never removes packages).

```bash
sudo apt-get upgrade -y
```

`apt-get dist-upgrade` — Smart upgrade: may add/remove packages to satisfy dependencies.

```bash
sudo apt-get dist-upgrade
```

## Install & Remove

`apt-get install <package>` — Install a package.

```bash
sudo apt-get install -y nginx
```

`apt-get install --no-install-recommends <package>` — Install without recommended packages (smaller footprint).

```bash
sudo apt-get install --no-install-recommends php8.3
```

`apt-get install -f` — Fix broken dependencies.

```bash
sudo apt-get install -f
```

`apt-get remove <package>` — Remove a package (keep config).

```bash
sudo apt-get remove nginx
```

`apt-get purge <package>` — Remove a package and its config files.

```bash
sudo apt-get purge nginx
```

`apt-get autoremove` — Remove unused dependencies.

```bash
sudo apt-get autoremove -y
```

## Download & Source

`apt-get download <package>` — Download a .deb package without installing.

```bash
apt-get download nginx
```

`apt-get source <package>` — Download the source package.

```bash
apt-get source nginx
```

`apt-get build-dep <package>` — Install build dependencies for a source package.

```bash
sudo apt-get build-dep nginx
```

`apt-get install --reinstall <package>` — Reinstall a package.

```bash
sudo apt-get install --reinstall openssh-server
```

## Cache & Cleanup

`apt-get clean` — Delete all cached .deb packages from /var/cache/apt/archives.

```bash
sudo apt-get clean
```

`apt-get autoclean` — Delete obsolete cached packages.

```bash
sudo apt-get autoclean
```

`apt-get check` — Verify that there are no broken dependencies.

```bash
apt-get check
```

## Scripting Options

`apt-get install -y <package>` — Auto-confirm (assume yes to all prompts).

```bash
sudo apt-get install -y curl wget
```

`apt-get install -q <package>` — Quiet mode (less output, good for scripts).

```bash
sudo apt-get install -qq -y nginx
```

`apt-get install --dry-run <package>` — Simulate install without making changes.

```bash
apt-get install --dry-run docker-ce
```

`DEBIAN_FRONTEND=noninteractive apt-get install -y <package>` — Fully non-interactive install (for Docker/CI).

```bash
DEBIAN_FRONTEND=noninteractive sudo apt-get install -y tzdata
```

<!-- PROSE:outro -->
## Conclusion

`apt-get` is the reliable choice wherever machines rather than humans manage the packages: in scripts, Dockerfiles and CI pipelines you get stable, predictable output and an option set that has stayed constant for years. For interactive use at the terminal, the more modern `apt` is often more convenient – but for automation, `apt-get` remains the first choice. Be careful with `remove`, `purge` and `autoremove`: they delete packages, and `purge` additionally removes the configuration files. `dist-upgrade` can remove packages too in order to resolve dependencies – use `--dry-run` first to see what would actually happen. Writing commands need root privileges (`sudo`); read-only commands like `check` or `download` do not.

## Further Reading

- [APT – Debian Wiki](https://wiki.debian.org/Apt) – overview of the APT tools and how to use them
- [apt-get(8) – manual page](https://manpages.debian.org/stable/apt/apt-get.8.en.html) – complete reference of all options
<!-- PROSE:outro:end -->

## Related Commands

- [apk](https://www.jpkc.com/db/en/cheatsheets/package-managers/apk/) – Alpine Linux package manager, lightweight for containers
- [apt](https://www.jpkc.com/db/en/cheatsheets/package-managers/apt/) – the modern, interactive APT front-end for the terminal
- [brew](https://www.jpkc.com/db/en/cheatsheets/package-managers/brew/) – Homebrew, the package manager for macOS and Linux

