This tutorial introduces how to use dpkg package manager by command lines. This article is intended for beginners who just started Ubuntu. It consists of listing, installing, removing, and purging. It including some examples too. And this article is compatible with any Debian family operating system (such as Linux Mint) too. We hope this helps.

Reading Conventions


  • Any command preceeded with # is should be run as root (or using sudo), and with $ is should be run as normal user.
  • You may change <package_file_name> variable into one package file name, or more than one package file names separated by spaces, or type one `*` (asterisk) character to mean all packages inside current directory.
  • This article assumes dpkg runs in the same directory with the package/packages. 
  • Don't install package blindly e.g. don't install vivid package in trusty, only install trusty package for trusty, and don't install package from any untrusted source. This may compromise your system stability and security.

1. List Installed Packages


$ dpkg --list <package_name>
$ dpkg -l <package_name>
$ dpkg --list bash
$ dpkg --list

Output example:

master@master:~$ dpkg --list
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  account-plugin 0.12+16.04.2 all          GNOME Control Center account plug
ii  account-plugin 0.12+16.04.2 all          GNOME Control Center account plug
ii  account-plugin 0.12+16.04.2 all          GNOME Control Center account plug
ii  accountsservic 0.6.40-2ubun i386         query and manipulate user account
ii  acl            2.2.52-3     i386         Access control list utilities
...
master@master:~$

Explanation:

The --list option is used to show all of dpkg database contents sorted by package names. It shows all installed packages list, along with their statuses, versions, and descriptions information. This command can be specified for particular package by typing its name as argument like the third command. The output example shows how normal output looks like. Because an Ubuntu system usually consists of thousands of installed package, the output will be very long.

2. Install Package


# dpkg --install <package_file_name>
# dpkg -i <package_file_name>
# dpkg --install wvdial_1.61-4.1_i386.deb
# dpkg --install *

Output example:

master@master:~/Public$ sudo dpkg --install wvdial_1.61-4.1_i386.deb 
(Reading database ... 270171 files and directories currently installed.)
Preparing to unpack wvdial_1.61-4.1_i386.deb ...
Unpacking wvdial (1.61-4.1) over (1.61-4.1) ...
Setting up wvdial (1.61-4.1) ...
Processing triggers for man-db (2.7.5-1) ...
master@master:~/Public$


Explanation:

The --install option tells dpkg to install a package or some packages. The most convenient way to install package is by installing package belongs to the same directory with your console. First you should make sure your console belongs to the same directory with the package (use pwd and ls command to know), then you should type the correct name of package you want to install. Third command example and the output above show you how to do it.

3. Remove Package


# dpkg --remove <package_name>
# dpkg -r <package_name>
# dpkg --remove wvdial

Output example:

master@master:~/Public$ sudo dpkg --remove wvdial
(Reading database ... 270170 files and directories currently installed.)
Removing wvdial (1.61-4.1) ...
Processing triggers for man-db (2.7.5-1) ...
master@master:~/Public$

Explanation:

The --remove option tells dpkg to remove one or some installed packages. To remove you can do it in any directory, but you should type the package_name instead of package_file_name. That's why third command example shows wvdial name instead of wvdial_1.61-4.1_i386.deb file name.

4. Purge Package 


# dpkg --purge <package_name>
# dpkg -purge <package_name>
# dpkg --purge 

Output example:

master@master:~/Public$ sudo dpkg --purge wvdial
(Reading database ... 270170 files and directories currently installed.)
Removing wvdial (1.61-4.1) ...
Purging configuration files for wvdial (1.61-4.1) ...
Processing triggers for man-db (2.7.5-1) ...
master@master:~/Public$

Explanation:

The --purge option tells dpkg to remove one or some packages. Purge is same with remove, but purge deletes also installed configuration files of the package. Notice the difference from output example while --purge shows "Purging configuration file for wvdial" message.

Getting Help


Internal:

type command man dpkg to show dpkg manual documentation via Terminal.

External:

read dpkg manual documentation in some websites such as http://manpages.ubuntu.com/manpages/precise/en/man1/dpkg.1.html.


, , ,