3

Im sorry Im a newbie in Ubuntu.

While dpkg can only install, remove, or query individual packages, apt offers additional functionality, such as automatically handling dependencies, retrieving and installing packages from remote locations, and upgrading all installed packages to their latest versions. - https://www.geekbits.io/what-is-the-difference-between-apt-and-dpkg/#:~:text=While%20dpkg%20can%20only%20install,packages%20to%20their%20latest%20versions.

so why do people still use dpkg when there is apt?

aqwertya
  • 112

2 Answers2

14

dpkg is the low-level packaging tool that apt uses to handle packages.

Most "normal" user should only use apt, because it automatically handles dependencies.

Only in very special cases, where you want to install a specific package, and you don't want to automatically resolve dependencies would you use dpkg.

I imagine this would mostly be relevant for troubleshooting and research purposes.

To put it short: If you need dpkg instead of apt, you'll have the insight to know why. If you're not sure, use apt.

And yes, I know some online guides use dpkg - in my opinion, this is a mistake that only causes confusion. The reason is likely (as muru states), that it's only recently that apt got the capability to install local .deb files.

Artur Meinild
  • 31,035
3

If you are literally just installing/updating/removing packages from your system repositories, there is zero reason to ever use dpkg directly, because APT does everything dpkg does (because it actually uses dpkg internally to do it), plus all the stuff that you generally need to do when managing packages that dpkg doesn’t do.

But, APT doesn’t do everything.

The big thing historically that APT did not do was installing DEB packages directly from the package files instead of fetching them from repos (IOW, up until a few years ago you could not apt-get install /some/package/file.deb, you had to use dpkg, or possibly dselect, for that). That limitation is why a lot of older ‘How to install foo on Debian’ type guides often use dpkg instead of APT, and why things like gdebi exist. These days it’s irrelevant though, because you can just pass a package file to APT and it will do the right thing in 99.9% of cases.

The other big thing that often comes up is figuring out which package a given file belongs to or listing the files installed by a package. APT has no options for this (apt-file can technically do it, but that’s not part of APT, is a pain to parse the output of at times, and it only looks at info from the repositories, not the packages themselves, so it does not always work), but dpkg (or, more correctly dpkg-query) provides options to make such lookups.

There are a number of other things APT just doesn’t cover, but just about all of them are only of interest to developers.