How to Install Ubuntu Package Without Internet Connection

ifeelfree
3 min readFeb 18, 2021
No internet (image from www.shutterstock.com)

Part 1: Introduction

It may happen that sometimes we may need to install Ubuntu packages without Internet connection. Such a scenario happens to me one day when my desktop needs to compile the wireless adapter driver program using make command before it can connect with the Internet. However, the native Ubuntu 18.04 system does not contain build-essential package. So I have to find a way to install it offline. In this article, I record the way how I successfully install this Ubuntu package.

Part 2: Step-by-step Guild-line

Step 1: in a Ubuntu machine that can connect with Internet, download the docker Ubuntu system that you have installed in the machine that cannot connect with Internet. In my case, I installed Ubuntu 18.04 in the new machine, so in the machine that can connect with Internet, I use sudo dockerpull ubuntu:18.04to have a system that simulate that in my new machine.

The reason why I use docker to obtain a pure Ubuntu system is to make sure that the solution can be reproducible in the new machine.

When you have the Docker container, double-check that the Linux kernel is exactly the same with the one in the new machine. Remember that the same Ubuntu 18.04 may have difference regarding to Linux kernel versions. Use uname -rs for Linux kernel checking. Sometimes, it may be possible that the Docker Ubuntu Linux kernel is not the same kernel in the new machine, and it is fine in some cases.

Step 2: run the Docker container with shared volumes with the host machine. This can be done using the following command:

sudo docker run -it -v host_dir:container_dir ubuntu:18.04

After that, we try to find where the package we want to install as well as its dependent packages are located. This can be done using the following command:

sudo apt-get -qq --print-uris install build-essential linux-headers-$(uname -r) | cut -d\' -f 2 > urls.txt

If you already know the Linux kernel version in the new machine (in my case 5.4.0–42), you can use

sudo apt-get -qq --print-uris install build-essential linux-headers-5.4.0-42 | cut -d\' -f 2 > urls.txt

The packages that are needed for build-essential will be written to urls.txt file, which looks like:

libubsan0_7.5.0-3ubuntu1~18.04_amd64.deb
libwind0-heimdal_7.5.0+dfsg-1_amd64.deb
linux-headers-5.4.0-62-generic_5.4.0-62.70~18.04.1_amd64.deb
linux-hwe-5.4-headers-5.4.0-62_5.4.0-62.70~18.04.1_all.deb
linux-libc-dev_4.15.0-135.139_amd64.deb
make_4.1-9.1ubuntu1_amd64.deb
manpages_4.15-1_all.deb
manpages-dev_4.15-1_all.deb
netbase_5.4_all.deb
patch_2.7.6-2ubuntu1.1_amd64.deb
perl_5.26.1-6ubuntu0.5_amd64.deb
perl-modules-5.26_5.26.1-6ubuntu0.5_all.deb
pinentry-curses_1.1.0-1_amd64.deb
readline-common_7.0-3_all.deb
xz-utils_5.2.2-1.3_amd64.deb

Step 3: based on the urls.txt, download all the packages, and save them to the volume (shared folder between host machine and container). This is done by:

wget --content-disposition -i urls.txt

Step 4: move the downloaded .deb packages in a USB, and install them in the new machine via the following command:

sudo dpkg -i *.deb

In some references, people suggest use

sudo cp /shared_folder/deb/* /var/cache/apt/archives/
sudo apt-get install build-essential linux-headers-$(uname -r)

However, that does not work in my case.

Reference

--

--