We already knew how to download a package along with all of its dependencies in Ubuntu and its derivatives. Today, we will see how to download recursive dependencies of a package in Ubuntu. In other words, we are going to download the dependencies of dependencies.
Let us say you are trying to install a package named a.deb. The a.deb package depends on package b.deb and again package b.deb depends on package c.deb. In this method, we not only download the dependencies of a.deb, but also the dependencies of b.deb and c.deb. This could be useful when you can't install the package even after you downloaded all of the required dependencies using apt-rdepends command.
Downloading packages with dependencies locally serves three main purposes.
- Avoid the repetitive download of the same set of packages over and over. For example, if you want to install Vim editor on multiple systems, you can download Vim with all required dependencies, save them in a USB drive (or transfer them via LAN) and install Vim on other system.
- Save the Internet bandwidth and time.
- Install Packages on non-internet connected systems. This is the main reason for downloading packages with dependencies locally. You can download the packages in an Internet-connected system and then transfer them to the offline system via USB drive or LAN and install them in it without Internet.
The reasons could be vary for you. If you ever wanted to install packages on an offline system, this method would definitely help.
Download recursive dependencies of a package in Ubuntu
For the purpose of this guide, we will take Vim program as an example.
First, let us list recursive dependencies of the Vim package using the following command:
$ apt-cache depends --recurse --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances vim | grep "^\w" | sort -u
Replace vim with your own package. If you want to display the output in column format for easy reading, run:
$ apt-cache depends --recurse --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances vim | grep "^\w" | sort -u | column
cdebconf libacl1 libdb5.3 liblzma5:i386 libpython3.6-stdlib libtinfo5 vim debconf libacl1:i386 libdebian-installer4 libmpdec2 libreadline7 libzstd1 vim-common dpkg libattr1 libexpat1 libncursesw5 libselinux1 libzstd1:i386 vim-runtime dpkg:i386 libattr1:i386 libffi6 libnewt0.52 libselinux1:i386 mime-support xxd gcc-8-base libbz2-1.0 libgcc1 libpcre3 libslang2 perl-base xxd:i386 gcc-8-base:i386 libbz2-1.0:i386 libgcc1:i386 libpcre3:i386 libsqlite3-0 readline-common zlib1g install-info libc6 libgpm2 libpython3.6 libssl1.1 tar zlib1g:i386 install-info:i386 libc6:i386 liblzma5 libpython3.6-minimal libtextwrap1 tar:i386
These are the dependencies of dependencies of Vim program. Please note that all of these may not required to install Vim.
Let us go ahead and download recursive dependencies of the Vim package with command:
$ apt-get download $(apt-cache depends --recurse --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances vim | grep "^\w" | sort -u)
This command will download vim along with its dependency programs in the current directory. It will also download the dependencies of the Vim's dependencies.
Check all of the dependencies have been downloaded using "ls" command:
Here is the list of Vim program's dependencies and the dependencies of its dependencies in my Ubuntu 18.04 desktop:
Now move all of the downloaded files via a USB drive or LAN to the offline system. And then go to the location where you saved all downloaded packages in your offline system and install them using command:
$ sudo dpkg -i *
Alternatively, you can build the index of all downloaded packages and install them using APT package manager.
To build index of the downloaded packages, go to the location where the packages are stored and run the following command:
$ dpkg-scanpackages . | gzip -c9 > Packages.gz
Add this folder to APT source list using the following command:
$ echo "deb[trusted=yes] file:///home/sk/vim ./" | sudo tee -a /etc/apt/sources.list
Here, I have saved all the files in
/home/sk/vim folder in my offline system. You need to replace this path with your own.
Update the package index using command:
$ sudo apt-get update
Finally, install the vim package using APT package manager:
$ sudo apt-get install vim
Similarly, you can download and install other packages as well.
Hope this helps.