APT Package Management
Master the APT package management system in Debian 13 and learn how to install, update, and manage software packages

APT (Advanced Package Tool) is the core package management tool of Debian systems. This tutorial will teach you how to use APT to install, update, and remove software packages.
🎯 APT Basic Concepts
What is APT?
APT is the package management tool of Debian systems, responsible for:
- 📦 Package installation: Downloading and installing software from repositories
- 🔄 Dependency handling: Automatically resolving package dependencies
- ⬆️ System updates: Upgrading installed packages
- 🗑️ Software removal: Safely uninstalling unwanted software
Repositories
A repository is a storage location for software packages:
# Main repository component types
main # Free software officially maintained by Debian
contrib # Free software that depends on non-free software
non-free # Non-free software
security # Security updates
updates # Stable release updates🔧 Basic APT Commands
Updating the Package List
Before using APT, first update the package list:
# Update the package list (recommended before every use)
sudo apt update
# Example output:
# Hit:1 http://deb.debian.org/debian trixie InRelease
# Get:2 http://security.debian.org/debian-security trixie-security InRelease [48.0 kB]
# Reading package lists... Done💡 Beginner Tip
apt update only updates the package list; it does not actually install or upgrade any software. This command is like "refreshing the store's product catalog."
Installing Packages
Installing a Single Package
# Basic install command
sudo apt install package-name
# Example: install a text editor
sudo apt install vim
# Show detailed information during installation
sudo apt install -v firefox-esrInstalling Multiple Packages
# Install multiple packages at once
sudo apt install git curl wget
# Install a specific version
sudo apt install python3=3.11.2-1
# Reinstall (to fix a broken installation)
sudo apt install --reinstall firefox-esrInstalling Suggested Packages
# Include suggested packages during installation
sudo apt install --install-suggests libreoffice
# Do not install suggested packages (default behavior)
sudo apt install --no-install-suggests gimpSearching for Packages
Basic Search
# Search package names and descriptions
apt search keyword
# Example: search for editors
apt search editor
# Search for a specific feature
apt search "media player"Precise Search
# Search package names only
apt search --names-only firefox
# Search using a regular expression
apt search '^python3-'Showing Package Information
# Show detailed package information
apt show package-name
# Example
apt show firefox-esr
# Show installed version information
apt list --installed firefox-esr
# Show available versions
apt list firefox-esrUpgrading the System
Upgrading Installed Packages
# Upgrade all upgradable packages
sudo apt upgrade
# Upgrade a specific package
sudo apt upgrade firefox-esr
# Full upgrade (including removing conflicting packages)
sudo apt full-upgradeSecurity Upgrades
# Install only security updates
sudo apt upgrade -s | grep security
sudo apt install $(apt list --upgradable 2>/dev/null | grep security | cut -d/ -f1)Removing Packages
Removing Packages
# Remove a package (keep configuration files)
sudo apt remove package-name
# Example
sudo apt remove firefox-esr
# Remove completely (including configuration files)
sudo apt purge package-name
# Automatically remove unneeded dependencies
sudo apt autoremoveCleaning Up the System
# Clean the downloaded package file cache
sudo apt clean
# Clean only outdated package files
sudo apt autoclean
# Remove orphaned packages
sudo apt autoremove --purge📋 Recommended Common Packages
Development Tools
# Essential development tools
sudo apt install build-essential
# Git version control
sudo apt install git
# Code editors
sudo apt install vim nano code
# Programming languages
sudo apt install python3 python3-pip nodejs npmMultimedia Tools
# Audio players
sudo apt install audacity rhythmbox
# Video players
sudo apt install vlc mpv
# Image editing
sudo apt install gimp inkscape
# Audio and video codecs
sudo apt install ffmpeg gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-uglyNetwork Tools
# Network diagnostics
sudo apt install net-tools curl wget
# Download tools
sudo apt install aria2 youtube-dl
# Browsers
sudo apt install firefox-esr chromiumOffice Software
# LibreOffice office suite
sudo apt install libreoffice
# PDF readers
sudo apt install evince okular
# Mind mapping
sudo apt install freemind⚙️ Repository Management
Viewing Current Repositories
# View repository configuration
cat /etc/apt/sources.list
# View additional repositories
ls /etc/apt/sources.list.d/Editing Repositories
# Edit the main sources file
sudo nano /etc/apt/sources.list
# Complete repository configuration for Debian 13 (Trixie) (including non-free software and firmware):
deb http://deb.debian.org/debian trixie main contrib non-free non-free-firmware
deb-src http://deb.debian.org/debian trixie main contrib non-free non-free-firmware
deb http://security.debian.org/debian-security trixie-security main contrib non-free non-free-firmware
deb-src http://security.debian.org/debian-security trixie-security main contrib non-free non-free-firmware
deb http://deb.debian.org/debian trixie-updates main contrib non-free non-free-firmware
deb-src http://deb.debian.org/debian trixie-updates main contrib non-free non-free-firmwareThe difference between non-free and non-free-firmware
non-free-firmware: Hardware firmware (WiFi, graphics card, Bluetooth firmware, etc.), a dedicated component newly added in Debian 13non-free: Other non-free software (such as NVIDIA driver packaging, proprietary fonts, etc.)
If you need to install non-free software such as the NVIDIA driver (nvidia-driver), you must also keep the non-free component.
Using Chinese Mirror Sources
To improve download speeds in China, you can use Chinese mirrors:
# Back up the original file
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
# Edit the sources
sudo nano /etc/apt/sources.listTsinghua University mirror:
# Tsinghua University mirror source
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ trixie main contrib non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ trixie main contrib non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security trixie-security main contrib non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security trixie-security main contrib non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ trixie-updates main contrib non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ trixie-updates main contrib non-free-firmwareUSTC mirror:
# USTC mirror source
deb https://mirrors.ustc.edu.cn/debian/ trixie main contrib non-free-firmware
deb-src https://mirrors.ustc.edu.cn/debian/ trixie main contrib non-free-firmware
deb https://mirrors.ustc.edu.cn/debian-security/ trixie-security main contrib non-free-firmware
deb-src https://mirrors.ustc.edu.cn/debian-security/ trixie-security main contrib non-free-firmware
deb https://mirrors.ustc.edu.cn/debian/ trixie-updates main contrib non-free-firmware
deb-src https://mirrors.ustc.edu.cn/debian/ trixie-updates main contrib non-free-firmwareAdding Third-Party Repositories
Adding a GPG Key
# Download and add a GPG key
# Modern method (recommended)
wget -qO - https://example.com/key.gpg | sudo gpg --dearmor -o /usr/share/keyrings/example-keyring.gpgAdding a Repository
# Create a new repository file
echo "deb [signed-by=/usr/share/keyrings/example-keyring.gpg] https://example.com/debian stable main" | sudo tee /etc/apt/sources.list.d/example.list
# Update the package list
sudo apt update🔍 Advanced APT Operations
Package Dependencies
# View a package's dependencies
apt depends package-name
# View which packages depend on this package
apt rdepends package-name
# Simulate an installation (without actually installing)
sudo apt install -s package-namePackage File Operations
# Download a package file without installing
apt download package-name
# List the files contained in a package
dpkg -L package-name
# Find which package a file belongs to
dpkg -S /path/to/file
# View a package's installation scripts
apt-get source package-nameVersion Control
# Hold a package version (prevent upgrades)
sudo apt-mark hold package-name
# Release a version hold
sudo apt-mark unhold package-name
# View held packages
apt-mark showhold
# Downgrade a package (requires an available older version)
sudo apt install package-name=version🛡️ Security and Best Practices
Security Updates
# Set up automatic security updates
sudo apt install unattended-upgrades
# Configure automatic updates
sudo dpkg-reconfigure unattended-upgrades
# Manually check for security updates
sudo unattended-upgrade --dry-runSystem Maintenance
# Regular maintenance commands (recommended weekly)
sudo apt update && sudo apt upgrade
sudo apt autoremove
sudo apt autoclean
# Check system integrity
sudo apt check
# Fix broken packages
sudo apt install -fBackup and Recovery
# Export the list of installed packages
dpkg --get-selections > installed-packages.txt
# Restore the package list
sudo dpkg --set-selections < installed-packages.txt
sudo apt-get dselect-upgrade🆘 Troubleshooting
Common Issues
GPG Key Errors
# Problem: NO_PUBKEY error
# Or use the modern method
wget -qO - https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xKEYID | sudo gpg --dearmor -o /usr/share/keyrings/package-keyring.gpgPackage Dependency Problems
# Fix broken dependencies
sudo apt install -f
# Clean up and reconfigure
sudo dpkg --configure -a
# Force-remove a problematic package
sudo dpkg --remove --force-remove-reinstreq package-nameInsufficient Disk Space
# Clean the package cache
sudo apt clean
# Remove unneeded packages
sudo apt autoremove --purge
# Find large files
sudo du -h /var/cache/apt/archives/📱 Graphical Package Management
Synaptic Package Manager
# Install the graphical package manager
sudo apt install synaptic
# Run Synaptic
sudo synapticGNOME Software Center
# Install GNOME Software
sudo apt install gnome-software
# Launch the software center
gnome-software🌐 Looking Up Package Information Online
In addition to local commands like apt show and apt-cache policy, you can also look up packages online with pkgseek:
- Package pages: URLs follow the format
https://pkgseek.com/packages/<package-name>, for example ffmpeg, vlc, nginx. You can see the actual version in Debian 13, its dependencies, and related CVEs. - Cross-distribution comparison: Compare the versions of the same package in Debian, Ubuntu, Fedora, Arch, and other distributions side by side.
- Error to command: Paste errors like "command not found", missing libraries, or missing headers into the Command Doctor and get the installation command directly.
- Reverse file lookup: Enter a path in the file lookup to find out which package it belongs to.
Next Steps
After mastering APT package management, you can continue learning:
- System Service Management - Manage system services
- User and Permission Management - User and permission configuration
- Network Configuration - Network settings and management
Want to learn more system administration skills? Continue with system services →
NVIDIA Optimus Dual Graphics Configuration
Configure NVIDIA Optimus hybrid graphics on a Debian 13 laptop, install drivers and use PRIME Render Offload
Security Management
Learn how to manage the security of your Debian system, including user access control, firewall configuration, automatic updates, and intrusion detection.