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 for Using DPKG Command in Linux

The syntax of DPKG 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.

Here’s a table summarizing some useful options associated with the DPKG command in Linux:

Option Description
dpkg -i package.deb Install a Debian package.
dpkg -r package_name Remove a previously installed package.
dpkg –purge package_name Remove a package along with its configuration files.
dpkg -l List all installed packages.
dpkg -L package_name List all files installed by a package.
dpkg -I package.deb Display detailed information about a Debian package.

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.

To Install a .deb package using DPKG in Linux, follow the steps below:

  1.  Open your Ubuntu terminal.
  2.   Write the following command.
    sudo dpkg -i cowsay_3.03+dfsg2-4_all.deb
  3.   Now, press the ENTER button.
  4.   Now, type your user password and press ENTER button. Installing using dpkg in linux

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

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.

To see installed packages using DPKG, write  dpkg -l in the terminal:Listing insalled packages using dpkg in Linux.

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

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.

To unpack a package using DPKG, follow the steps below:

  1.  Open your Ubuntu terminal.
  2.   Write the following command.
    sudo dpkg --unpack cowsay_3.03+dfsg2-4_all.deb
  3.   Now, press the ENTER button.
  4.   Now, give your user password and press ENTER button.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.

To list the contents of an installed package, follow the steps below:

  1.  Open your Ubuntu terminal.
  2.   Write the following commands.
    sudo dpkg -c cowsay_3.03+dfsg2-4_all.deb
  3.   Now, press the ENTER button.
  4.   Now, give your user password and press ENTER button. Using dpkg in Linux to print contents

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

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.

  1.  Open your Ubuntu terminal.
  2.   Write the following command.
    sudo dpkg -I cowsay_3.03+dfsg2-4_all.deb
  3.   Now, press the ENTER button.
  4.   Now, give your user password and press ENTER button.Showing information of files using dpkg in linux

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.

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) lists the contents of an installed package.

To show the location of a package, follow the steps below:

  1.  Open your Ubuntu terminal.
  2.   Write the following commands and press ENTER.
     dpkg -L cowsay

    showing location of the packages

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

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) removes an installed package. Now follow the steps below to see how this works.

  1.  Open your Ubuntu terminal.
  2.   Write the following command.
    sudo dpkg -r cowsay_3.03+dfsg2-4_all.deb
  3.   Now, press the ENTER button.
  4.   Now, give your user password and press ENTER button.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.

  1.  Open your Ubuntu terminal.
  2.   Write the following command.
    sudo dpkg -P cowsay
  3.   Now, press the ENTER button.
  4.   Now, give your user password and press ENTER button.This command removes all the configuration files.Purging file

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.

DPKG vs APT

Apt is more modern and user-friendly than the dpkg. APT stands for Advanced Package Tool 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.

Look into the article: DPKG VS APT for a detailed overview.

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.

People Also Ask

Why use dpkg?

dpkg is used in Linux for managing Debian packages. It allows installation, removal, and configuration of software packages on Debian-based systems, such as Ubuntu. While dpkg is effective for basic package management, higher-level tools like apt are often preferred for handling dependencies more efficiently.

Why is apt used?

apt in Debian-based Linux distributions simplifies package management by automating dependency resolution, providing a user-friendly interface, and managing a centralized package repository for efficient software installation, removal, and updates.

What is dpkg vs apt?

dpkg is a low-level package manager for Debian-based Linux, handling individual packages, while apt is a higher-level tool that simplifies package management by automating tasks like dependency resolution and providing a user-friendly interface. They often work together, with apt utilizing dpkg for package handling.

Why use sudo with apt?

Using sudo with apt is necessary to acquire administrative privileges, enabling the execution of commands that involve system-level operations, such as installing or updating software packages.


Similar Readings

Rate this post
LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now
icon linux
Md. 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

Leave a Comment