dpkg commands in Linux with Examples

dpkg commands for Debian Based Distros

In this article we will discuss about “ dpkg commands” for Debian Based Distros. We will describe each of these briefly, before focusing on ' dpkg' command.

APT Command
Advanced Package Tool(APT) works directly without using ' deb' packages. It works with ‘ deb‘ archive from the location specified in the “ /etc/apt/sources.list” file.

Aptitude
It' s a text based package manager for Debian. It enables user to manage packages easily.

Synaptic
It is a graphical package manager, even a newbies can install, upgrade and uninstall packages easily.

Tasksel
It enables user to install all the required packages for a specific task.

Deselect
A menu-driven package management tool. It is initially used during the first time of installation and now is replaced with aptitude.

Dpkg-deb
It Interacts with the Debian archive.

Dpkg-split
splitting and merging larger file into small files to store on a smaller size storage medium like floppy-disk.

Dpkg Command

dpkg is the main package management program to install, build, remove, and manage packages in Debian and Debian based System.

To Install a Package

To install a " deb" package, use the dpkg command with “ -i” option.

root@linuxhelp:~# dpkg -i teamviewer_11.0.57095_i386.deb 
Selecting previously unselected package teamviewer:i386.
(Reading database ... 204404 files and directories currently installed.)
Preparing to unpack teamviewer_11.0.57095_i386.deb ...
Unpacking teamviewer:i386 (11.0.57095) ...
Setting up teamviewer:i386 (11.0.57095) ...

List the installed Packages

To view and list the packages use the “ -l” option along with the command.

