
Often, when deploying a network of machines on
Ubuntu, there is a problem with the organization of Internet access in order to install new programs from standard repositories. For example, when only a very narrow channel on the Internet is available or traffic is not unlimited. Fortunately, the principle of the organization of the Ubuntu package system allows you to very flexibly control what and from where to download using regular package management tools. In particular, you can create a local copy of the Ubuntu online repositories you need and connect it as the main source of applications to your local network. Thus, all computers on your network will not require an Internet connection to install new programs and updates. And at the same time, and most importantly, all the functionality of package managers will remain.
In this article I will explain how to create a local copy of the repository using the
apt-mirror utility. This is a simple and handy utility for creating local copies of Ubuntu repositories, using the same syntax as in the
/etc/apt/sources.list file, which lists all repositories for Ubuntu.
All you need is a computer with Ubuntu installed and unlimited internet access.
The local copy of the official repository of Ubuntu 10.10 for only one i386 architecture takes 36.2 GiB, keep this in mind.')
So, on a computer connected to the Internet and with Ubuntu installed, we install the
apt-mirror package through any means of installing packages, for example, with the command
sudo apt-get install apt-mirror
Next, you need to decide in which directory to put a copy of the repository. Let us consider, for example, that the repository copy will be added to the
/ media / data / ubuntu-repo / folder, which is located on a separate hard disk mounted in the
/ media / data directory. Of course, you need to make sure that there is enough space in the specified folder to place a full copy of the repositories you need.
Apt-mirror setup
All that remains to be done is to edit the
apt-mirror configuration file, add the necessary options and necessary repositories, and start the mirroring process itself. This file is
/etc/apt/mirror.list . Below is the commented its contents for the case of creating a copy of the official
Ubuntu 10.10 repositories for the
i386 architecture in the
/ media / data / ubuntu-repo / folder:
Now it remains to run
apt-mirror and wait for it to finish. Before launching, you must make sure that the main directory
/ media / data / ubuntu-repo / , as well as all the auxiliary directories
mirror ,
var and
skel inside it, exist and are available for writing to the user
apt-mirror . You can create all these directories with commands.
mkdir -p /media/data/ubuntu-repo/ mkdir -p /media/data/ubuntu-repo/{mirror,var,skel}
It is easiest to assign the necessary rights by setting the owner of these directories to the user
apt-mirror :
sudo chown -R apt-mirror /media/data/ubuntu-repo/
After that you can run
apt-mirror with the command
sudo -u apt-mirror apt-mirror
After downloading the indices,
apt-mirror will tell you how many packages will be uploaded:
You just have to wait for the download to complete.
Automatic update of the local repository
You can configure automatic updating of the local copy of the repositories using
cron jobs. To do this, simply uncomment the required line with the task in the
/etc/cron.d/apt-mirror file:
You can change the task execution time (by default - at 04:00 every day).
Additional features apt-mirror
When using the scheme described above,
apt-mirror will copy only packages from the specified repositories. However, besides that, the Ubuntu repositories also contain a lot of useful data, for example, network installers. All of this when using the "
clean " instructions for these repositories will be deleted because it is not contained in the actual indexes. In order not to clear some directories forcibly, you can specify the instruction "
skip-clean " with the necessary address in the file
mirror.list . For example:
You can specify the architecture directly in the APT repository line, for example like this:
In addition, you can connect to HTTP and FTP hosts that require authorization. To do this, you must specify the name, password and, if necessary, the port:
Further work with a local copy of the repository
Upon completion, local copies of all repositories listed in
mirror.list will be in the
mirror / repository_name folders in the specified main working folder
apt-mirror . Thus, the repository copy that was specified in
mirror.list as
deb http://archive.ubuntu.com/ubuntu maverick main restricted
will be in our case in the folder
/ media / data / ubuntu-repo / mirror / archive.ubuntu.com / ubuntu . And this folder will need to be connected as a repository to other systems using an HTTP or FTP server, or directly through the physical connection of the file carrier.
To connect using HTTP server, you can install Apache:
sudo aptitude install apache2
Then make a symlink
/ var / www / ubuntu pointing to your repository folder:
sudo ln -s /media/data/ubuntu-repo/mirror/archive.ubuntu.com/ubuntu /var/www/ubuntu
After that, it will be possible to connect this computer as a source of applications to everyone else on the network, pointing out the following repository:
deb http://__/ubuntu maverick main restricted
In your case, perhaps, besides
main and
restricted , there will be other components.
If you want to use your copy of the repository as a local repository, then you will need to connect your repository media to the computer you need, and then add approximately the following line to the list of application sources on this computer:
deb file:/media/data/ubuntu-repo/mirror/archive.ubuntu.com/ubuntu maverick main restricted
The path, of course, in your case may be different.
Finally, I would like to note that in many cases it is not necessary to make a copy of the entire repository, but rather using something like
apt-cache or
apt-move .
Current version of the article
The latest and most current version of this article is on the official Russian-language Wiki-resource for Ubuntu documentation. There you can freely improve and supplement the laid out reference and training materials, as well as add your own. If you have something to tell other Ubuntu users, then a huge request - write or edit the relevant article on help.ubuntu.ru . Even with small improvements and additions you will help thousands of people, and some of them, in turn, will describe something useful and interesting for you.