Open-Source Internship opportunity by OpenGenus for programmers. Apply now.
In Linux software is considered a package and is distributed using remote repositories. As end-users, we use package managers such as dpkg to manage packages.
Table of contents.
- Introduction.
- Syntax.
- Commands.
- Summary.
- References.
Introduction.
Package management involves downloading, installing, upgrading, updating, downgrading, removing, and purging software just to name a few.
dpkg is a Linux package manager used to extract, analyze, unpack, build, install, remove .deb files.
Syntax.
When we write a dpkg command, we follow the following format:
dpkg [<option>...] <command>
Commands.
In this section, we discuss commonly used dpkg commands to manage Debian packages.
1. Installing a package.
To install a package using dpkg we use the -i option as follows:
$ sudo dpkg -i [.deb file]
In this case, we have downloaded the vscode .deb file and are now installing it using dpkg.
We can also install multiple packages by listing them as follows;
$ sudo dpkg -i [.deb file 1, .deb file 2, .deb file 3...]
Now, to make sure the package was installed, we confirm a successful installation as follows:
$ dpkg -s [package name]
2. Unpacking a package.
Instead of installing and configuring a package, we may just want to unpack its contents. For this we write:
$ sudo dpkg --unpack [package name]
Now to configure the package we use the --configure option as follows:
sudo dpkg --configre [package name]
Assuming the package was installed and configured successfully and we wish to configure its settings further we write:
$ sudo dpkg-reconfigure [package name]
3. Listing packages.
To see the packages installed on our system we use the -l option:
$ dpkg -l
From the output list, we have four columns. The first specifies the name of the package, the second specifies the version number, then we have the architecture on which the package runs, all means that it can run on any processor architecture and finally we have a description of the package in the last column.
We can also use the same command to search for a package as follows:
$ dpkg -l [package name]
4. List package contents.
We can list the contents of a package using the -c option as follows:
$ dpkg -c [package name]
5. Removing a package.
To remove a package using dpkg we use the -r option:
$ sudo dpkg -r [package name]
The above command removes the package but keeps its configuration file. To remove everything we use the -P option for purge: This removes everything including the package's configuration files.
sudo dpkg -P [package name]
6. Updating repositories.
A repository is a storage location where a Linux system fetches and updates software packages. To update repositories using dpkg we write:
$ sudo dpkg --update-avail
For additional functionality we can use the following commands for more options and dpkg's manual page:
$ dpkg --help
$ man dpkg
Summary.
dpkg is a Debian-based package management utility. We use it to install configure, list, update, remove, and everything involving the management of software in Debian distributions.
apt is also a package manager in Linux Debian-based distros, it uses dpkg to install packages. However as you have noticed, we had to have downloaded the .deb file for dpkg to work. With apt, everything is handled for us, it fetches the package from the remote repo and installs it.
For more on apt check out the article in the references section below.