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

The configuration file of dpkg will 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 example about dpkg.

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

Check if the dpkg package is installed or not

To check whether a package is installed or not by using option “-l”.

# 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

See whether a deb package is 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 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 by 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. In case if any package has 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 using 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.

# sudo dpkg --yet-to-unpack

Performing a Dry Run

Perform an 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.

# 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. In our next article let’s go through any other article related to Linux setup till then subscribe to our newsletter and keep you updated.

Babin Lonston
Overall 13+ Years of experience in IT field, 7+ years of experience in Linux administration with Virtualization & Cloud technologies. Love documentation and being Numismatics for a long time.

You account are not allowed to access to crontab because of pam configuration.

Previous article

Splunk forwarder installation using Ansible

Next article

You may also like

Comments

Leave a reply

Your email address will not be published.

More in Ubuntu Linux