This assumes you already have a web server like nginx or apache running.
1. Install apt-mirror
First, ensure your system is up to date:
Then, install the apt-mirror package:
Code:
sudo apt install apt-mirror
2. Configure apt-mirror
Edit the configuration file /etc/apt/mirror.list to specify the repositories you want to mirror. Open the file with your preferred text editor:
Code:
sudo nano /etc/apt/mirror.list
Here’s an example configuration for Ubuntu 22.04:
Code:
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 cleanscript $var_path/clean.sh
set defaultarch amd64 set nthreads 20 set _tilde 0
deb http://archive.ubuntu.com/ubuntu jammy main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu jammy-security main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu jammy-updates main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu jammy-backports main restricted universe multiverse
clean http://archive.ubuntu.com/ubuntu
Adjust the URLs and distribution names according to your needs.
3. Run apt-mirror
To start the mirroring process, simply run:
This will download the specified repositories to your local machine.
4. Serve the mirrored repository
You can use a web server like Apache to serve the mirrored repository. Install Apache:
Create a symbolic link to the mirror directory in the web server’s root directory:
Code:
sudo ln -s /var/spool/apt-mirror/mirror /var/www/html/ubuntu
5. Configure clients to use the mirror
On the client machines, edit the /etc/apt/sources.list file to point to your local mirror. For example:
Code:
deb http://your-server-ip/ubuntu jammy main restricted universe multiverse deb http://your-server-ip/ubuntu jammy-security main restricted universe multiverse deb http://your-server-ip/ubuntu jammy-updates main restricted universe multiverse deb http://your-server-ip/ubuntu jammy-backports main restricted universe multiverse
Replace your-server-ip with the IP address of your server.
6. Update and upgrade
Finally, update the package list and upgrade the packages on the client machines:
Code:
sudo apt update sudo apt upgrade
That's it! Your clients should now be able to use the local mirror for package updates.