Debian & Ubuntu
Package Management
Basic package management on Debian and Ubuntu Linux. A practical guide to using APT and DPKG for installing, updating, and managing .deb packages.
This guide applies to Debian, Ubuntu, Linux Mint, Pop!_OS and other Debian/Ubuntu-based distributions using APT and DEB packages.
Linux distributions based on Debian use .deb packages. The low-level package tool is dpkg, while the normal user-facing package manager is apt.
In practical use:
apt-get = recommended for scripts and automation
dpkg = lower-level tool for local .deb files and package database operations
Querying Packages
1. Piping commands together
In the terminal, commands can be combined with the pipe character: |
A pipe sends the output of one command into another command. This is useful when you want to filter or process long command output.
Example:
This command lists packages known to dpkg and filters only lines containing the word zip. However, this can also match package names, descriptions or related text.
For a cleaner package-name search, use:
2. Check whether a package is installed
Check whether a package is installed using apt:
# Example:
apt list –installed zip
Check package status using dpkg:
# Example:
dpkg -s zip
Search installed packages with dpkg and dpkg-query:
dpkg-query -l ‘*zip*’
3. List installed packages
List installed packages using apt:
List packages known to dpkg:
List only package names of installed packages:
4. Search for packages in repositories
Search for an available package:
# Example:
apt search zip
Show detailed package information:
# Example:
apt show zip
Updates & Installing Packages
5. Update package information
Before installing or upgrading packages, update the local package index:
This does not upgrade packages by itself. It only refreshes information about available packages and versions from the configured repositories.
6. Upgrade installed packages
Upgrade installed packages:
Show packages that can be upgraded:
For a more complete upgrade that may install new dependencies or remove conflicting packages when required:
Use full-upgrade carefully on servers and production systems. Always read the list of packages that will be removed or changed before confirming.
7. Install a package from repositories
Install a package from the configured repositories:
# Example:
sudo apt install zip
Install multiple packages at once:
8. Install a local .deb file
To install a local Debian package file:
This is usually better than using dpkg directly, because apt can also resolve and install missing dependencies from repositories when possible.
The lower-level dpkg method is:
# Short form:
sudo dpkg -i package-file.deb
If dpkg reports missing dependencies, repair the installation with:
Removal & Cleanup
9. Remove a package
Remove an installed package but keep its system configuration files:
# Example:
sudo apt remove zip
# Remove multiple packages:
sudo apt remove package1 package2 package3
10. Purge a package completely
Remove a package including its system configuration files:
# Alternative form:
sudo apt remove –purge package-name
Important: purge removes package configuration files from system locations such as /etc. It does not normally remove user data stored in home directories.
11. Remove unused dependencies
After removing packages, some automatically installed dependencies may no longer be needed. Remove them with:
Remove unused dependencies and purge their configuration files:
Always read the list of packages before confirming.
12. Clean downloaded package cache
APT stores downloaded package files in its cache. To remove old downloaded package files that can no longer be downloaded:
To clear the local package cache more aggressively:
13. Remove a package with dpkg
The lower-level dpkg removal command is:
# Short form:
sudo dpkg -r package-name
This removes the package files but usually keeps configuration files.
To purge a package with dpkg:
Use dpkg directly only when you know why apt is not the right tool for the job.
Inspection, Reinstall & Logs
14. Reinstall a package
Reinstall a package from repositories:
# Example:
sudo apt reinstall zip
17. Hold a package version
Prevent a package from being automatically upgraded:
Remove the hold & Show held packages:
apt-mark showhold
15. Find which package owns a file
If a file exists on the system and you want to know which package installed it:
# Example:
dpkg -S /usr/bin/zip
16. List files installed by a package
Show files installed by a package:
# Example:
dpkg -L zip
18. Check package manager logs
APT history log & terminal output log:
less /var/log/apt/term.log
dpkg log:
19. Useful command summary
sudo apt upgrade
apt list –upgradable
apt search package-name
apt show package-name
apt list –installed
apt list –installed package-name
sudo apt install package-name
sudo apt install ./package-file.deb
sudo apt remove package-name
sudo apt purge package-name
sudo apt autoremove
sudo apt autoremove –purge
sudo apt clean
sudo apt autoclean
dpkg -l
dpkg -s package-name
dpkg -L package-name
dpkg -S /path/to/file
sudo dpkg -i package-file.deb
sudo apt –fix-broken install
sudo dpkg -r package-name
sudo dpkg –purge package-name