Looking to setup a local Debian Linux mirror or host your own repository? You can 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 or 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).
To Create a Local Debian Mirror or Repository
In the following steps I’ll guide you through the process of creating a local Debian mirror or repository. With the primary goal being that you can then use a local repository to quickly install packages or perform Debian Linux builds on computers from your own local network.
NOTE: This method can also be edited and used for building a local Ubuntu mirror if desired. To do this, simply replace the Debian sources with Ubuntu sources.
- First, open a terminal Ctrl+Alt+T and type the following to become root:
sudo su
- Next, install the prerequires for hosting a local mirror:
apt-get install apt-mirror apache2
- Then, backup your existing mirror.list:
mv /etc/apt/mirror.list /etc/apt/backup-mirror.list
- Now you can proceed to create a new mirror list entry:
Note that you can use the “gedit” command in place of “nano” if you have the graphical editor installed.nano /etc/apt/mirror.list
- Add the following to your mirror list. If you want to use a different Debian repository for your mirror, for example buster, simply replace all occurrences of bullseye with buster. Once finished, 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/
- Finally, type the following to begin creating a local mirror:
su - apt-mirror -c apt-mirror
This entire process will take a while (it could even take hours depending on your connection speed), so it’s best to start this process when you plan to be away from your computer for some time. Once finished you can find your Debian mirrors 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.
- From the terminal use the ln command to create a symbolic link for debian:
ln -s /var/spool/apt-mirror/mirror/ftp.us.debian.org/debian /var/www/debian
- Then, create a symbolic link for debian-security:
ln -s /var/spool/apt-mirror/mirror/security.debian.org/debian-security /var/www/debian-security
- Now you’ll want to backup your original apt sources list:
mv /etc/apt/sources.list /etc/apt/backup-sources.list
- Then, edit the apt sources list to include the debian source repositories:
gedit /etc/apt/sources.list
Add the following deb sources, and 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
- Finally, update them to make sure all packages are current:
apt-get update
That’s all there is to it. You should now be able to perform all of your package management locally. I hope this helps you enjoy having the ability to install Debian packages locally from your own Debian mirror or local repository.