This guide explores about dpkg Command in Linux. The dpkg command syntax and options. The dpkg in Linux is the primary package manager for Debian and Debian-based systems, such as Ubuntu. The tool installs, builds, removes, configures, and retrieves information for Debian packages. The command works with packages in .deb format.
- A system with a Debian or a Debian-based OS.
- Access to the command line/terminal as sudo.
- A .deb file to work with the examples.
dpkg Command in Linux
dpkg Command Syntax
The basic syntax for the dpkg command is:
$ dpkg [options] action
The command accepts one action and zero or more options.
The dpkg command acts as a front-end for the following two tools:
- The dpkg-deb command, which shows information about .deb packages.
- The dpkg-query command, which shows the information from the dpkg database.
The dpkg command runs actions from dpkg-query and dpkg-deb. Therefore, the following two commands show the same result:
$ dpkg -l
$ dpkg-query -l
The action -l is a dpkg-query action that lists all packages from the dpkg database. The dpkg command detects the foreign options and runs dpkg-query automatically.
dpkg Command Options
The table below provides brief descriptions of commonly used options and actions for the dpkg command.
|Action||Installs the package.|
|Action||Unpacks the package without configuration.|
|Action||Configures an unpacked package.|
|Action||Removes an installed package. Does not remove configuration files and other data.|
|Action||Purges an installed or removed package. Deletes configuration files and other data.|
|Action||Fetches packages with current selections.|
|Action||Sets file selection states from a file read from standard input.|
|Builds a .deb package.|
|Lists package contents.|
|Shows information about a package.|
|Lists packages by matching the pattern.|
|List installed package’s file locations.|
|Shows the status of an installed package.|
|Search for a pattern in installed packages.|
|Option||Handles action recursively in target directory and subdirectories.|
|Option||Logs status change updates to a file.|
|Option||Shows output without committing changes. Use before action.|
Actions that change the system, such as package installation or removal, require sudo privileges. Information-based options do not require special user privileges.
Privileged access management helps secure the system by disallowing regular users to make system-wide changes.
Installing deb files with dpkg
dpkg is a low-level package manager for Debian-based systems. Use the -i (or –install) option to install deb packages with dpkg.
$ sudo dpkg -i code_1.70.1_amd64.deb
$ sudo dpkg -i code_1.70.1_amd64.deb [sudo] password for techdhee: Selecting previously unselected package code. (Reading database ... 199013 files and directories currently installed.) Preparing to unpack code_1.70.1_amd64.deb ... Unpacking code (1.70.1-1660113095) ... Setting up code (1.70.1-1660113095) ... Processing triggers for mailcap (3.70+nmu1ubuntu1) ... Processing triggers for gnome-menus (3.36.0-1ubuntu3) ... Processing triggers for desktop-file-utils (0.26-1ubuntu3) ... Processing triggers for shared-mime-info (2.1-2) ...
The command requires sudo to install a .deb package.
List Known Packages
To list all known packages, use the -l tag:
$ dpkg -l
The command prints the packages in pager mode. Navigate using the arrow keys or use space to list by page. Press q to exit the list. The columns list each package’s name, version, architecture, and description.
To remove a Debian package, use the following command:
$ dpkg -r <package>
To purge a package, use the -P option:
$ sudo dpkg -P <package>
Show Package Contents
A .deb package contains several files and directories, indicating where the package resides after installation or unpacking.
To display the package contents, run:
$ dpkg -c <package.deb>
Check If the Package Installed
To check whether a package is installed, use the -s tag:
$ dpkg -s <package>
Show Package Information
To show package information directly from the .deb file, use the following command:
$ dpkg -I <package.deb>
List Installed Package Files’ Locations
To list the package files and their location, use the -L tag:
$ dpkg -L <package>
Check dpkg Command Version
To check which dpkg version the system is running, use:
$ dpkg --version
The output shows the dpkg version along with the architecture.
To show a simple help menu, use the following command:
$ dpkg --help
Use the man command to find find the complete documentation.
After following this tutorial and the examples from this tutorial, you should master the basics of the
dpkg command. You can use it as you want. Enjoy!!!
Related Linux Tutorials: