# apt — Manage Packages on Debian and Ubuntu

> Practical guide to apt — install, update, upgrade and remove packages on Debian and Ubuntu with the user-friendly high-level package-management frontend.

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

<!-- PROSE:intro -->
apt is the user-friendly, high-level frontend for package management on Debian and Ubuntu – it folds the most-used parts of `apt-get` and `apt-cache` into one tidy, readable command. Instead of remembering several tools, you install, update, search and remove packages with a single command, complete with automatic dependency resolution and a coloured progress bar. This guide walks you through the commands you actually reach for daily, from refreshing the package index to cleaning up orphaned dependencies.
<!-- PROSE:intro:end -->

## Update & Upgrade

`apt update` — Update the package index (fetch latest package lists).

```bash
sudo apt update
```

`apt upgrade` — Upgrade all installed packages to their latest versions.

```bash
sudo apt upgrade
```

`apt full-upgrade` — Upgrade packages, adding/removing dependencies as needed.

```bash
sudo apt full-upgrade
```

`apt update && apt upgrade -y` — Update index and upgrade all packages (non-interactive).

```bash
sudo apt update && sudo apt upgrade -y
```

## Install & Remove

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

```bash
sudo apt install nginx
```

`apt install <pkg1> <pkg2>` — Install multiple packages.

```bash
sudo apt install curl wget git
```

`apt install <package>=<version>` — Install a specific version.

```bash
sudo apt install nginx=1.24.0-1
```

`apt install -y <package>` — Install without confirmation prompt.

```bash
sudo apt install -y docker-ce
```

`apt reinstall <package>` — Reinstall a package.

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

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

```bash
sudo apt remove nginx
```

`apt purge <package>` — Remove a package including config files.

```bash
sudo apt purge nginx
```

`apt autoremove` — Remove unused dependencies (orphan packages).

```bash
sudo apt autoremove
```

## Search & Info

`apt search <query>` — Search for packages by name or description.

```bash
apt search nodejs
```

`apt show <package>` — Show detailed info about a package.

```bash
apt show nginx
```

`apt list --installed` — List all installed packages.

```bash
apt list --installed
```

`apt list --upgradable` — List packages with available upgrades.

```bash
apt list --upgradable
```

`apt depends <package>` — Show dependencies of a package.

```bash
apt depends nginx
```

`apt rdepends <package>` — Show packages that depend on a package (reverse deps).

```bash
apt rdepends libssl3
```

## Hold & Pin

`apt-mark hold <package>` — Hold a package at its current version (prevent upgrades).

```bash
sudo apt-mark hold linux-image-generic
```

`apt-mark unhold <package>` — Remove a hold (allow upgrades again).

```bash
sudo apt-mark unhold linux-image-generic
```

`apt-mark showhold` — List all held packages.

```bash
apt-mark showhold
```

`apt-mark auto <package>` — Mark a package as automatically installed (dependency).

```bash
sudo apt-mark auto libfoo
```

`apt-mark manual <package>` — Mark a package as manually installed.

```bash
sudo apt-mark manual nginx
```

## Cleanup & Cache

`apt clean` — Delete all cached .deb packages.

```bash
sudo apt clean
```

`apt autoclean` — Delete cached .deb packages that can no longer be downloaded.

```bash
sudo apt autoclean
```

`apt autoremove --purge` — Remove unused dependencies and their config files.

```bash
sudo apt autoremove --purge
```

## Repositories

`add-apt-repository <ppa>` — Add a PPA repository.

```bash
sudo add-apt-repository ppa:ondrej/php
```

`add-apt-repository --remove <ppa>` — Remove a PPA repository.

```bash
sudo add-apt-repository --remove ppa:ondrej/php
```

`apt edit-sources` — Edit the sources.list file.

```bash
sudo apt edit-sources
```

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

apt takes much of the friction out of package management on Debian and Ubuntu: one command, a consistent syntax and automatic dependency resolution – for everyday work you rarely need more than `update`, `upgrade`, `install` and `search`. Keep in mind, though, that write operations require `sudo` and touch your system: `remove`, `purge` and especially `autoremove` delete packages and sometimes configuration files too, and `autoremove` occasionally takes more than you expect – review the preview before you confirm. `full-upgrade` can also remove packages to resolve conflicts. Only add repositories and keys you trust (`sources.list`, PPAs), since they may install arbitrary software on your machine.

## Further Reading

- [Debian Wiki: Apt](https://wiki.debian.org/Apt) – introduction to package management with apt
- [Ubuntu Server docs: Package management](https://documentation.ubuntu.com/server/how-to/software/package-management/) – official Ubuntu guide to installing and managing software
<!-- PROSE:outro:end -->

## Related Commands

- [apk](https://www.jpkc.com/db/en/cheatsheets/package-managers/apk/) – Alpine Linux package manager
- [apt-get](https://www.jpkc.com/db/en/cheatsheets/package-managers/apt-get/) – the classic low-level package-management frontend
- [brew](https://www.jpkc.com/db/en/cheatsheets/package-managers/brew/) – the Homebrew package manager for macOS and Linux

