apt-get Package Management#
apt-get is the command-line front-end to APT (Advanced Package Tool) on Debian-based systems (Debian, Ubuntu, Mint, Raspberry Pi OS, etc.).
Update & upgrade#
# Refresh the local package index (always run before upgrading/installing)
apt-get update
# Upgrade installed packages β won't remove or add packages
apt-get upgrade
# Full upgrade: installs new deps and removes conflicting packages
# Also allows transitioning to the next minor OS release (e.g. 22.04.1 β 22.04.2)
apt-get dist-upgrade
# One-liner: refresh then full-upgrade
apt-get update && apt-get dist-upgrade
Install & remove#
# Install one or more packages (with dependencies)
apt-get install PACKAGE
apt-get install nginx curl git
# Install without recommended packages
apt-get install --no-install-recommends PACKAGE
# Remove a package (keeps config files)
apt-get remove PACKAGE
# Remove a package AND its system-wide configuration files
apt-get purge PACKAGE
apt-get remove --purge PACKAGE # equivalent
# Fix broken dependency tree (run when apt complains about unmet deps)
apt-get -f install
Download without installing#
# Download .deb to current directory (no install)
apt-get download PACKAGE
# Download a package AND its important dependencies (useful for offline installs)
apt-get download firefox \
$(apt-cache --important depends firefox | awk '{if(NR>1){printf("%s ", $2)}}')
Cache maintenance#
# Remove .deb files that can no longer be downloaded (interrupted downloads)
apt-get autoclean
# Remove ALL cached .deb files and package index files
apt-get clean -s # -s = simulate; omit to actually clean
apt-get clean
# Remove packages that were installed as dependencies but are no longer needed
apt-get autoremove
Useful flags#
| Flag | Effect |
|---|---|
-y | Assume yes to all prompts |
-q | Quiet β suppress progress output |
--no-install-recommends | Skip recommended (not required) packages |
-f | Fix broken installs |
-s / --simulate | Dry-run: show what would happen |
--reinstall | Reinstall already-installed package |
-o Dir::Cache="β¦" | Override cache directory |
Silence config-file prompts in batch updates#
# Keep existing config files during unattended upgrades
apt-get update -o DPkg::Options::='--force-confold' && apt-get upgrade -y
Find whatβs installed#
# Show packages installed since log began
grep 'install ' /var/log/dpkg.log
# List manually installed packages
apt-mark showmanual
# Check if a specific package is installed
dpkg -l PACKAGE
View the changelog before upgrading#
apt-get changelog firefox
Tip:
apt-gethandles downloads and installs. For searching and querying metadata, useapt-cache search,apt-cache show, andapt-cache depends.