Skip to content

Instantly share code, notes, and snippets.

@glaucoleme
Created September 1, 2020 12:10
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save glaucoleme/8da8c5737a503a666144aee8e7c7034f to your computer and use it in GitHub Desktop.
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:

#online
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:
#offline
dpkg -i python3-magic_0.4.15-1_all.deb
  • Install the apt-offline:
#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:

#offline
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:

#online
apt-offline get ~/apt-offline.sig --bundle ~/apt-offline.zip

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

#offline
apt-offline install ~/apt-offline.zip

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:

#offline
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:

#online
apt-offline get ~/nginx-info.sig --bundle ~/nginx-install.zip

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

#offline
apt-offline install ~/nginx-install.zip

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:

#offline
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