apt & dpkg (Debian/Ubuntu) Cheat Sheet
apt installs packages from repositories and handles dependencies. dpkg works with individual .deb files. Most commands need sudo.
On this page
Everyday #
| Command | Action |
|---|---|
| Refresh the package lists (always do this first) | |
| Upgrade installed packages | |
| Upgrade and allow adding / removing dependencies | |
| Install | |
| Install several packages without the confirmation prompt | |
| Install a local .deb with its dependencies | |
| Remove (keeps config files) | |
| Remove including config files | |
| Remove dependencies that are no longer needed | |
| Reinstall |
Search & Info #
| Command | Action |
|---|---|
| Search packages | |
| Package details (version, size, dependencies) | |
| All installed packages | |
| Packages with updates available | |
| Installed vs available version and which repo it comes from | |
| Dependencies | |
| What depends on this package |
dpkg (low level) #
| Command | Action |
|---|---|
| Install a .deb (does not fetch dependencies) | |
| Remove | |
| List installed packages | |
| Check whether something is installed | |
| Files installed by a package | |
| Which package owns this file | |
| Finish interrupted installs |
Fixing Problems #
| Command | Action |
|---|---|
| Fix missing or broken dependencies | |
| Resume after a crash or interrupted install | |
| Delete all downloaded .deb files | |
| Delete only outdated .deb files | |
| Freeze a package at its current version | |
| Unfreeze | |
| Packages you installed yourself |
Repositories #
| Path / command | Use |
|---|---|
/etc/apt/sources.list | Main repository list (older format) |
/etc/apt/sources.list.d/*.sources | Extra repos (deb822 format, Debian 12+ / Ubuntu 24.04+) |
/etc/apt/keyrings/ | Place for repository signing keys |
| Add a PPA (Ubuntu only) | |
| Upgrade to the next Ubuntu release |
Other Package Formats #
| Command | Action |
|---|---|
| Install a Snap (Ubuntu) | |
| / | List / update snaps |
| Install a Flatpak | |
| Update Flatpaks |
Tips #
- A quick full update:
sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y. - "Could not get lock"? Another update is still running. Wait for it instead of deleting lock files.
- Automatic security updates:
sudo apt install unattended-upgrades.
aptalso: apt-getInstall and update software on Debian, Ubuntu, Mint and Raspberry Pi OS. sudo apt [options] command [packages]
| Command / option | What it does |
|---|---|
update | Refresh the package lists (do this first) |
upgrade | Upgrade installed packages |
full-upgrade | Upgrade, allowing packages to be added or removed |
install pkg… | Install (./file.deb installs a local file with dependencies) |
reinstall pkg | Reinstall |
remove pkg | Remove, keep config files |
purge pkg | Remove including config files |
autoremove | Remove dependencies that are no longer needed |
search word | Search packages |
show pkg | Package details |
list --installed / --upgradable | Installed / upgradable packages |
edit-sources | Edit the repository list |
-y | Answer "yes" to every question |
--no-install-recommends | Skip recommended extras (smaller installs) |
-s, --simulate | Show what would happen, change nothing |
--fix-broken | Repair broken dependencies (apt --fix-broken install) |
--only-upgrade pkg | Upgrade one package, don't install new ones |
-t bookworm-backports | Install from a specific release / repo |
-q | Less output |
apt-cacheQuery the package database (read-only). apt-cache command pkg
| Command | What it does |
|---|---|
policy pkg | Installed version, candidate version and repo priority |
madison pkg | Every available version, one per line |
depends pkg | What it needs |
rdepends pkg | What needs it |
show pkg | Full details |
search word | Search names and descriptions |
showpkg pkg | Low-level dependency info |
pkgnames prefix | Package names starting with a prefix |
dpkgLow-level .deb package tool. dpkg [options] …
| Option | What it does |
|---|---|
-i file.deb | Install a .deb (does not fetch dependencies) |
-r pkg | Remove (keep config) |
-P pkg | Purge (remove including config) |
-l [pattern] | List installed packages (ii = installed) |
-L pkg | Files installed by a package |
-S /path/file | Which package owns this file |
-s pkg | Status and details of an installed package |
-c file.deb | Files inside a .deb |
-I file.deb | Info about a .deb |
-x file.deb folder | Extract a .deb without installing |
--configure -a | Finish interrupted installations |
--get-selections | Every package and its state |
--add-architecture i386 | Allow packages of another architecture |
apt-markMark packages: hold back, manual, auto. sudo apt-mark command pkg
| Command | What it does |
|---|---|
hold pkg | Keep at the current version (no upgrades) |
unhold pkg | Allow upgrades again |
showhold | List held packages |
showmanual | Packages you installed yourself |
showauto | Packages installed as dependencies |
manual pkg / auto pkg | Change how a package is marked |
add-apt-repositoryAdd or remove software sources, including PPAs (Ubuntu). sudo add-apt-repository [options] repo
| Usage / option | What it does |
|---|---|
ppa:user/name | Add a Launchpad PPA |
universe / multiverse | Enable an Ubuntu component |
-r | Remove the repository |
-y | Don't ask for confirmation |
-n | Don't run apt update afterwards |
-L | List the configured repositories (newer versions) |
do-release-upgradeUpgrade Ubuntu to the next release. sudo do-release-upgrade [options]
| Option | What it does |
|---|---|
| (none) | Upgrade to the next supported release (LTS → next LTS on LTS systems) |
-c | Only check whether a new release is available |
-d | Upgrade to the development release (testing only) |
-f DistUpgradeViewNonInteractive | Non-interactive upgrade (servers, scripts) |
Back up first and run it inside tmux when upgrading over SSH.
snapInstall sandboxed Snap packages (Ubuntu). sudo snap command [options]
| Command / option | What it does |
|---|---|
install name | Install |
install name --classic | Install with full system access (editors, dev tools) |
install name --channel=beta | Other channel: stable, candidate, beta, edge |
remove name | Remove (--purge = no snapshot) |
list | Installed snaps |
refresh / refresh name | Update all / one |
revert name | Back to the previous version |
find word | Search the store |
info name | Details and channels |
disable / enable name | Turn off / on without removing |
logs name / services | Logs / background services |
connections name | Permissions (interfaces) of a snap |
flatpakInstall sandboxed apps on any distro. flatpak command [options]
| Command / option | What it does |
|---|---|
remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo | Add the Flathub store |
install flathub app.id | Install an app |
run app.id | Start an app |
update | Update everything |
list --app | Installed apps |
search word | Search |
info app.id | Details |
uninstall app.id | Remove (--delete-data removes its data too) |
uninstall --unused | Remove runtimes nothing uses any more |
override --filesystem=home app.id | Give an app extra permissions |
--user / --system | Install for you only / for everyone |
Nothing on this sheet matches “”.