Linux Package Management: APT, DPKG, and Beyond
Master Linux package management across Debian-based systems including APT, DPKG, repository configuration, dependency resolution, and troubleshooting.
Managing Software on Linux
Every security tool on Kali Linux — from Nmap to Metasploit — is installed through the package management system. Knowing how to install, update, and troubleshoot packages is a core operational skill that you will use daily. This guide covers APT, DPKG, and related tools so you can keep your environment up to date and resolve dependency issues without breaking your system.
Prerequisites
Familiarity with basic Linux commands and terminal navigation. Root or sudo access for package operations.
DPKG — The Foundation
DPKG is the low-level tool that directly installs, removes, and queries .deb packages.
Basic DPKG Commands
sudo dpkg -i package.deb # Install a .deb file
sudo dpkg -r package_name # Remove a package (keep configs)
sudo dpkg -P package_name # Purge a package (remove everything)
dpkg -l # List installed packages
dpkg -L package_name # List files installed by a package
dpkg -S /path/to/file # Find which package owns a file
DPKG Troubleshooting
sudo apt --fix-broken install # Fix missing dependencies
APT — The Package Manager
APT works with DPKG to provide dependency resolution, repository management, and a user-friendly interface.
Repository Configuration
APT works with sources in /etc/apt/sources.list:
deb http://http.kali.org/kali kali-rolling main non-free contrib
Essential APT Commands
sudo apt update # Update package index
sudo apt upgrade # Upgrade all packages
sudo apt full-upgrade # Full upgrade with dependency changes
sudo apt install nmap # Install a package
sudo apt remove nmap # Remove a package
sudo apt purge nmap # Purge a package and configs
apt search "web scanner" # Search for packages
apt show nmap # Show package information
apt list --installed # List installed packages
sudo apt autoremove # Remove unneeded packages
sudo apt clean # Clear package cache
APT Update Pipeline
Dependency Resolution
apt install --dry-run wireshark # Simulate install without changes
Adding Third-Party Repositories
# Method 1: add-apt-repository
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
# Method 2: Manual repository file
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker.gpg] https://download.docker.com/linux/debian bookworm stable" | sudo tee /etc/apt/sources.list.d/docker.list
# Method 3: Direct .deb download
wget https://example.com/software.deb
sudo dpkg -i software.deb
sudo apt --fix-broken install
Package Hold and Pinning
sudo apt-mark hold package_name # Prevent package from being upgraded
sudo apt-mark unhold package_name # Unhold a package
apt-mark showhold # Show held packages
Real-World Examples
Installing Metasploit: sudo apt install metasploit-framework
Minimal install: sudo apt install --no-install-recommends package
Upgrading Kali: sudo apt update && sudo apt full-upgrade -y
Common Mistakes
Running apt upgrade without apt update first. Using unstable repos without pinning. Forgetting GPG keys for third-party repos.
Best Practices
Always run sudo apt update before sudo apt upgrade. Use apt search and apt show before installing. Use --dry-run to preview changes. Remove unused packages with sudo apt autoremove. Verify GPG keys when adding repositories.
Related Tools
snap — Canonical's container package system. flatpak — Sandboxed applications. gdebi — GUI .deb installer. aptitude — Alternative APT interface.
Related Articles
Summary
Package management on Debian systems uses DPKG (low-level .deb handling) and APT (high-level dependency resolution). Essential commands: apt update,apt install, apt upgrade, apt remove. Understanding both tools is fundamental to maintaining a healthy Linux system.