dpkg is a low-level package management command-line tool used in Debian-based systems to install, configure, and remove software packages. This cheat sheet covers essential dpkg commands for managing packages.

Introduction:

dpkg directly interacts with the Debian package system, providing low-level package management capabilities. It is the underlying tool for package management on Debian-based systems.

Basic Commands:

CommandDescription
sudo dpkg -i [package.deb]Install a .deb package file.
sudo dpkg -r [package]Remove (uninstall) a package.
sudo dpkg -P [package]Purge a package, removing its configuration files.
sudo dpkg -L [package]List files installed by a package.
sudo dpkg -lList all installed packages.
sudo dpkg -s [package]Display information about a package.

Querying and Searching:

CommandDescription
dpkg-query -lList all installed packages.
dpkg-query -L [package]List files installed by a package.
dpkg-query -S [file]Find the package providing a specific file.
`dpkg -lgrep [keyword]`

Updating and Clearing:

CommandDescription
sudo dpkg --configure -aConfigure all unpacked but unconfigured packages.
sudo dpkg-reconfigure [package]Reconfigure a package.
sudo dpkg --clear-selectionsClear the package selections.

Information and Troubleshooting:

CommandDescription
dpkg --get-selectionsList all installed packages and their status.
dpkg-reconfigure [package]Reconfigure a package.
sudo dpkg --auditCheck for broken dependencies and missing packages.

Miscellaneous:

CommandDescription
sudo dpkg --add-architecture [architecture]Add a new architecture (e.g., i386 for 32-bit) to the system.
sudo dpkg --remove-architecture [architecture]Remove an architecture from the system.
sudo dpkg -I [package.deb]Display information about a .deb package file.
dpkg --helpDisplay help and usage information for dpkg.

Conclusion

dpkg is a fundamental tool for managing packages on Debian-based systems. This cheat sheet covers essential commands for installing, removing, querying, and troubleshooting packages using dpkg. Whether you are a system administrator or a Debian user, these commands will help you efficiently manage software packages on your system.