Let’s discuss the dpkg command on Linux in this article. Packages help deliver or install any application on a Linux system. Essentially, packages are compressed files of the files and dependencies needed to install a program or service.
These packages are used when you want to install a new program or service on your system. All packages on a system are stored in a local “repository”.
A package management service can access this repository whenever needed. Let’s talk about one such package management utility, the dpkg command in Linux today.
What is the dpkg command?
Essentially, the man page describes it like this: “dpkg is a tool for installing, building, removing, and managing Debian packages.”
We use the dpkg command to interact with the packages in our system. It is fully controlled with the help of command line parameters and the first parameter is known as the action parameter that is used to direct what to do. This parameter may or may not be followed by any other parameter.
Later, a new tool called aptitude was designed to provide a more user-friendly interactive front-end for users to manage packages without the complexity of the dpkg command. Interacts with the dpkg interface on behalf of the user. Now, let’s try to understand the dpkg command on Linux.
The
basics
of the dpkg command in Linux
Here’s what the basic syntax of the
dpkg command looks like: dpkg [options] [package name .deb]
The dpkg command provides a long list of options for customizing the data we receive as we analyze our network. Here is a list of some of the most popular dpkg options.
Here are some of the most commonly used options for the dpkg command
and you can explore further by displaying the help options on your terminal
.
Using
the dpkg command
Let’s explore common uses of the dpkg command. As the command works the same for Debian and Ubuntu systems, we will only mention Ubuntu in this tutorial from now on.
1. Installing
a package
The most basic use of the dpkg command in Ubuntu is installing a package. We can install a deb package on Ubuntu or Debian using the dpkg -i command option.
This is how you would install a package.
sudo dpkg -i [package name]
We are installing VLC player on our Ubuntu system. Take a look at the screenshot below to see what the installation looks like on the screen.
![The dpkg Command in Linux - A Beginners Reference | DigitalOcean 1 Dpkg Command](https://journaldev.nyc3.digitaloceanspaces.com/2020/08/dpkg-command.png)
You can also install multiple packages at the same time by specifying the space-separated package names
.
2. Deleting
a package When you no longer need a program or service
on your system, it’s no use maintaining it
.
The dpkg command also has us covered here
.
We can uninstall a program or service from our system using
the dpkg -r option.
Let’s remove the VLC player we installed for this demo
. sudo dpkg -r [package name]
Look at the following screenshot to see how dpkg triggers changes for all dependent menus, desktop icons, etc. similar to the apt command.
![The dpkg Command in Linux - A Beginners Reference | DigitalOcean 2 Dpkg R Vlc](https://journaldev.nyc3.digitaloceanspaces.com/2020/08/dpkg-r-vlc.png)
3. Updating repositories
The dpkg repository stores all packages available for installation on your Ubuntu or Debian Linux distribution
.
However, as these packages are stored locally, you can often end up having old versions of packages for a program when newer versions have already been released. This causes the need for a method to update the repositories.
Guess what? The dpkg -update-avail option has you covered.
Check online repositories and download all updated packages to your local repository.
Let’s update our local repositories to the latest version:
sudo dpkg -update-avail
Final Notes
That brings us to the end of our topic of the day. This is all you would need for the most part when using the dpkg command on Linux. Most regular users would not need more than these three options for the command. However, if you are an advanced user, you can run man dpkg and get full details of everything the command can do.