How to Install Packages to Offline Ubuntu or Debian Machines

We all face this problem time to time and it becomes time consuming for the packages that have lots of dependencies. Downloading, copying and installing one-by-one, and by hand is nearly impossible for these packages. So, here’s what you need to do for installing packages offline to your Debian or Ubuntu machine.

In a Machine Connected to the Internet

1- If your target package is not on the Ubuntu/Debian repository by default, add its repository to /etc/apt/source.list or source.list.d/ directory.

2- Update your source list index by using the commands apt update or apt-get update. This index is at /var/lib/apt/lists/.

3- If you need to see what your package depends on, and what it conflicts with, check apt depends {package-name}.

4- Now, you can list URIs of the dependencies of a package. Use the command apt-get -qq –print-uris {package-name} > {temporary-package-list-name}. Now, you have all packages’ URIs listed in the document to be downloaded.

5- We will now create a shell script to download all these. We will do these by using awk. The command we will use is: awk ‘{print “wget ” $1}’ < {temporary-package-list-name} > download_packages.sh.

6- Now you will make the script you’ve generated executable as a user. chmod u+x download_packages.sh

7- Now we will run the script by ./download_packages.sh

At this point, you have all packages you need at the machine that has the Internet connection.

In the Target Machine

By either using SFTP, FTP, or by using a physical connection medium:

1- Copy the source list index from the Internet-connected machine to the offline machine at /var/lib/apt/lists

2- Copy all the source.list.d directory of the Internet-connected machine to the offline machine at /etc/apt/source.list

3- Copy all .deb packages you’ve downloaded to the /var/cache/apt/archives/ directory.

Now you are all set! What is left to do is using apt install {package-name} on the target machine. Now it is done! We’ve done it.

Also, if you’re okay with a sloppier installation, copy .deb packages and use dpkg -i * at the copied destination.

For more information, check Debian’s article about offline apt here. Also, you may check more solutions at my homepage!

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *