How to Setup a Local Debian Mirror

Looking to Setup a Local Debian Linux Mirror or host your own Repository? Use your local hard drive or a network drive and share your mirror over a network or even on the internet. Having your our own Debian/Ubuntu Linux Mirror enables you to drastically speed up the process of installing packages or complete netbuilds on one or more networked Linux PC (s).

The following method can also be edited and used for building a Ubuntu Mirror if desired. Simply replace the Debian sources with Ubuntu to make the change.

Note: If step 2 fails to find and install the apt-mirror package, you may need to add the following line to your /etc/apt/sources.list

deb http://apt-mirror.sourceforge.net/ apt-mirror/

To Create a Local Debian Mirror or Repository

  1. Open a terminal and type the following to become root;
    sudo su
  2. Next, type the following to install the prerequires for hosting a local mirror;
    apt-get install apt-mirror apache2
  3. Then, type the following to backup your existing mirror.list;
    mv /etc/apt/mirror.list /etc/apt/backup-mirror.list
  4. Now to create a new entry, type;
    gedit /etc/apt/mirror.list
  5. Then add the following – If you want to use a different Debian Repository for your Mirror – for example buster (just replace all occurrences of  bullseye with buster) and then save the file;
    ## apt-mirror configuration file
    ## The following are default configuration options (uncomment the singular # to change)
    # set base_path /var/spool/apt-mirror
    # set mirror_path $base_path/mirror
    # set skel_path $base_path/skel
    # set var_path $base_path/var
    # set defaultarch
    # set nthreads 20
    set _tilde 0##
    ## sources
    deb http://deb.debian.org/debian bullseye main contrib non-free
    deb-src http://deb.debian.org/debian bullseye main contrib non-free
    deb http://security.debian.org/debian-security bullseye-security main contrib non-free
    deb-src http://security.debian.org/debian-security bullseye-security main contrib non-free
    deb http://deb.debian.org/debian bullseye-updates main deb-src http://deb.debian.org/debian bullseye-updates main contrib non-free
    deb http://deb.debian.org/debian bullseye-backports main deb-src http://deb.debian.org/debian bullseye-backports main contrib non-free
    ## Cleaner configuration example
    # set cleanscript $var_path/clean.sh
    ## Cleaning section
    clean http://security.debian.org/
    clean http://ftp.us.debian.org/
  6. Finally, type the following to begin the Mirror creation process;
    su - apt-mirror -c apt-mirror

The process will likely take several hours, so it’s best to start this process when you plan to be away from the PC for some time.
(Your Debian Mirrors will be stored in subdirectories located at /var/spool/apt-mirror/mirror/)

Make your Debian Mirror available via HTTP (localhost or Network IP)

To access your Debian Mirror on a network, replace localhost in step 4 with the IP address of the PC hosting the Local Repository.

  1. From the terminal type;
    ln -s /var/spool/apt-mirror/mirror/ftp.us.debian.org/debian /var/www/debian
  2. Then, type;
    ln -s /var/spool/apt-mirror/mirror/security.debian.org/debian-security /var/www/debian-security
  3. Next, type the following to backup your original list, again;
    mv /etc/apt/sources.list /etc/apt/backup-sources.list
  4. Then, type the following to edit the sources, again;
    gedit /etc/apt/sources.list

    and add the following deb sources, then save the file:

    deb http://deb.debian.org/debian bullseye main contrib non-free
    deb-src http://deb.debian.org/debian bullseye main contrib non-free
    deb http://security.debian.org/debian-security bullseye-security main contrib non-free
    deb-src http://security.debian.org/debian-security bullseye-security main contrib non-free
    deb http://deb.debian.org/debian bullseye-updates main deb-src http://deb.debian.org/debian bullseye-updates main contrib non-free
    deb http://deb.debian.org/debian bullseye-backports main deb-src http://deb.debian.org/debian bullseye-backports main contrib non-free
  5. Finally, type;
    apt-get update

    and enjoy having the ability to install Debian or packages from your own Debian Mirror or Local Repository.