How to Use dpkg Command in Linux

The dpkg command in Linux is a package management command-line utility. You can use this command for various situations that include installing packages, removing the desired ones entirely, checking updates, maintaining repositories, and more.

When we talk about packages in UNIX-based systems, we’re looking at a compressed archive of files and dependencies that are crucial for installing and running any program or service. 

The packages are stored within a local repository, no matter which system you’re operating on. 

Encountering situations when you need to manage these packages and corresponding repositories is pretty common, and this is when the dpkg command hits the scene.

The dpkg command can be essentially described as a tool that helps build, install, remove and manage Debian packages in every possible manner. The command offers an efficient way to interact with the system packages.

In this article, we’ll walk you through the command and its possible uses.

dpkg Command in Linux: Syntax

The basic structure of dpkg command in Linux looks something like this:

$ dpkg [OPTIONS] [deb package name]
dpkg command in Linux syntax

This command-line utility bags several options that help customize the data you receive in various ways. Following is the list of options you can use alongside the dpkg command in Linux.

-i or -install flag: You’ll need to use this option when you’re willing to install a package with the dpkg command. Running this flag will extract the control files available for the desired package. It will also remove any previously seated version and install the new package.

-r or -remove flag: The -r flag is executed to remove an installed package from your system. The option ensures that every package file except the configuration ones is removed entirely. In simple words, the -remove flag works as an uninstall command.

-P or -purge flag: As already mentioned, the -r command doesn’t remove the configuration file while uninstalling a package. This is when the -P or -purge flag comes in. It is an alternative to the -r flag that removes the configuration files and uninstalls a specific package.

-update-avail flag: Using the -update-avail flag with the dpkg command in Linux will print the information about the available packages in a repository. In case there are any, the command will sync them from the official sources.

-merge-avail flag: As the name suggests, the flag helps merge the information about the available packages. It is usually employed right after executing -update-avail option.

--help flag: Executing this flag will simply print the dpkg command help options and exit.

--version flag: Use this to display the version information about the dpkg command in Linux.

How to Use dpkg Command in Linux

Now that you’re well aware of the dpkg command, its syntax, and the available options, let’s explore the common ways in which the command can help you deal with certain situations. 


Before proceeding with the dpkg command, ensure you’ve access to the following:

sudo privileges

Terminal access (you can use the “Ctrl+Alt+T” key combination to launch it)

Installing a Package Using dpkg Command in Linux

One of the most usual utilities of Linux’s dpkg command is, of course, package installation. You can do that by simply applying the -i flag alongside the dpkg command, followed by the package name.

Here is what you’ll need to do:

Launch the Terminal

Run the following command:

$ sudo dpkg -i [name of the package]
using dpkg command to install packages

Installing Multiple Packages

Similar to how the dpkg command works for installing a single package, you can employ the same to install multiple packages simultaneously. All you need to do is separate the name of the packages with spaces.

$ sudo dpkg -i [package1] [package2] [package3]
installing multiple packages with dpkg command

Using dpkg Command in Linux to Remove a Package

If you’re willing to remove a package from your system, pass the -r flag followed by the package information. It will remove the package and the associated files, except for the configuration ones.

Here is how the code should look like:

$ sudo dpkg -r [package name]
use dpkg command to remove packages

Need to remove the configuration files as well? Luckily, the dpkg command in Linux has got us covered. Instead of the -r flag, pass the -p option. It will instruct the system to eliminate everything that the specific package comprises.

$ sudo dpkg -p [package name]
removing packages

Getting your Repositories Updates

Apart from installing and removing packages, the dpkg command in Linux is of great significance for updating the available repositories.

Although the dpkg command itself stores the packages open for installation, those often end up as outdated versions because of the new releases. However, you don’t need to worry much as the -update-avail flag is there to take care of.

Suppose you need to check if the repositories of package201 are updated. In that case, launch the terminal and run the following command:

$ sudo dpkg -update-avail [package201]
update repositories in Linux

Display dpkg Command Help

Using the --help flag alongside the dpkg command will display the help information and exit.


$ dpkg --help


display help dpkg command

Version Info

Pass the --version flag alongside the dpkg command and your system will print the version information


$ dpkg --version


version info

Other Utilities of the dpkg Command:

-V--verify: It helps verify the integrity of package(s). 

--get-selections: Use this to get a list of selections to stdout. 

--set-selections: This option helps set the package selections from stdin. 

--clear-selections: With this, you can deselect every non-essential package. 

--clear-avail: You can erase existing available info with this option.

--forget-old-unavail: Pass this flag to forget uninstalled unavailable packages. 

-s|--status <package>: It instructs the system to display package status details. 

-p|--print-avail <package>: It helps display available version details. 

-L|--listfiles <package>: This option prints the list files ‘owned’ by package(s). 

-l|--list [<pattern> ...]: One way to list packages concisely. 

-S|--search <pattern>: Use this flag to find package(s) owning file(s). 

-C|--audit [<package> ...]: It is mainly used to check for a broken package(s). 

-yet-to-unpack: It instructs the system to print packages selected for installation. 

--predep-package: This option helps in printing pre-dependencies to unpack. 

--add-architecture <arch>: It adds <arch> to the list of architectures. 

--remove-architecture <arch>: It removes <arch> from the list of architectures. 

--print-architecture: With this flag you can print the dpkg architecture. 

--print-foreign-architectures: Using this option will print allowed foreign architectures. 

--assert-<feature>: Use this to assert support for the specified feature. 

--validate-<thing> <string>: It helps in validating a <thing> <string>. 

--compare-versions <a> <op> <b>: As the structure suggests, it compares version numbers.

--force-help: Use this to show help on forcing. 

-Dh|--debug=help: Run this to show help on debugging.

uses of dpkg command

This wraps up today’s article. Here, we’ve discussed how you can use the dpkg command in Linux in the most efficient manner. Alongside the basic utilities, we’ve talked about the long list of options that come alongside this command-line utility.

If this guide helped you, please share it.

Leave a Reply
Related Posts