Beyond basic apt install, understanding apt and dpkg more deeply helps you troubleshoot package issues, manage versions precisely, and keep a Debian/Ubuntu system clean.
apt vs apt-get vs dpkg: Understanding the Layers
dpkg is the low-level package tool that actually installs/removes .deb packages; apt (and the older apt-get) are higher-level tools that handle dependency resolution and repository management on top of dpkg.
Searching for Packages
apt search nginx
Viewing Detailed Package Information
apt show nginx
Listing Installed Packages
apt list --installed
Checking Which Package Provides a Specific File
dpkg -S /usr/bin/nginx
Listing Files Installed by a Package
dpkg -L nginx
Installing a Specific Package Version
apt list -a nginx
sudo apt install nginx=1.24.0-1
Useful when you need to pin a specific version rather than always installing the latest available.
Holding a Package at Its Current Version
sudo apt-mark hold nginx
Prevents a specific package from being upgraded during general apt upgrade operations — useful if a newer version has a known compatibility issue with your setup.
Releasing a Hold
sudo apt-mark unhold nginx
Cleaning Up Unused Dependencies
sudo apt autoremove
Clearing the Local Package Cache
sudo apt clean
Removes downloaded .deb files from /var/cache/apt/archives, freeing disk space — safe since these can be re-downloaded if needed again.
Fixing a Broken Package State
sudo apt --fix-broken install
Attempts to resolve dependency issues from an interrupted or partial installation.
Reconfiguring an Already-Installed Package
sudo dpkg-reconfigure PACKAGE_NAME
Re-runs a package's initial configuration prompts — useful for packages like tzdata or others with interactive setup you want to redo.
Adding a Third-Party Repository Safely
curl -fsSL https://example.com/gpg-key | sudo gpg --dearmor -o /etc/apt/keyrings/example.gpg
echo "deb [signed-by=/etc/apt/keyrings/example.gpg] https://repo.example.com stable main" | sudo tee /etc/apt/sources.list.d/example.list
Using a dedicated keyring file (rather than the older, now-deprecated apt-key add method) is the current recommended approach for adding third-party repository signing keys.
Checking for Held-Back Upgrades
apt list --upgradable
Common Errors
"E: Unable to locate package" — run sudo apt update first to refresh the package index, or verify the package name is spelled correctly and the relevant repository is actually enabled.
"dpkg was interrupted" errors — run sudo dpkg --configure -a to complete any interrupted package configuration before retrying other apt operations.
Continue Reading
- How to Update and Upgrade Your Ubuntu or Debian VPS
- How to Enable Automatic Security Updates on Ubuntu & Debian
- Common Debian Package Management Errors and Fixes
Browse more articles in Linux Server Administration.