📦
apt cheat sheet
apt is the package manager for Debian, Ubuntu and derivatives. Most commands need sudo. Run apt update before installing so the package lists are current.
Click any command to copy it.
Update and upgrade
| Command | What it does |
|---|---|
sudo apt update | Refresh the package lists. |
sudo apt upgrade | Upgrade installed packages without removing any. |
sudo apt full-upgrade | Upgrade and allow removing or installing packages as needed. |
apt list --upgradable | Show which packages can be upgraded. |
ls /var/run/reboot-required | Exists if a reboot is needed after updates. |
sudo apt --fix-broken install | Repair broken dependencies. |
Install and remove
| Command | What it does |
|---|---|
sudo apt install package | Install a package. |
sudo apt install -y package | Install without the confirmation prompt. |
sudo apt install package=1.2.3-1 | Install a specific version. |
sudo apt remove package | Remove a package but keep its configuration. |
sudo apt purge package | Destructive: Remove a package and its configuration files. |
sudo apt autoremove | Remove packages that were installed as dependencies and are no longer needed. |
sudo apt install ./file.deb | Install a local .deb file and resolve dependencies. |
Search and inspect
| Command | What it does |
|---|---|
apt search keyword | Search package names and descriptions. |
apt show package | Show details of a package. |
apt list --installed | List installed packages. |
apt policy package | Show installed and available versions and their sources. |
dpkg -l | grep package | Check whether a package is installed. |
dpkg -L package | List the files a package installed. |
dpkg -S /path/to/file | Find which package owns a file. |
Hold, repositories and cleanup
| Command | What it does |
|---|---|
sudo apt-mark hold package | Prevent a package from being upgraded. |
sudo apt-mark unhold package | Allow upgrades again. |
apt-mark showhold | List held packages. |
sudo add-apt-repository ppa:user/ppa | Add a PPA (Ubuntu). |
sudo apt clean | Delete downloaded package files from the cache. |
sudo apt install unattended-upgrades | Install automatic security updates. |
Frequently asked questions
What is the difference between apt update and apt upgrade?
update downloads the latest package lists; upgrade installs newer versions of the packages you already have. Run update first.
What is the difference between apt and apt-get?
apt is the newer, friendlier interface for interactive use. apt-get is the older tool, still preferred in scripts because its output is stable.