What is DPKG in Linux? [With Practical Applications]

DPKG is an abbreviation for Debian Package Manager. DPKG in Linux is useful for downloading, removing, or upgrading software packages. This is a powerful tool that can also be used with sudo, which lets us be the super user or sudo root user.

How to Use DPKG

DPKG must be used with sudo. Because to install or remove you need to be a root user. As you know sudo gives the root privilege. You can use DPKG in multiple ways, for multiple purposes. For example Installation, listing, or removal of packages. The DPKG command in Linux is a hashed command. This command takes different options to complete different operations.

Syntax

The syntax of this command is given below.

dpkg [OPTION]... FileName

The DPKG command in Linux has a lot of options. I have listed some of the important ones below.

Useful Options

  • -i, –install: This option installs packages.
  • –unpack: This option is used for unpacking packages.
  • -r, –remove: This option removes packages.
  • -P: This option also removes packages but with the configuration files.

Download “.deb” File

There are many ways that you can use the dpkg command. I will show you some examples in the next part of the article. Now first you need to have a “.deb” file. If you don’t have one then get the file below by typing in the terminal.

wget http://archive.ubuntu.com/ubuntu/pool/universe/c/cowsay/cowsay_3.03+dfsg2-4_all.deb

You can take a look at the picture below to see how this works.

installing a debian file

How to Install a Package Using DPKG in Linux

If you want to install a package on your machine that is a .deb file then you will have to use an option. Normally option (-i) is useful for installing packages. Now follow the steps below to see how this works.

Steps to Follow:

 Open your Ubuntu terminal.

➋  Write the following commands and press ENTER.

sudo dpkg -i cowsay_3.03+dfsg2-4_all.deb

➌  Now, press the ENTER button.

➍  Now, give your user password and press ENTER button

Output:

As you can see from the picture below that the .deb package installation is successful

Installing using dpkg in linux

How to List Installed Packages Using DPKG

If you want to see the packages on your machine that are .deb files then you will have to use an option. Normally option (-l) is useful for listing out packages. Now follow the steps below to see how this works.

Steps to Follow:

 Open your Ubuntu terminal.

➋  Write the following commands and press ENTER.

 dpkg -l

➌  Now, press the ENTER button.

Output:

As you can see that the list of the installed packages is on the terminal.

Listing insalled packages using dpkg in Linux.

How to Unpack a Package Using DPKG in Linux

If you want to unpack packages on your machine that are .deb files then you will have to use an option. Normally option (–unpack) is useful for listing out packages. Now follow the steps below to see how this works.

Steps to Follow:

 Open your Ubuntu terminal.

➋  Write the following commands and press ENTER.

sudo dpkg --unpack cowsay_3.03+dfsg2-4_all.deb

➌  Now, press the ENTER button.

➍  Now, give your user password and press ENTER button

Output:

Unpacking package using the dpkg in Linux

List the Contents of an Installed Package Using DPKG in Linux

If you want to see the contents of installed packages on your machine that are .deb files then you will have to use an option. Normally option (-c) is useful for listing the contents of an installed package. Now follow the steps below to see how this works.

Steps to Follow:

 Open your Ubuntu terminal.

➋  Write the following commands and press ENTER.

sudo dpkg -c cowsay_3.03+dfsg2-4_all.deb

➌  Now, press the ENTER button.

➍  Now, give your user password and press ENTER button.

Output:

As you can see that the list of the contents of the installed package is printed on the terminal.

Using dpkg in Linux to print contents

How to Show Information of a Package Using DPKG in Linux

If you want to see the information of installed packages on your machine that are .deb files then you will have to use an option. Normally option (-I) is used for listing information of an installed package. Now follow the steps below to see how this works.

Steps to Follow:

 Open your Ubuntu terminal.

➋  Write the following commands and press ENTER.

sudo dpkg -I cowsay_3.03+dfsg2-4_all.deb

➌  Now, press the ENTER button.

➍  Now, give your user password and press ENTER button.

Output:

As you can see that the information on the installed package is printed on the terminal. Here you can see the installation size and other pieces of information.

Showing information of files using dpkg in linux

How to Show the Location of a Package Using DPKG

If you want to see the location of installed packages on your machine that are .deb files then you will have to use an option. Normally option (-L) is used for listing the contents of an installed package. Now follow the steps below to see how this works.

Steps to Follow:

 Open your Ubuntu terminal.

➋  Write the following commands and press ENTER.

 dpkg -L cowsay

➌  Now, press the ENTER button.

Output:

As you can see that the location of the installed package is printed on the terminal.

showing location of the packages

How to Remove a Package Using DPKG

If you want to remove installed packages on your machine that are .deb files then you will have to use an option. Normally option (-r) is used for removing an installed package. Now follow the steps below to see how this works.

Steps to Follow:

 Open your Ubuntu terminal.

➋  Write the following commands and press ENTER.

sudo dpkg -r cowsay_3.03+dfsg2-4_all.deb

➌  Now, press the ENTER button.

➍  Now, give your user password and press ENTER button.

Output:

This command doesn’t remove the configuration files. For removing the configuration files you will have to use purge, which I will show you in the next section.

Removing files

How to Purge a Package Using DPKG

If you want to remove configuration files of a package on your machine that are .deb file then you will have to use an option. Normally option (-P) is used for purging an installed package. Now follow the steps below to see how this works.

Steps to Follow:

 Open your Ubuntu terminal.

➋  Write the following commands and press ENTER.

sudo dpkg -P cowsay

➌  Now, press the ENTER button.

➍  Now, give your user password and press ENTER button.

Output:

This command removes all the configuration files.

Purging file

DPKG vs APT

Apt is more modern and user-friendly than the dpkg. Apt stands for Advanced Packaging Tools on the other hand dpkg stands for Debian Package Manager. Both of these tools can be used for installing, removing, or updating software packages in the system. Apt has some advantages over dpkg like installing from a remote location. Apt can also resolve dependencies which dpkg can’t do.

Conclusion

In this article, I have tried to explain how dpkg works, some useful dpkg command lines, and the difference between dpkg and apt. I tried to make it as simple as possible, considering how hard it is to learn to use the command line for beginners. So after reading this article you should be able to use dpkg properly and without facing many difficulties.


Similar Readings

Rate this post
Rafsan Zani

Rafsan Zani

Hello, I’m Md. Rafsan Zani. I have recently completed my Undergraduate from the Bangladesh University of Engineering and Technology (BUET). Currently, I’m pursuing higher studies abroad. I’m really interested in computer science and would like to learn a lot about the wonderful world of computers. Currently, I’m working as a Linux Content Developer Executive and find Linux really interesting. I certainly would like to learn more about Linux and implement them in my future studies. Read Full Bio

We will be happy to hear your thoughts

Leave a reply

LinuxSimply
Logo