1. Overview

Sometimes, we may need to install the dependencies of a package without installing the package itself. For example, we may want to compile the source code of a software and generate the binaries instead of installing the package of the software. We must have the dependencies of the software installed beforehand in this case.

In this tutorial, we’ll discuss how to install the dependencies of a package without installing the package itself. We’ll install the dependencies of the iperf3 package as an example. This package provides a tool for testing the performance of a network using protocols like TCP or UDP.

Firstly, we’ll install the packages that iperf3 is dependent on in CentOS 8 using dnf. Then, we’ll see how to install the packages that iperf3 depends on in Debian 11 using apt.

2. Using dnf

We’ll install the dependencies of iperf3 in Centos 8 in this section. Although we use the dnf command in the examples, we can also use the yum command instead of dnf.

2.1. Checking the Installation of iperf3

Let’s first confirm that iperf3 isn’t installed:

$ dnf list installed iperf3*x86_64*
Error: No matching Packages to list

The dnf list installed command lists all the installed packages. We provide iperf3*x86_64* as an argument to list all the installed x86_64 packages that begin with iperf3. As can be seen from the output, there aren’t any x86_64 packages installed starting with iperf3.

Now, let’s check whether iperf3 is available in the enabled repositories:

$ dnf list available iperf3*x86_64*
Last metadata expiration check: 0:08:15 ago on Sun 22 Oct 2023 07:58:12 AM +03.
Available Packages
iperf3.x86_64                                                 3.5-8.el8                                                  appstream

The dnf list available command lists all the available packages that haven’t been installed yet. The iperf3*x86_64* argument filters the output of dnf list available, so only the x86_64 packages whose names start with iperf3 are listed. The iperf3.x86_64 package with version *3.*5 and release 8 is available according to the output.

2.2. Getting the Dependencies

Let’s check the dependencies of iperf3.x86_64:

$ dnf deplist iperf3-3.5-8.el8.x86_64
Last metadata expiration check: 0:09:21 ago on Sun 22 Oct 2023 07:58:12 AM +03.
package: iperf3-3.5-8.el8.x86_64
  dependency: /sbin/ldconfig
   provider: glibc-2.28-236.el8.7.i686
   provider: glibc-2.28-236.el8.7.x86_64
  dependency: libc.so.6(GLIBC_2.15)(64bit)
   provider: glibc-2.28-236.el8.7.x86_64
  dependency: libcrypto.so.1.1()(64bit)
   provider: openssl-libs-1:1.1.1k-9.el8.x86_64
  dependency: libcrypto.so.1.1(OPENSSL_1_1_0)(64bit)
   provider: openssl-libs-1:1.1.1k-9.el8.x86_64
  dependency: libm.so.6()(64bit)
   provider: glibc-2.28-236.el8.7.x86_64
  dependency: libsctp.so.1()(64bit)
   provider: lksctp-tools-1.0.18-3.el8.x86_64
  dependency: libsctp.so.1(VERS_1)(64bit)
   provider: lksctp-tools-1.0.18-3.el8.x86_64
  dependency: libssl.so.1.1()(64bit)
   provider: openssl-libs-1:1.1.1k-9.el8.x86_64
  dependency: rtld(GNU_HASH)
   provider: glibc-2.28-236.el8.7.i686
   provider: glibc-2.28-236.el8.7.x86_64

The dnf deplist command lists all direct dependencies and what packages provide those dependencies for the given package. Therefore, we must filter the previous output to obtain the packages that provide the dependencies:

$ dnf deplist iperf3-3.5-8.el8.x86_64 | grep provider | sort -u
Last metadata expiration check: 0:10:06 ago on Sun 22 Oct 2023 07:58:12 AM +03.
   provider: glibc-2.28-236.el8.7.i686
   provider: glibc-2.28-236.el8.7.x86_64
   provider: lksctp-tools-1.0.18-3.el8.x86_64
   provider: openssl-libs-1:1.1.1k-9.el8.x86_64

We use the grep provider command to obtain the list of providers. However, some of the providers in the list exist more than once. Therefore, we use the sort -u command to list a provider only once.

We can further filter the output to eliminate the provider: part in the last output using the awk command:

