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.
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
Command
What 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.
apt
Script equivalent
History and Logs
Command
What 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
Error
Fix
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
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.