Table of Contents

Create an Apt Repository Mirror with apt-mirror

The goal of this guide is to set up a local Debian package mirror using the apt-mirror tool and Apache to serve the files.

Install apt-mirror

The version of apt-mirror that is included in the Debian repositories is old and broken, so we need to use a forked version that is not broken. Stifler6996 on GitHub provides a non-broken version that we will use today.

So first we will install Git to clone the repository:

apt install -y git

Then we will find a suitable spot to install apt-mirror, clone the repository, and then symlink it to /usr/local/bin so it's easy to call:

cd /usr/local/src
git clone https://github.com/Stifler6996/apt-mirror
ln -s /usr/local/src/apt-mirror/apt-mirror /usr/local/bin

Configuring apt-mirror

Now we need to set up apt-mirror to download our repositories. Before continuing, make sure you have a sizeable disk mounted somewhere on this system to store the downloaded repositories. For the sake of this demo I'm assuming you have a disk mounted at /srv/repos, but if you want them stored elsewhere then just change that path to match your config.

Thankfully apt-mirror is easy to configure. It's basically just creating /etc/apt/mirror.list with the sources entries you want and some options telling apt-mirror how to behave. Below is an example that will copy the major Debian repositories:

############# config ##################
#
set base_path    /var/spool/apt-mirror
#
set mirror_path  /opt/repos/ubuntu
# set skel_path    $base_path/skel
# set var_path     $base_path/var
# set cleanscript $var_path/clean.sh
set defaultarch  amd64
# set postmirror_script $var_path/postmirror.sh
# set run_postmirror 0
set nthreads     20
set _tilde 0
#
############# end config ##############

# Debian 11 (Bullseye)
... repos ...

clean ...

Install Apache

Install Apache:

apt install -y apache2