create a local 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.