15 dpkg commands to Manage Debian based Linux Servers

Introduction

dpkg is the package manager for Debian based Linux servers. We can manage and install the package in Ubuntu/Debian Linux server by using dpkg commands, Below dpkg commands with options apply for Ubuntu Linux version 12.0 and above.

The configuration file of dpkg will be reside under /etc/dpkg/dpkg.cfg and the log will be saved under /var/log/dpkg.log.

Interested in reading about Yum commands?

Let’s go through one by one with an example of dpkg commands.

List all installed dpkg packages in Debian Servers

Here “less” is a simple text reader used to scroll through the list of packages in a new buffer that opens in the existing terminal window. The list will not be mixed with other terminal commands and output. Hit ‘q’ to return to the terminal prompt. See “man less” for more info.

# sudo dpkg -l | less

Verify the installed dpkg package

Confirm whether a package is already installed by running dpkg command with “-l” option.

# sudo dpkg -l {package_name}
# sudo dpkg -l skype

Search for a package and do a grep to find the required package.

# sudo dpkg -l | grep {keywords}
# sudo dpkg -l | grep ruby

Display information about a deb package

Here -I stands for information, To get information about a specific package.

# dpkg -I {package_name}
# dpkg -I skypeforlinux-64.deb

Check for a package whether it’s installed or not

Show the location where the package is installed. The “-S” (capital S) stands for “search”

# sudo dpkg -S {package_name}
# sudo dpkg -S ruby

Check whether it is installed and get more information about the package. The status “installed” is the package which correctly unpacked and configured.

# sudo dpkg-query -s ruby

Install a *.deb package from a specified location

To install a downloaded .deb extension package use option “-i”. Or install all packages recursively from a directory.

# sudo dpkg -R --install {package_location}
# sudo dpkg -i skypeforlinux-64.deb
# sudo dpkg -i -R /root/dpkg_downloads

Reconfigure an already installed package

To dpkg-reconfigure command will reconfigure already installed package in the system

# sudo dpkg-reconfigure skypeforlinux-64.deb
# sudo dpkg-reconfigure -R /root/dpkg_downloads

Remove a package and its configuration files

To remove any one of installed package use “-r” or we can use the capital “-P” to purge the same.

# sudo dpkg -r skypeforlinux-64.deb
# sudo dpkg -P skypeforlinux-64.deb

Locating an Installed package

Print the location of installed files of a specific package.

# sudo dpkg -L skypeforlinux-64.deb

To view the content of a package

Print all the content of a .deb package using “-c”, Use -c (lowercase c) to show the content.

# sudo dpkg -c {package_name}
# sudo dpkg -c skypeforlinux-64.deb

Extract the *.deb package file

To extract the files contained by a .deb package use -x (lowercase x).

# dpkg -x {package_name} {location_were_to_extract}
# dpkg -x skypeforlinux-64.deb /home/linuxsysadmins/

Extract and display the filenames contained in a package

The .deb package can be extracted and display the filenames contained by a package using a -X (uppercase X).

# dpkg -X {package_name} {location_were_to_extract}
# dpkg -X skypeforlinux-64.deb /home/linuxsysadmins/

Sanity and Consistency Checks for all Packages

Check for any issue with installed packages by running an audit. Because In case, if any package has an issue like dependencies or version compatibility it will report the same.

# sudo dpkg --audit

Unpacking a .deb Package

Unpacking a package without configuring it. In your requirement to unpack a whole bunch of package under any directory use recursive option “-R”.

# sudo dpkg --unpack skypeforlinux-64.deb
# sudo dpkg --unpack -R /root/dpkg_downloads

To check for selected but not installed packages

Searches for packages selected for installation but which for some reason not yet got installed. So run the option –yet-to-unpack to print those packages.

# sudo dpkg --yet-to-unpack

Performing a Dry Run with DPKG command

Perform installation with “–dry-run” to show what will happen if we use “-i”. This can be replaced with any command to see the output without making any changes to the server. Because verifying is a good and best practice before installing with any packages.

# sudo dpkg --dry-run -i skypeforlinux-64.deb

That’s it. we will update the article frequently with more command usage.

If you are using Yum it’s better to have a read.

Conclusion

To manage a Debian based package in Ubuntu/Debian Linux we can use dpkg command. Alternatively in RedHat based operating system, we can use yum or DNF commands. Subscribe to our newsletter and stay closed for more Linux related articles.