Tools › Cheat sheets › System Administration › apt
📦

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

CommandWhat it does
sudo apt updateRefresh the package lists.
sudo apt upgradeUpgrade installed packages without removing any.
sudo apt full-upgradeUpgrade and allow removing or installing packages as needed.
apt list --upgradableShow which packages can be upgraded.
ls /var/run/reboot-requiredExists if a reboot is needed after updates.
sudo apt --fix-broken installRepair broken dependencies.

Install and remove

CommandWhat it does
sudo apt install packageInstall a package.
sudo apt install -y packageInstall without the confirmation prompt.
sudo apt install package=1.2.3-1Install a specific version.
sudo apt remove packageRemove a package but keep its configuration.
sudo apt purge packageDestructive: Remove a package and its configuration files.
sudo apt autoremoveRemove packages that were installed as dependencies and are no longer needed.
sudo apt install ./file.debInstall a local .deb file and resolve dependencies.

Search and inspect

CommandWhat it does
apt search keywordSearch package names and descriptions.
apt show packageShow details of a package.
apt list --installedList installed packages.
apt policy packageShow installed and available versions and their sources.
dpkg -l | grep packageCheck whether a package is installed.
dpkg -L packageList the files a package installed.
dpkg -S /path/to/fileFind which package owns a file.

Hold, repositories and cleanup

CommandWhat it does
sudo apt-mark hold packagePrevent a package from being upgraded.
sudo apt-mark unhold packageAllow upgrades again.
apt-mark showholdList held packages.
sudo add-apt-repository ppa:user/ppaAdd a PPA (Ubuntu).
sudo apt cleanDelete downloaded package files from the cache.
sudo apt install unattended-upgradesInstall 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.

More System Administration cheat sheets

⚙️ systemctl📜 journalctl🎩 dnf / yum👥 Users & groups📊 Processes & performance💽 Disks & storage🔄 rsync⏱️ Cron expressionsAll System Administration cheat sheets →
Copied to clipboard