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 packagesudo apt install nginx=1.24.0Install a specific versionsudo apt remove nginxRemove a package but keep its configsudo apt purge nginxRemove a package and its configsudo apt autoremoveRemove unused dependenciessudo apt install --reinstall nginxReinstall a packageUpdate & upgrade
sudo apt updateRefresh the package index (do this first)sudo apt upgradeUpgrade all installed packagessudo apt full-upgradeUpgrade, removing packages if requiredsudo apt update && sudo apt upgrade -yRefresh and upgrade in one lineSearch & inspect
apt search keywordSearch packages by name or descriptionapt show nginxShow details about a packageapt list --installedList installed packagesapt list --upgradableList packages with updates availableapt-cache policy nginxShow installed and available versionsMaintenance
sudo apt-get cleanClear the local package cachesudo dpkg -i package.debInstall a local .deb filesudo apt --fix-broken installFix broken or half-installed dependenciessudo apt-mark hold nginxPrevent a package from being upgradedInstalling 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.