Debian Linux and other Debian based Linux distributions, such as Ubuntu and Linux Mint, use dpkg as a package manager.
You might be thinking, “I thought those distributions used apt – that’s what I always use to install packages.” That’s true, apt is also a package manager, but really it’s just passing off tasks to dpkg in the background. apt and other package managers on Debian usually just utilize dpkg to install packages or perform similar tasks.
Package manager commands like those from apt or apt-get are meant for end-users. They’re easy to use and are very familiar to most Linux users. dpkg is low-level tool that is more geared towards use by the system, but we can still use it with the
In this guide, we’ll go over various
dpkg command examples to help you learn to use the tool and manage packages on your Debian or Debian based system.
In this tutorial you will learn:
- How to install .deb packages with dpkg
- How to use dpkg command through examples
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro with dpkg|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
How to use dpkg command through examples
The easiest way to learn about the dpkg command is through examples. To get started, use some of the following commands on your own system, and you’ll eventually have it mastered and be able to use it to install deb files or reconfigure packages, etc.
- The most common use for dpkg is probably to install .deb files, since apt is ordinarily used to install packages from repositories. Once you have downloaded a deb file, you can use the
-i(install) option to install it.
$ dpkg -i package-name.deb
- To see a full list of installed packages on your system, you can use the
-l(list) option. This will give you extra details like the version of the package, system architecture, and a description.
$ dpkg -l
- If you want to search for an installed package by its name, just specify your search string after the
$ dpkg -l nmap ... ||/ Name Version Architecture Description +++-==============-==================-============-================================= ii nmap 7.80+dfsg1-2build1 amd64 The Network Mapper
- You can remove a package by using the
-r(remove) option. Note that this will leave behind configuration files, but uninstall the program.
$ sudo dpkg -r package-name
- You can purge a package, which will uninstall the software and delete all of its configuration files instead of leaving them behind, by using the
$ sudo dpkg -P package-name
- To quickly check whether a package is installed or not, you can use the
$ dpkg -s nmap
- Use dpkg to examine the contents of a .deb file by appending the
$ dpkg -c package-name.deb
- You can unpack a .deb file to see and manipulate its contents by using the
$ dpkg --unpack package-name.deb
- If you make changes to the unpacked .deb files, you can repackage everything into a .deb file by using the
$ sudo dpkg --configure package-name
- If a package has already been installed and configured, you will probably have to opt for the
dpkg-reconfigurecommand if you wish to configure its settings further`.
$ sudo dpkg-reconfigure unattended-upgrades
This should be the majority of the dpkg commands that you’ll ever need to know, although even more options exist. If you’d like to delve even further, check the man page for more options.
$ man dpkg
In this guide, we saw how to use dpkg, the Debian package manager, through command line examples. We covered installing deb files, removing and purging packages, as well as listing, unpacking, and configuring deb files. Most likely, these will be all the dpkg commands you will need to familiarize yourself with. dpkg usually only needs learned after high level wrappers like apt have been mastered first.