Cheat Sheet

apt Commands

apt is the package manager on Debian, Ubuntu, and their derivatives, including Raspberry Pi OS and Mint. This apt commands cheat sheet covers updating, installing, and removing packages, repositories and keys, held packages, and the errors apt update likes to throw.

Last updated September 5, 2026

Update and Upgrade

refreshes the package lists and installs nothing; installs the new versions. Run them in that order.

CommandWhat it does
Refresh the package lists from every repository
Upgrade everything that can be upgraded without removing packages
Upgrade and allow removals when the upgrade needs them
Old name for full-upgrade, same behaviour
The usual pair in one line
See what an upgrade would touch, after an update
Upgrade a single package and nothing else
Dry run: print the plan without doing any of it

Install and Remove

CommandWhat it does
Install a package and its dependencies
Install a specific version ( shows them)
Install a local .deb with dependency resolution
Reinstall the current version
Assume yes to the confirmation prompt (scripts)
Remove the package, keep its config files
Remove the package and its config files
Remove dependencies nothing needs any more
Same, and drop their config files too

Search and Show

CommandWhat it does
Search package names and descriptions
Search names only, less noise
Description, version, dependencies, download size
Installed version, candidate version, and which repo offers what
Every available version
Which installed package owns a file
Which package, installed or not, ships a file ( first, then )

List Installed Packages

CommandWhat it does
Every installed package
Check whether a package is installed
Status and version of one package; non-zero exit if absent
The classic full listing with status flags
Files a package installed
Packages you installed on purpose, not as dependencies

Hold Packages

A held package keeps its current version through every upgrade until you release it.

CommandWhat it does
Pin the installed version
Release it
List held packages

Repositories and Keys

Current releases (Debian 12+, Ubuntu 24.04+) use deb822 files under instead of one-line entries:

# /etc/apt/sources.list.d/example.sources
Types: deb
URIs: https://packages.example.com/apt
Suites: stable
Components: main
Signed-By: /etc/apt/keyrings/example.gpg

is deprecated and gone from the newest releases. Keys go into and are referenced by :

curl -fsSL https://packages.example.com/key.asc | sudo gpg --dearmor -o /etc/apt/keyrings/example.gpg
CommandWhat it does
Add a PPA on Ubuntu; it installs the key and source for you
Remove it again
Edit sources.list with a syntax check on save
Quick look at where your packages come from

Clean Up and Fix Broken

CommandWhat it does
Repair a broken or interrupted install ( for short)
Finish configuring packages after an interrupted run
Delete every downloaded .deb from the cache
Delete only cached .debs that repos no longer offer

apt vs apt-get

apt is the human-facing command: it merges the most used parts of apt-get and apt-cache and adds a progress bar. Its output can change between releases, so scripts should stick to apt-get and apt-cache, whose interfaces are stable.

aptScript equivalent

History and Logs

CommandWhat it does
What was installed, upgraded, or removed, and when
Search the rotated history too
Full terminal output of past apt runs
dpkg's own log, one line per package action

Common apt update Errors

ErrorFix
Another apt is running, usually unattended-upgrades; wait, or find it with
The repo's signing key is missing: fetch it into and reference it with
The release left the mirror: fix the entry under , or point EOL Ubuntu at old-releases.ubuntu.com
Stale mirror or broken cache: , or switch mirrors
Usually a wrong system clock or an intercepting proxy: check first
A release moved from testing to stable:

apt, dnf and pacman

The same tasks on RHEL and Fedora are in the DNF cheat sheet, and on Arch in the pacman cheat sheet.

Taskaptdnfpacman
Refresh and upgrade
Install
Remove with dependencies
Search
Who owns a file
List installed
Clean cache

Tips

  • Security patches can install themselves: , then . It is also the usual holder of the dpkg lock right after boot.
  • In scripts and Dockerfiles, use with so a config prompt cannot hang the run.
  • Behind a proxy, create containing .
  • never removes packages, which means it can also silently hold some back; when it reports packages "kept back", will resolve them.
  • Removing a package does not stop its service first in every case; check with (see the systemctl cheat sheet).

apt Cheat Sheet FAQ

What is the difference between apt update and apt upgrade?
apt update downloads the latest package lists from your repositories and installs nothing. apt upgrade reads those lists and installs the newer versions. The order matters: an upgrade run on stale lists installs stale versions. apt full-upgrade goes one step further and will remove packages when an upgrade requires it, which is what kernel and release upgrades sometimes need.
How do I upgrade just one package with apt?
Run sudo apt update, then sudo apt install --only-upgrade <package>. Plain apt install <package> also upgrades an installed package, but would install it if it were missing; --only-upgrade refuses to touch packages that are not already there. To see which version you would get, check apt-cache policy <package> first.
Should I use apt or apt-get?
At the keyboard, apt: it merges the useful parts of apt-get and apt-cache and adds progress output. In scripts, apt-get and apt-cache: their options and output are kept stable across releases, and apt itself warns that its CLI is not. The packages you end up with are identical either way.
How do I fix 'Could not get lock /var/lib/dpkg/lock-frontend'?
Another package manager is running, often unattended-upgrades a few minutes after boot, or a stuck Software Updater window. Find it with ps aux | grep -i apt and let it finish; the lock releases itself. Only if no apt or dpkg process exists should you delete the lock files, and then run sudo dpkg --configure -a to finish whatever was interrupted.
How do I see what apt installed or removed recently?
apt logs every run in /var/log/apt/history.log as a dated block that includes the exact command line. Older runs rotate into history.log.1 and gzipped files you can search with zgrep. /var/log/dpkg.log records every individual package action, which also catches installs made with dpkg directly.

Related cheat sheets