Installing applications via command line is quite easy in Ubuntu/Debian. All you need to do is to use apt install package_name.
But what if you want to know the dependencies of a package before or after installing it?
In this tutorial, I’ll show you various ways to see the dependencies of a package in Ubuntu and other Debian-based Linux distributions that use APT package management system.
What is package dependency in Ubuntu?
If you didn’t know already, when you install a software package in Linux, sometimes, it needs other packages to function properly. These additional packages are called dependencies. If these dependency packages are not installed on the system, it is usually installed automatically with the package.
If you don’t have these packages installed on your system, they will be automatically installed when you install HandBrake on Ubuntu.
Check dependencies of a package in Ubuntu and Debian based distributions
As it often happens in Linux, there are more than one way to achieve the same result. Let’s see various ways to see the dependencies of a package.
Checking dependencies with apt show
You can use the apt show command to display details of a package. Part of this information is dependencies and you can see it in the line starting with Depends.
For example, here’s what it shows for ubuntu-restricted-extras package.
[email protected]ss:~$ apt show ubuntu-restricted-extras Package: ubuntu-restricted-extras Version: 67 Priority: optional Section: multiverse/metapackages Origin: Ubuntu Maintainer: Ubuntu Developers <[email protected]> Bugs: https://bugs.launchpad.net/ubuntu/+filebug Installed-Size: 14.3 kB Depends: ubuntu-restricted-addons Recommends: libavcodec-extra, ttf-mscorefonts-installer, unrar Download-Size: 3,200 B APT-Manual-Installed: yes APT-Sources: http://us.archive.ubuntu.com/ubuntu focal/multiverse amd64 Packages Description: Commonly used media codecs and fonts for Ubuntu This collection of packages includes: - MP3 and other audio codec software to play various audio formats (GStreamer plugins) - software to install the Microsoft Web fonts - the Adobe Flash plugin - LAME, software to create compressed audio files. . This software does not include libdvdcss2, and will not let you play encrypted DVDs. For more information, see https://help.ubuntu.com/community/RestrictedFormats/PlayingDVDs . These software packages are from the Multiverse channel, restricted by copyright or legal issues in some countries. For more information, see http://www.ubuntu.com/ubuntu/licensing
As you can see, ubuntu-restricted-extras package depends on ubuntu-restricted-addons package.
Here’s a catch! The dependency package may also depend on some other package and the chain could go on. Thankfully, the APT package manager handles this for you by automatically installing all the dependencies (most of the time).
What is recommended package?
Use apt-cache for getting just the dependencies information
The apt show has way too many information. If you want to get the dependencies in a script, the apt-cache command gives you a better and clean output.
apt-cache depends package_name
The output looks much clean, does it not?
Check the dependencies of a DEB file using dpkg
Both apt and apt-cache command work on the packages that are available from the repositories. But if you download a DEB file, these command won’t work.
In this case, you can use the dpkg command with -I or –info option.
dpkg -I path_to_deb_file
The dependencies can be seen in the line starting with Depends.
Checking dependencies and reverse dependencies with apt-rdepends
If you want more details on the dependencies, you can use the apt-rdepends tool. This tool creates the complete dependency tree. So, you get the dependency of a package and the dependencies of the dependencies as well.
It is not a regular apt command and you’ll have to install it from the universe repository:
sudo apt install apt-rdepends
The output is usually quite large depending on the dependency tree.
Reading package lists... Done Building dependency tree Reading state information... Done shutter Depends: procps Depends: xdg-utils imagemagick Depends: imagemagick-6.q16 (>= 8:184.108.40.206+dfsg-2~) imagemagick-6.q16 Depends: hicolor-icon-theme Depends: libc6 (>= 2.4) Depends: libmagickcore-6.q16-6 (>= 8:220.127.116.11) Depends: libmagickwand-6.q16-6 (>= 8:18.104.22.168) hicolor-icon-theme libc6 Depends: libcrypt1 (>= 1:4.4.10-10ubuntu4) Depends: libgcc-s1 libcrypt1 Depends: libc6 (>= 2.25)
The apt-rdepends tool is quite versatile. It can also calculate the reverse dependencies. Which means, you can see what other packages depend on a certain package.
apt-rdepends -r package_name
The output could be pretty big because it will print the reverse dependency tree.
[email protected]:~$ apt-rdepends -r ffmpeg Reading package lists... Done Building dependency tree Reading state information... Done ffmpeg Reverse Depends: ardour-video-timeline (>= 1:5.12.0-3ubuntu4) Reverse Depends: deepin-screen-recorder (5.0.0-1build2) Reverse Depends: devede (4.15.0-2) Reverse Depends: dvd-slideshow (0.8.6.1-1) Reverse Depends: green-recorder (>= 3.2.3)
I hope this quick tutorial was helpful in improving your command line knowledge a bit. Stay tuned for more such tips.