The dpkg
command in Linux is the low-level package manager for Debian-based distributions like Ubuntu. It is used to install, remove, and manage .deb
packages. Here's a list of common dpkg
commands, along with example outputs:
sudo dpkg -i <package_name>.deb
Example:
sudo dpkg -i mypackage.deb
Output:
Selecting previously unselected package mypackage.
(Reading database ... 12345 files and directories currently installed.)
Preparing to unpack mypackage.deb ...
Unpacking mypackage (1.0) ...
Setting up mypackage (1.0) ...
sudo dpkg -r <package_name>
Example:
sudo dpkg -r mypackage
Output:
(Reading database ... 12345 files and directories currently installed.)
Removing mypackage (1.0) ...
sudo dpkg -P <package_name>
Example:
sudo dpkg -P mypackage
Output:
(Reading database ... 12345 files and directories currently installed.)
Purging mypackage (1.0) ...
dpkg -l
Example:
dpkg -l
Output:
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Installed/Configured/Unpacked/Failed-Config/Half-Installed
|/ Error?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-======================-======================-======================-=======================================================
ii bash 5.0-6ubuntu1.1 amd64 GNU Bourne Again SHell
ii libc6 2.31-0ubuntu9.9 amd64 GNU C Library: Shared libraries
dpkg -s <package_name>
Example:
dpkg -s bash
Output:
Package: bash
Status: install ok installed
Priority: important
Section: shells
Installed-Size: 1168
Maintainer: Ubuntu Developers <[email protected]>
Architecture: amd64
Version: 5.0-6ubuntu1.1
Depends: libc6 (>= 2.17)
Description: GNU Bourne Again SHell
dpkg -L <package_name>
Example:
dpkg -L bash
Output:
/.
/usr
/usr/bin
/usr/bin/bash
/usr/share
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/bash.1.gz
dpkg -S <file_name>
Example:
dpkg -S /usr/bin/bash
Output:
bash: /usr/bin/bash
sudo dpkg --configure -a
Example:
sudo dpkg --configure -a
Output:
(Reading database ... 12345 files and directories currently installed.)
Setting up mypackage (1.0) ...
sudo apt-get install -f
(Although apt-get
is not a dpkg
command, it can be used to fix broken dependencies after dpkg
operations.)
dpkg --audit
Example:
dpkg --audit
Output:
dpkg: error: could not open package info file '/var/lib/dpkg/status': No such file or directory
dpkg --help
Output:
Usage: dpkg [option...] <package_file...>
Options:
-?, --help Show this help message
-D, --debug Enable debugging output
-i, --install Install the package(s)
-r, --remove Remove the package(s)
-P, --purge Purge the package(s)
-L, --listfiles List files installed by package
-S, --search Search for a package owning a file
-s, --status Show package information