If you use Ubuntu or any other Debian-based Linux distro, you've no doubt read installation instructions telling you to use the APT command, while others have told you to use dpkg.
So does it matter if you install packages on your Linux system with any of those package managers? What's the difference? Today we'll tackle those questions so that you know how to best install packages on Ubuntu.
APT vs dpkg: Two Important Package Installers
APT and dpkg are both command-line package management interfaces you can use in the terminal on Ubuntu and other Debian-based systems. They can, among other things, install DEB files and list installed packages.
But you might be wondering if they're so similar, why do you need both APT and dpkg?
The two interfaces in fact work together, with APT acting like a complete package management tool through the use of dpkg.
Confused? Let's break down the key differences.
APT Uses dpkg to Install Packages
When APT (or its cousin, Apt-get) installs a package, it's actually using dpkg on the back-end to accomplish that. In that way, dpkg acts more as an "under the hood" tool for APT's more user-friendly interface.
APT Can Download Packages
With APT, you can retrieve a file from a remote repository and install it, all in one command. This saves you from the work of manually finding and downloading the package before installation.
With dpkg, you can only install local files you've already downloaded yourself. It can't search remote repositories or pull packages from them.
Dpkg Won't Install Dependencies
When you install a package with dpkg, that's all that will happen: the system will simply install the package. Some packages, however, need additional software called dependencies in order to operate. If this is the case, dpkg might warn you with an error message.
APT, however, will automatically check for and get relevant dependencies to make sure whatever you're trying to install functions correctly. That's why we recommend that, after installing a package with dpkg, you still use APT's special command for restoring dependencies.
sudo apt install -f
Dpkg Indexes Local Packages Only
If you're trying to find out about the packages installed on your system, the --list function in dpkg might serve you better than APT. That's because, in the same way it can't find and download remote packages, dpkg also can't list any packages that aren't local to the device.
dpkg --list
APT's list command will list every package it knows about, local or otherwise.
apt list
To see only the installed packages, you must pass the --installed or -i option.
apt list --installed
Dpkg vs. Apt: Which One’s Better for You?
If you want to install local packages with dpkg, you can do so without facing any issues. However, you're better off with APT or Apt-get if you regularly search for packages on remote software repositories.
APT will do the work of finding and downloading the package you want, and it'll make sure all the necessary dependencies are met. You can still use dpkg, but APT is going to perform the same function while ensuring your software works the way you need it to. Additionally, APT is ideal for properly uninstalling packages and removing them from your system.