Create a local apt-mirror
Download an apt-mirror
To create a local Debian APT mirror, you can follow these general steps:
Set up a server: You will need a server with sufficient storage capacity and network bandwidth to host the mirror.
Install the necessary packages: Start by installing the
apt-mirrorpackage, which is available in the Debian repositories. Use the following command to install it:
sudo apt-get install apt-mirror
Configure the mirror: Open the
apt-mirrorconfiguration file using a text editor. The file is located at
/etc/apt/mirror.list. You can use the following command to open it with
sudo nano /etc/apt/mirror.list
Inside the file, you need to define the repositories you want to mirror. Uncomment the lines for the desired repositories, or add new lines if needed. For example:
deb http://deb.debian.org/debian buster main contrib non-free deb-src http://deb.debian.org/debian buster main contrib non-free
Save the file after making the necessary changes.
Configure the mirror directory: By default,
apt-mirroruses the directory
/var/spool/apt-mirrorto store the mirrored files. Ensure that you have enough space available in that directory, or specify a different location in the
apt-mirrorconfiguration file if needed.
apt-mirror: Execute the
apt-mirrorcommand with root privileges to start the mirroring process. Use the following command:
The mirroring process will take some time, depending on the speed of your network connection and the size of the repositories you're mirroring. Ensure that the server remains connected to the internet during this process.
Serve the mirror using a web server: After the mirroring process completes, you need to serve the mirror using a web server. You can use any web server of your choice, such as Apache or Nginx. Install and configure the web server, ensuring that it points to the mirror directory you specified earlier.
Configure clients to use the local mirror: On the machines where you want to use the local mirror, modify the
/etc/apt/sources.listfile to point to your mirror's URL. Replace the original Debian repository URLs with the URL of your local mirror. For example:
deb http://your-mirror-url/debian buster main contrib non-free deb-src http://your-mirror-url/debian buster main contrib non-free
Save the file after making the changes.
That's it! Your local Debian APT mirror should be ready to use. Clients can now update and install packages from the mirror, which will be significantly faster than downloading from the official Debian repositories. Remember to periodically update your mirror by running
apt-mirror again to keep it synchronized with the official repositories.
To provide your local Debian APT mirror via Apache2, you can follow these steps:
Install Apache2: If you don't already have Apache2 installed, you can install it using the package manager. On Debian-based systems, you can use the following command:
sudo apt-get install apache2
Configure Apache2: Once Apache2 is installed, you need to configure it to serve your APT mirror. Open the Apache2 configuration file using a text editor. On Debian-based systems, the file is located at
/etc/apache2/sites-available/000-default.conf. Use the following command to open it with
sudo nano /etc/apache2/sites-available/000-default.conf
Inside the file, you need to add a new
Aliasdirective that maps a URL path to the directory where your mirror is located. For example, if your mirror is stored in
/var/spool/apt-mirror, you can add the following line within the
Alias /debian /var/spool/apt-mirror/mirror/deb.debian.org/debian
Save the file after making the changes.
Enable the Alias module: By default, the
aliasmodule is not enabled in Apache2. Enable it using the following command:
sudo a2enmod alias
Restart Apache2: After making the configuration changes, restart Apache2 for the changes to take effect:
sudo service apache2 restart
Test the mirror: Open a web browser and enter the URL
your-server-ipwith the IP address or hostname of your server). You should see the directory listing of the Debian mirror, indicating that Apache2 is serving the mirror correctly.
Note: If you want to restrict access to the mirror and only allow specific clients to use it, you can configure Apache2 to add authentication or restrict access based on IP addresses.
With these steps, you have configured Apache2 to provide your local Debian APT mirror. Clients can now update their
/etc/apt/sources.list file to point to your mirror URL, such as
http://your-server-ip/debian, and use it to download packages from the local mirror.