Download Packages with dependencies locally in Ubuntu

Download Packages with dependencies locally in Ubuntu

A while ago, we have published an article that described how to Install Softwares offline in Ubuntu. That tutorial explained how can we download packages in an Internet-enabled system, and install them offline in another system that has slow or no Internet connection. In this tutorial, we will see how to download a .DEB package along with all required dependencies. Using this method, we can download download packages from one system and install them later in another system that has no Internet connection. Also, we can download packages of different architectures. For example, you can download the 32 bit packages from a 64 bit systems and vice versa. Let us get started. For the purpose of this tutorial, I will be using Ubuntu 16.04 LTS desktop.

List dependencies of a package

To display list of all dependencies of a package, for example python, run:

sudo apt-cache depends python

Sample output:

python
PreDepends: python-minimal
Depends: python2.7
Depends: libpython-stdlib
Conflicts: <python-central>
Breaks: update-manager-core
Suggests: python-doc
Suggests: python-tk
Replaces: python-dev

Download packages with dependencies locally in Ubuntu

Let us download python package with its dependencies to our local disk

To do so, first create a directory to save the packages.

mkdir python

Go to the directory:

cd python

And then run:

for i in $(apt-cache depends python | grep -E 'Depends|Recommends|Suggests' | cut -d ':' -f 2,3 | sed -e s/'<'/''/ -e s/'>'/''/); do sudo apt-get download $i 2>>errors.txt; done

The above command will download python along with all dependencies and saves them. This command will save any errors in the errors.txt file.

Let us view the downloaded files using ‘ls’ command:

ls

Sample output:

errors.txt
libpython-stdlib_2.7.11-1_amd64.deb
python2.7_2.7.11-7ubuntu1_amd64.deb
python-doc_2.7.11-1_all.deb
python-minimal_2.7.11-1_amd64.deb
python-tk_2.7.11-2_amd64.deb

Download packages locally in Ubuntu

As you see in the above output, python package with all its dependencies has been downloaded.

Just copy them to your USB drive and install the python packages on any offline system as shown below.

Mount the USB drive, go to the location where you have mounted the drive, and run the following command to install Python.

sudo dpkg -i *

Suggested Read : How To Download A RPM Package With All Dependencies In CentOS


Download packages with dependencies locally for a specific architecture

You might notice that the above command has downloaded the 64 bit packages. It is because I am downloading them from 64 bit Ubuntu system. What if you want to download packages for 32 bit arch systems? It’s also possible.

First, enable the architecture you want in your Ubuntu system using command:

sudo dpkg --add-architecture i386

If you don’t add the architecture, you will get the following error message when try to download the packages.

E: No packages found

After enabling the Architecture of your choice, run the following command to download specific architecture related packages.

for i in $(apt-cache depends python:i386 | grep -E 'Depends|Recommends|Suggests' | cut -d ':' -f 2,3 | sed -e s/'<'/''/ -e s/'>'/''/); do sudo apt-get download $i 2>>errors.txt; done

As you see in the above output, I have added the architecture ‘i386’ with ‘apt-cache’ command.

Sample output:

Get:1 http://in.archive.ubuntu.com/ubuntu xenial/main i386 python-minimal i386 2.7.11-1 [28.2 kB]
Fetched 28.2 kB in 1s (25.8 kB/s) 
Get:1 http://in.archive.ubuntu.com/ubuntu xenial/main i386 python2.7 i386 2.7.11-7ubuntu1 [220 kB]
Fetched 220 kB in 1s (116 kB/s) 
Get:1 http://in.archive.ubuntu.com/ubuntu xenial/main i386 libpython-stdlib i386 2.7.11-1 [7,664 B]
Fetched 7,664 B in 0s (13.3 kB/s) 
Get:1 http://in.archive.ubuntu.com/ubuntu xenial/main i386 python-tk i386 2.7.11-2 [28.0 kB]
Fetched 28.0 kB in 1s (24.8 kB/s)
Download packages locally 

Let us check the downloaded packages.

ls

Sample output:

errors.txt
libpython-stdlib_2.7.11-1_i386.deb
python2.7_2.7.11-7ubuntu1_i386.deb
python-minimal_2.7.11-1_i386.deb
python-tk_2.7.11-2_i386.deb

That’s for all now.

You know now how to download packages with dependencies in Ubuntu systems. This method is same for Debian, Linux Mint, and other Ubuntu derivatives. Hope this helps. I will be here again with an Interesting article. Until then, stay tuned with OSTechNix.

Cheers!

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You may also like...