Howto create your own Ubuntu repository

Friday, 11th September 2009, 2225hrs

Linux | Debian

Ubuntu and Debian packages are all bundled in something what is called a repository. Some people, like me, create their own:


My repository links with the Jaunty distribution (that is Ubuntu 9.04). Your can connect yours to any other, like Debians experimental repository.

First create your own repository.

My repository is accessible over the web, so I installed it on my web server:

user@box:~$ cd /var/www/
user@box:/var/www$ sudo mkdir packages
user@box:/var/www$ cd packages/

In this /var/www/packages we will create a pool, the 'jaunty' distribution and the cache directories:

user@box:/var/www/packages$ sudo mkdir -p pool/main
user@box:/var/www/packages$ sudo mkdir -p dists/jaunty/main/binary-i386
user@box:/var/www/packages$ sudo mkdir .cache

Now two files need to be created. The first one is the apt-release.conf. Make sure that it looks like:

APT::FTPArchive::Release::Codename "jaunty";
APT::FTPArchive::Release::Origin "";
APT::FTPArchive::Release::Components "main";
APT::FTPArchive::Release::Label "ElevenBits Ubuntu Repository";
APT::FTPArchive::Release::Architectures "i386";
APT::FTPArchive::Release::Suite "jaunty;

The second file is called apt-ftparchive.conf. This one should look like:

Dir {
     ArchiveDir ".";
     CacheDir "./.cache";

Default {
     Packages::Compress ". gzip bzip2";
     Contents::Compress ". gzip bzip2";

TreeDefault {
     BinCacheDB "packages-$(SECTION)-$(ARCH).db";
     Directory "pool/$(SECTION)";
     Packages "$(DIST)/$(SECTION)/binary-$(ARCH)/Packages";
     Contents "$(DIST)/Contents-$(ARCH)";

Tree "dists/jaunty" {
     Sections "main";
     Architectures "i386";

After you'd created these file your system should look like this:

user@box:/var/www/packages$ ls -al
total 28
drwxr-xr-x 5 root root 4096 Aug 14 13:32 .
drwxr-xr-x 3 root root 4096 Aug 14 13:22 ..
drwxr-xr-x 2 root root 4096 Aug 14 13:26 .cache
-rw-r--r-- 1 root root  427 Aug 14 13:32 apt-ftparchive.conf
-rw-r--r-- 1 root root  282 Aug 14 13:30 apt-release.conf
drwxr-xr-x 3 root root 4096 Aug 14 13:26 dists
drwxr-xr-x 3 root root 4096 Aug 14 13:26 pool

Add your own packages and update the repository.

Here the yourpackage package version 1.0 is copied into the new (empty) repository:

user@box:~$ cd /var/www/packages/pool/main
user@box:/var/www/packages/pool/main$ sudo cp ~/yourpackage_1.0_all.deb .

Now the repo needs to be initialized. This you can do using these commands:

user@box:~$ cd /var/www/packages
user@box:/var/www/packages$ sudo apt-ftparchive generate apt-ftparchive.conf
 pool/main: 1 files 9900B 0s
Done Packages, Starting contents.
 dists/jaunty/Contents-i386: 1 files 9900B 0s
Done. 9900B in 1 archives. Took 0s
user@box:/var/www/packages$ apt-ftparchive -c apt-release.conf release dists/jaunty | sudo tee dists/jaunty/Release
Architectures: i386
Codename: jaunty
Components: main
Date: Mon, 17 Aug 2009 14:16:41 UTC
Label: ElevenBits Ubuntu Repository
Suite: jaunty
 1d25efc884e5bbfc32eeba74771e322e              536 main/binary-i386/Packages
 574c2e304fb14272b8f70355e93fbe80              416 main/binary-i386/Packages.bz2
 3a0cbc2e4a38e40c8182451c85de1251              390 main/binary-i386/Packages.gz
 949b9e9045f7698cd64abd4c1fa2261eb5d22f82              536 main/binary-i386/Packages
 6d5d5c841a8890b4491650f4f360d53158d16cc0              416 main/binary-i386/Packages.bz2
 eda59ba70dc9e9d65cf92076e33cb589a07de564              390 main/binary-i386/Packages.gz
 b30b4e68d8928785d132dbdc6bb4158e75e907e07f00a3b8d206030236b8f94a              536 main/binary-i386/Packages
 38b855ab6e0ce3111f986f26347871827e5e461af9b29b8ccf12773560f63caf              416 main/binary-i386/Packages.bz2
 1d1aec4f2cff1a3b71212083aabfc3f2003c88b70f1f0a2ef32bfbb94c2aa879              390 main/binary-i386/Packages.gz

After this, the repository is ready to be used. See http://localhost/packages to make sure.


Remember to re-initialize the repo each time the /var/www/packages is altered.

Enable the repository on your client machines.

On the Ubuntu machines that need access to your repository, use

sudo vim /etc/apt/sources.list

to add in the repository address:

deb http://ww.xx.yy.zz/packages jaunty main

where ww.xx.yy.zz is the address where your server lives.

From now on the system has access to our own private repository. Cool, no?