$ dep_list=$(dnf deplist iperf3-3.5-8.el8.x86_64 | grep provider | sort -u | awk '{print $2}')
Last metadata expiration check: 0:11:16 ago on Sun 22 Oct 2023 07:58:12 AM +03.
$ echo $dep_list
glibc-2.28-236.el8.7.i686 glibc-2.28-236.el8.7.x86_64 lksctp-tools-1.0.18-3.el8.x86_64 openssl-libs-1:1.1.1k-9.el8.x86_64

We have only the list of providers now. Additionally, we assign the list to the shell variable dep_list using command substitution.

2.3. Installing the Dependencies

It’s time to install each dependency using a for loop:

for package in $dep_list
do
    echo "Installing package $package"
    sudo dnf -y install $package >& /dev/null
done

We give information about the package we install using echo “Installing package $package”. We install each package in dep_list using sudo dnf -y install. The -y option of dnf automatically answers yes to all questions asked during installation. We redirect the output of the dnf install command to /dev/null since the output is long.

Installation of a package using dnf install needs root privileges, so we use the sudo command.

Let’s install the packages using a for loop:

$ for package in $dep_list; do echo "Installing package $package"; sudo dnf -y install $package >& /dev/null; done
Installing package glibc-2.28-236.el8.7.i686
Installing package glibc-2.28-236.el8.7.x86_64
Installing package lksctp-tools-1.0.18-3.el8.x86_64
Installing package openssl-libs-1:1.1.1k-9.el8.x86_64

We’ll check the installation of the packages using dnf list installed in another for loop:

$ for package in $dep_list; do dnf list installed $package; done
Installed Packages
glibc.i686                        2.28-236.el8.7                         @baseos
Installed Packages
glibc.x86_64                       2.28-236.el8.7                        @baseos
Installed Packages
lksctp-tools.x86_64                     1.0.18-3.el8                     @baseos
Installed Packages
openssl-libs.x86_64                    1:1.1.1k-9.el8                    @baseos

Therefore, we’re successful in installing all the dependencies of iperf3.x86_64.

3. Using apt

We’ll install the dependencies of iperf3 in Debian 11 in this section.

3.1. Checking the Installation of iperf3

Let’s first check the installation of iperf3:

$ apt -qq list iperf3
iperf3/oldstable-security 3.9-1+deb11u1 amd64

The iperf3 package exists, but it isn’t installed. Otherwise, the output of the apt -qq list iperf3 command would specify that it’s installed. The -qq option of apt produces a cleaner output.

3.2. Getting the Dependencies

Now, let’s check the dependencies of iperf3 using apt-cache depends:

$ apt-cache depends iperf3
iperf3
  Depends: libc6
  Depends: libiperf0

The apt-cache depends command lists the dependencies of a package. The iperf3 package in Debian depends on the packages libc6 and libiperf0. Let’s filter the output of apt-cache depends iperf3 using the grep and awk commands to obtain the dependent packages:

$ dep_list=$(apt-cache depends iperf3 | grep "Depends:" | awk '{print $2}')
$ echo $dep_list
libc6 libiperf0

The dep_list shell variable contains the packages that iperf3 depends on.

3.3. Installing the Dependencies

We can now install the packages in dep_list using a for loop as before:

$ for package in $dep_list; do echo "Installing package $package"; sudo apt-get -y install $package >& /dev/null; done
Installing package libc6
Installing package libiperf0

We use the apt-get -y install $package >& /dev/null command to install each package iperf3 depends on. The -y option of apt-get automatically answers yes to all questions for a non-interactive installation.

Installation of a package using apt-get install needs root privileges, so we use the sudo command.

Let’s check the installation of the packages:

$ for package in $dep_list; do apt -qq list $package; done
libc6/oldstable-security,now 2.31-13+deb11u7 amd64 [installed]
libiperf0/oldstable-security,now 3.9-1+deb11u1 amd64 [installed]

As can be seen from the output, we’re successful in installing both packages that iperf3 depends on.

4. Conclusion

In this article, we discussed how to install the dependencies of a package without installing the package itself. We used iperf3 in our examples.

Firstly, we saw how to install the packages iperf3 depends on without installing iperf3 in Centos 8. We used the dnf deplist command for obtaining the dependencies and the dnf install command for installing the packages.

Then, we learned how to install the packages iperf3 depends on without installing iperf3 in Debian 11. We used the apt-cache depends command for obtaining the dependencies and the apt-get install command for installing the packages.