Skip to main content

Create a local apt-mirror

To create a local Debian APT mirror, you can follow these general steps:

  1. Set up a server: You will need a server with sufficient storage capacity and network bandwidth to host the mirror.

  2. Install the necessary packages: Start by installing the apt-mirror package, which is available in the Debian repositories. Use the following command to install it:

    sudo apt-get install apt-mirror
  3. Configure the mirror: Open the apt-mirror configuration file using a text editor. The file is located at /etc/apt/mirror.list. You can use the following command to open it with nano:

    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 buster main contrib non-free
    deb-src buster main contrib non-free

    Save the file after making the necessary changes.

  4. Configure the mirror directory: By default, apt-mirror uses the directory /var/spool/apt-mirror to store the mirrored files. Ensure that you have enough space available in that directory, or specify a different location in the apt-mirror configuration file if needed.

  5. Run apt-mirror: Execute the apt-mirror command with root privileges to start the mirroring process. Use the following command:

    sudo apt-mirror

    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.

  6. 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.

  7. Configure clients to use the local mirror: On the machines where you want to use the local mirror, modify the /etc/apt/sources.list file 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.