Setup Local Repository On Ubuntu 14.04/13.10/13.04 Server

Let us say, you have so many system running with Ubuntu on your office and have to install softwares, security updates and fixes often in all systems, then having a local Ubuntu repository is an efficient way. Because all required packages are downloaded over the fast LAN connection from your local server, so that it will save your Internet bandwidth and reduces the annual cost of Internet.

In this tutorial, I will show you how to install the local repository in Ubuntu 14.04 server in two methods. Moreover, If you use external hard drive, you can setup a portable repository too. You can use the portable repository on multiple locations on your LAN. Both methods are very easy to set up and configure.

Method 1: APT-Mirror

In this method, we are going to pull all packages from the public repository (Ubuntu global server) and save them in our local Ubuntu server hard drive. First install Apache server. Apache web server is important to share the packages over the network.

sudo apt-get install apache2

Now install APT-Mirror:

sudo apt-get install apt-mirror

Be mindful that, you need at least 50GB or more free space in your local or external hard drive.

Now create a directory on your harddisk to save all packages. For example, let us create a directory called “/myrepo”. We are going to save all packages in this directory:

In the above configuration file, you can add the Ubuntu source lists depending upon the distribution you use. For this tutorial, I use the default 14.04 source list. Change them as per your requirements.

If you use both 32bit and 64bit architectures, you should name them separately in the above file. For example, if you use 32bit architecture, the lines should start with deb-i386 and for 64bit, they should be deb-amd64. Clear? Well, once you saved the configuration file, populate your repository using the following command:

Now the packages from public repositories are being pulled and saved to your local directory(/myrepo). Depending upon your Internet speed, it will take hours.

You can cancel this process at any time. Once you started it again, it will resume the downloading process where you left it off. I strongly advise you to use a fast broadband Internet connection.

Do I need to run this command every day to get new softwares/updates? No, it is not necessary. You can schedule this process using a cron job. So your machine will automatically run the apt-mirror command on a regular daily basis and will keep your repository up-to-date.

That’s it. Here 192.168.1.2 is my Ubuntu server IP address. Now, you can use your Local repository. The clients need not to be connected to the Internet to download packages. Instead, it will get all packages, updates from your Ubuntu server’s local repository.

Method 2: APT-Cacher

APT-Cacher is different from APT-Mirror. It does not mirror the entire repository contents, instead it saves the packages requested by the clients on your local network and make them available to the rest of the clients for future use.

First install Apache server. This is required to share the packages over the network:

sudo apt-get install apache2

Now install APT-Cacher.

sudo apt-get install apt-cacher

Choose daemon to run as a standalone daemon and click OK.

Once you are done the installation, open the file /etc/default/apt-cacher,

sudo vi /etc/default/apt-cacher

and set autostart=1 if it is 0, else leave as it is.

# apt-cacher daemon startup configuration file
# Set to 1 to run apt-cacher as a standalone daemon, set to 0 if you are going
# to run apt-cacher from /etc/inetd or in CGI mode (deprecated). Alternatively,
# invoking "dpkg-reconfigure apt-cacher" should do the work for you.
#
AUTOSTART=1
# extra settings to override the ones in apt-cacher.conf
# EXTRAOPT=" daemon_port=3142 limit=30 "

You can also allow or deny the no of hosts to access the cache (packages). To do that, open the /etc/apt-cacher/apt-cacher.conf file.

sudo vi /etc/apt-cacher/apt-cacher.conf

Uncomment and update the value for allowed_hosts to match the individual hosts. Once you done all the settings, restart the service:

Conclusion

Due to lack of resources and time, I haven’t properly checked both methods. As far as I know, both methods should work fine and they are highly recommended to save your Internet bandwidth. Moreover, both are easy to configure and maintain, and you don’t to be a master In Linux. Just give it a try and share your thoughts in the comment section below.

12 responses

Etescartz

May 7, 2014

I think the repository wold be faster with nginx instead of apache2. Also there is no mention on how to add specific ‘.deb’ files to this repository.
This can be used for software not directly stored on Canonical’s official repositories or just in some private package archives (PPA) found on https://launchpad.net

I use this for latest libreoffice.org packages that take time to make their way into Ubuntu’s official repositories.

You’ll need ‘dpkg-dev’ package:

sudo apt-get install dpkg-dev

Then you’ll need to create a folder that you’ll use to store the *.deb files
sudo mkdir -p //debs/ for obvious path consistency reasons, but any folder path can be used.

To update the *.deb files in the directory you created and make them visible through your repository, you’ll need to create a script :

Note. This script must be run after any change/update/addition of .deb files in the foder you created. This can be set up as a crobjob or just manually run the script once you added/removed .deb packages.

SK

May 7, 2014

Thanks for the suggestion. Much appreciated.

Stockman

May 8, 2014

ho about using nginx instead of apache2 ?

Etescartz

May 8, 2014

Didn’t read the comments after reading the article. Did you ? :D

Stockman

May 9, 2014

oh sorry. didn’t read. but it would be nice to have an article about how to configure using nginx

Etescartz

May 9, 2014

it’s pretty much the same thing. I think I saw one for Debian on howtoforge.com . The configuration options, for nginx were pretty straight forward so I guess you can use them in Ubuntu as well.

Robert Eddy

May 11, 2014

I’ve not used apt-cacher, but I’ve been pretty happy with apt-cacher-ng, which is a fork of Apt-Cacher, if I’m recalling correctly, though the name also suggests this.

I ran apt-mirror and it downloaded a ton of stuff, so far so good, but it only created the ubuntu/pool directory, I don’t have necessary directories such as ubuntu/dists. Any idea what would cause that and how to fix it?