apt — Package Management on Debian & Ubuntu
Master apt commands for installing, updating, removing, and searching packages on Debian, Ubuntu, and their derivatives.
March 17, 20255 min read
linuxaptdebianubuntupackages
Essential apt Commands
sudo apt update # Refresh package list from repos
sudo apt upgrade # Upgrade all installed packages
sudo apt install nginx # Install a package
sudo apt remove nginx # Remove (keep config files)
sudo apt purge nginx # Remove + delete config files
sudo apt autoremove # Remove unused dependencies
sudo apt search "text editor" # Search available packages
apt show nginx # Show package details
apt list --installed # List all installed packages
apt list --upgradable # List packages with updatesCommon Patterns
# Update + upgrade in one go
sudo apt update && sudo apt upgrade -y
# Install multiple packages
sudo apt install nginx php mysql-server
# Install specific version
sudo apt install nginx=1.18.0-0ubuntu1
# Fix broken dependencies
sudo apt --fix-broken install
# Clean download cache
sudo apt clean
sudo apt autocleandpkg — Low-level (Manual .deb Files)
sudo dpkg -i package.deb # Install a .deb file manually
dpkg -l # List all installed packages
dpkg -L nginx # List files installed by a package
dpkg -S /usr/bin/vim # Which package owns this file?
sudo dpkg -r package # Remove packageAlways run sudo apt update before installing — without it, you might install an outdated version or get 'package not found' errors.
Quick Check
What is the difference between `apt remove` and `apt purge`?
Exercise
Update your package list, then search for the tree package and install it.