Create a local apt-mirror for offline usage

Sep 27, 2019 by Alexandre Croix | 10034 views

In some cases, it is necessary to work on offline machines because of sensitive data for example. To install a Ubuntu version on an offline computer is quite easy. Problems begin when it is needed to install some programs/debian packages for your development. With the default configuration, it is not possible to install anything without an Internet connection.

To avoid this problem, a solution is to install a local apt-mirror (on your machine or on a local network disconnected from the Internet).


An APT-mirror is a full or partial copy of the official apt packages.

Download packages

On a machine connected to the Internet, run the following command

debmirror -p -v -h -r mirror/ --method ftp --passive -d xenial,xenial-security,xenial-updates -a i386,amd64 --ignore-release-gpg  /path/to/usb-disk/ubuntu-xenial/

This command will download, in ftp, on mirror/ all packages for Ubuntu Xenial (16.04LTS) for architecture i386 and amd64. All packages will be stored on folder /path/to/usb-disk/ubuntu-xenial.

Debmirror has a lot of different options, you can easily adapt the command for other needs.

It is important to have enough space disk to create an apt-mirror. The above example command requires around 300GB of space.

Set up a mirror on the offline machine

On the offline machine, you need to install an Apache server. It is really easy with an Internet connection, but more difficult without... Apache requires several dependencies and it is necessary to install these manually. The following script downloads all deb packages needed to install Apache on Ubuntu 16.04LTS:

wget -c
wget -c
wget -c
wget -c
wget -c
wget -c
wget -c
wget -c
wget -c

Copy all these deb packages on the offline machine and install all packages with the command:

sudo dpkg -i package

After that, simply copy the mirror previously downloaded in the folder /var/www/html/apt

Set up offline machine(s) to use the mirror

On each machine on which you want to use the offline apt-mirror, change the file /etc/apt/sources.list by the following:

deb http://ip.of.srv/apt/ubuntu-xenial xenial main restricted universe
deb http://ip.of.srv/apt/ubuntu-xenial xenial-updates main restricted universe
deb http://ip.of.srv/apt/ubuntu-xenial xenial-security main restricted universe

by replacing ip.of.srv by the IP address of your offline mirror.

You can now update and install all the packages you want!

This blog post is licensed under CC BY-SA 4.0

This website uses cookies. More information about the use of cookies is available in the cookies policy.