skip to content

apt-get Package Management

Debian and Ubuntu package management β€” update, install, remove, upgrade, and maintain packages with apt-get.

2 min read 7 snippets 3d ago

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#

FlagEffect
-yAssume yes to all prompts
-qQuiet β€” suppress progress output
--no-install-recommendsSkip recommended (not required) packages
-fFix broken installs
-s / --simulateDry-run: show what would happen
--reinstallReinstall 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-get handles downloads and installs. For searching and querying metadata, use apt-cache search, apt-cache show, and apt-cache depends.