Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Apt Offline on Ubuntu 18.04 (how to use and install)

1. Apt-Offline

This tutorial aims to install a package on a Ubuntu machine that is not able to connect into the internet, using apt-offline tool. This should be applicable to other Debian distros but it was not validated.

1.1. Table of Contents

1.2. Pre-requisites

  • The offline machine must be accessible by SSH or physically.
  • Another Ubuntu machine with the same major release that can access the internet, labelled as online machine from now on.

1.3. Installing the tool

Unfortunatelly the apt-offline is not a standart tool of Ubuntu, at least not yet. So the installation on the offline machine will be done by download and transfering .deb installation files. All links are related with bionic release so do not forget to change for the correct version of your distro.

On the online machine it can be installed in a single step:

apt install apt-offline

Now you need to download the .deb files. Is possible to download through terminal using the wget command before the url.

Then, transfer the .deb files to the offline machine. Next:

  • Install the python3-magic:
dpkg -i python3-magic_0.4.15-1_all.deb
  • Install the apt-offline:
dpkg -i apt-offline_1.8.1_all.deb

After these steps the apt-offline command should be available on the terminal.

1.4. Updating the system

Notice that the commands might need root permission (sudo). Execute on the offline machine:

apt-offline set --update ~/apt-offline.sig

It will generate the .sig file containning all the information necessary for apt. Transfer the apt-offline.sig to the online machine home folder, then run on the online machine:

apt-offline get ~/apt-offline.sig --bundle ~/

All the data to install on the offline machine is inside the generated file, so transfer it back to the offline home folder and run on the offline machine:

apt-offline install ~/

The offline machine finally has its repositories updated. 👏🎉

1.5. Installing a package

As an example, the nginx installation process will be detailed.

On the offline machine, generate the .sig file that contains the installation request information:

apt-offline set ~/nginx-info.sig --install-packages nginx

Transfer the nginx-info.sig to the online machine home folder. On the online machine, generate the compressed installation package file, based on the .sig file:

apt-offline get ~/nginx-info.sig --bundle ~/

Transfer the .zip file to the offline machine and update the dependencies locally:

apt-offline install ~/

It is wierd but is necessary to use the apt install after apt-offline install to properly install the package, the apt-offline updates the repository and keep locally everything necessary to install the package. So, at long last, install it:

apt install nginx

Hopefully, the package is now installed and working fine! 👏🎉

1.6. Transfering files

Two options will be listed to send files between the online and offline machines, through SSH: STFP client and SCP.

1.6.1. SFTP

It mean SSH File Transfer Protocol. There are many programs that use SFTP. The MobaXTerm and FileZilla are good options for Windows. Both have a good interface and will provide a way to upload and download files from the offline and online machine.

1.6.2. SCP

In short, is a network version of linux cp command. To see all the options use the man scp command under the terminal. Examples of SCP command being inside of origin machine:

# Copy a single file to destination
scp originPath/file user@machineIP:destPath/file

# Copy entire folder to destination
scp -r originPath user@machineIP:destPath

# Copy all zip files to destination
scp -r originPath/*.zip user@machineIP:destPath

1.7. References

1.8. Changellog

  • @glaucoleme: August 31th, 2020: Adding update system option.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment