apt Commands

apt commands cheatsheet.

Install, remove, update and upgrade packages on Debian and Ubuntu — the apt commands you reach for daily. Tap to copy.

Install & remove
sudo apt install nginxInstall a package
sudo apt install nginx=1.24.0Install a specific version
sudo apt remove nginxRemove a package but keep its config
sudo apt purge nginxRemove a package and its config
sudo apt autoremoveRemove unused dependencies
sudo apt install --reinstall nginxReinstall a package
Update & upgrade
sudo apt updateRefresh the package index (do this first)
sudo apt upgradeUpgrade all installed packages
sudo apt full-upgradeUpgrade, removing packages if required
sudo apt update && sudo apt upgrade -yRefresh and upgrade in one line
Search & inspect
apt search keywordSearch packages by name or description
apt show nginxShow details about a package
apt list --installedList installed packages
apt list --upgradableList packages with updates available
apt-cache policy nginxShow installed and available versions
Maintenance
sudo apt-get cleanClear the local package cache
sudo dpkg -i package.debInstall a local .deb file
sudo apt --fix-broken installFix broken or half-installed dependencies
sudo apt-mark hold nginxPrevent a package from being upgraded

Installing software on Debian & Ubuntu

apt is the package manager for Debian-based systems. The one habit worth building: run apt update to refresh the package index before installing or upgrading, so you get current versions. Use remove to uninstall but keep config, or purge to remove everything.

On macOS, the equivalent is Homebrew. See also the Linux commands reference and pip for Python packages.

FAQ

What's the difference between apt remove and purge?
remove deletes the package but leaves its configuration files behind; purge removes both. Follow either with apt autoremove to clear unused dependencies.
Do I need apt update before installing?
Yes — apt update refreshes the list of available packages and versions. Without it you may install an outdated version or hit a not-found error.

More cheatsheets