root@linuxhelp:~# dpkg -l
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-=============================-===================-===================-===============================================================
ii a11y-profile-manager-indicato 0.1.10-0ubuntu3 amd64 Accessibility Profile Manager - Unity desktop indicator
ii account-plugin-facebook 0.12+16.04.20160126 all GNOME Control Center account plugin for single signon - faceboo
ii account-plugin-flickr 0.12+16.04.20160126 all GNOME Control Center account plugin for single signon - flickr
ii account-plugin-google 0.12+16.04.20160126 all GNOME Control Center account plugin for single signon
ii accountsservice 0.6.40-2ubuntu11.1 amd64 query and manipulate user account information
.
.
.
ii zenity 3.18.1.1-1ubuntu2 amd64 Display graphical dialog boxes from shell scripts
ii zenity-common 3.18.1.1-1ubuntu2 all Display graphical dialog boxes from shell scripts (common files
ii zip 3.0-11 amd64 Archiver for .zip files
ii zlib1g:amd64 1:1.2.8.dfsg-2ubunt amd64 compression library - runtime
ii zlib1g:i386 1:1.2.8.dfsg-2ubunt i386 compression library - runtime

You can also use the “ -l” option along with package-name.

root@linuxhelp:~# dpkg -l teamviewer
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-=============================-===================-===================-===============================================================
rc teamviewer:i386 11.0.57095 i386 TeamViewer (Remote Control Application)

To remove a Package

“ -r” option is used to remove/uninstall a package.

root@linuxhelp:~# dpkg -r teamviewer
(Reading database ... 204689 files and directories currently installed.)
Removing teamviewer:i386 (11.0.57095) ...
Removed symlink /etc/systemd/system/multi-user.target.wants/teamviewerd.service.
Clearing assignments ...
done

Use ‘ p‘ option instead of ‘ r’ to remove the package along with configuration file.

dpkg -P teamviewer
(Reading database ... 230988 files and directories currently installed.)
Removing teamviewer:i386 (11.0.57095) ...
Removed symlink /etc/systemd/system/multi-user.target.wants/teamviewerd.service.
Clearing assignments ...
done

To View the Content of a Package

Use the “ -c” option to display the contents of “ .deb” package in a long-list format.

root@linuxhelp:~# dpkg -c teamviewer_11.0.57095_i386.deb
drwxr-xr-x root/root 0 2016-03-22 14:12 ./
drwxr-xr-x root/root 0 2016-03-22 14:12 ./opt/
drwxr-xr-x root/root 0 2016-03-22 14:12 ./opt/teamviewer/
drwxr-xr-x root/root 0 2016-03-22 14:12 ./opt/teamviewer/doc/
-rw-r--r-- root/root 25805 2016-03-22 14:12 ./opt/teamviewer/doc/CopyRights_EN.txt
-rw-r--r-- root/root 1003 2016-03-22 14:12 ./opt/teamviewer/doc/Lizenz.txt
-rw-r--r-- root/root 812 2016-03-22 14:12 ./opt/teamviewer/doc/License.txt
.
.
.
lrwxrwxrwx root/root 0 2016-03-22 14:12 ./opt/teamviewer/logfiles ->  /var/log/teamviewer11
lrwxrwxrwx root/root 0 2016-03-22 14:12 ./opt/teamviewer/tv_bin/TeamViewer ->  script/teamviewer
lrwxrwxrwx root/root 0 2016-03-22 14:12 ./opt/teamviewer/tv_bin/wine/lib/libwine.so.1 ->  libwine.so.1.0
lrwxrwxrwx root/root 0 2016-03-22 14:12 ./opt/teamviewer/tv_bin/wine/lib/libwine.so ->  libwine.so.1.0
lrwxrwxrwx root/root 0 2016-03-22 14:12 ./usr/bin/teamviewer ->  /opt/teamviewer/tv_bin/script/teamviewer

To check a Package is installed or not

Use “ -s” option with package name to check whether a deb package installed or not.

root@linuxhelp:~# dpkg -s teamviewer
Package: teamviewer
Status: install ok installed
Priority: optional
Section: non-free/internet
Installed-Size: 189688
Maintainer: Teamviewer GmbH < service@teamviewer.com> 
Architecture: i386
Version: 11.0.57095
Replaces: teamviewer5, teamviewer6, teamviewer7, teamviewer8, teamviewer9
Depends: libc6 (> = 2.4), libgcc1, libasound2, libdbus-1-3, libexpat1, libfontconfig1, libfreetype6, libjpeg62, libpng12-0, libsm6, libxdamage1, libxext6, libxfixes3, libxinerama1, libxrandr2, libxrender1, libxtst6, zlib1g
Recommends: ttf-liberation | fonts-liberation
Conflicts: teamviewer5, teamviewer6, teamviewer7, teamviewer8, teamviewer9
Description: TeamViewer (Remote Control Application)
TeamViewer is a remote control application. TeamViewer provides easy, fast and secure remote access to Linux, Windows PCs, and Macs.
.
TeamViewer is free for personal use. You can use TeamViewer completely free of charge to access your private computers or to help your friends with their computer problems.
.
To buy a license for commercial use, please visit http://www.teamviewer.com

To check the location of Packages installed

Run dpkg command along with ' L' option to know the location of the installed packages.

root@linuxhelp:~# dpkg -L apacheds
/.
/etc
/etc/init.d
/etc/init.d/apacheds-2.0.0-M21-default
/opt
/opt/apacheds-2.0.0-M21
/opt/apacheds-2.0.0-M21/bin
/opt/apacheds-2.0.0-M21/bin/apacheds
/opt/apacheds-2.0.0-M21/bin/wrapper
/opt/apacheds-2.0.0-M21/conf

To Install all Packages from a Directory

Use dpkg command along with the “ -R” and “ &ndash install” options, to install all packages from a directory.

root@linuxhelp:~# ls /deb
apacheds-2.0.0-M21-amd64.deb webmin_1.801_all.deb
root@linuxhelp:~# dpkg -R --install /deb
Selecting previously unselected package webmin.
(Reading database ... 204690 files and directories currently installed.)
Preparing to unpack /deb/webmin_1.801_all.deb ...
Unpacking webmin (1.801) ...
Selecting previously unselected package apacheds.
Preparing to unpack .../apacheds-2.0.0-M21-amd64.deb ...
Unpacking apacheds (2.0.0-M21) ...
Setting up webmin (1.801) ...
Webmin install complete. You can now login to https://linuxhelp:10000/
as root with your root password, or as any user who can use sudo
to run commands as root.
Setting up apacheds (2.0.0-M21) ...
Processing triggers for systemd (229-4ubuntu6) ...
Processing triggers for ureadahead (0.100.0-19) ...

To Unpack a Package

Using “ &ndash unpack” will simply unpack the package and it will not install or configure.

root@linuxhelp:~# dpkg --unpack teamviewer_11.0.57095_i386.deb
(Reading database ... 230989 files and directories currently installed.)
Preparing to unpack teamviewer_11.0.57095_i386.deb ...
Removed symlink /etc/systemd/system/multi-user.target.wants/teamviewerd.service.
Unpacking teamviewer:i386 (11.0.57095) over (11.0.57095) ...

To Reconfigure a Unpacked Package

Option “ --configure” will reconfigure the already unpacked package.

root@linuxhelp:~# dpkg --configure teamviewer
Setting up teamviewer:i386 (11.0.57095) ...

To print the Architecture, run the below command.

root@linuxhelp:~# dpkg --print-architecture
amd64

To Forget Uninstalled and Unavailable Packages

The dpkg command with option “ --forget-old-unavail” option will automatically forget the uninstalled and unavailable packages

root@linuxhelp:~# dpkg --forget-old-unavail
dpkg: warning: obsolete ' --forget-old-unavail'  option  unavailable packages are automatically cleaned up
root@linuxhelp:~# dpkg --version
Debian ' dpkg'  package management program version 1.18.4 (amd64).
This is free software  see the GNU General Public License version 2 or
later for copying conditions. There is NO warranty.
Use “ --help”  option to get a list of available options in dpkg command.

root@linuxhelp:~# dpkg --help
Usage: dpkg [...]

Commands:
-i|--install ... | -R|--recursive ...
--unpack ... | -R|--recursive ...
-A|--record-avail ... | -R|--recursive ...
--configure ... | -a|--pending
--triggers-only ... | -a|--pending
-r|--remove ... | -a|--pending
-P|--purge ... | -a|--pending
-V|--verify ... Verify the integrity of package(s).
--get-selections [ ...] Get list of selections to stdout.
--set-selections Set package selections from stdin.
Tag : Dpkg
FAQ
Q
Does dpkg command works on linuxmint?
A
Yes dpkg command works on linuxmint as it is also debian based distro
Q
What is the Purpose of using the Dpkg command ?
A
Dpkg is responsible for package management in Debian based systems. It is a tool used for the process of installation, removal, building, and management of packages.
Q
Is it possible to execute the Dpkg command on Redhat based distro?
A
No, Dpkg command can be executed only Debian based distros.
Q
Dpkg command has trouble to install dependencies for particular packages. is there any alternative command?
A
Instead of Dpkg Use "gdebi" command to install Debian packages to install the package along with dependencies.
Q
How to status the status of the package using the Dpkg command?
A
Check the status of Dpkg command by executing the following command "dpkg -s 'package name' "