Creating a Simple Ubuntu Software Repository
Introduction
Wanna know what really goes into just adding that simple extra line in "sources.list" for your favorite Ubuntu repositories? Well, in this article, I'll be detailing some of the work I do while maintaining the CLUG Ubuntu software repository. Listed here will be the basics of how to set up a repository to share your Ubuntu software packages, and a few notes on how to update the repository and troubleshooting a few things you may run into.
Ubuntu (or Debian) software repositories are usually simply hosted on HTTP web servers. There a several directories used for storing the software (the ".deb" files), and then several extra directories are created to provide the information about the packages available.
What You'll Need
To begin, you'll need to install two packages. First, you'll need the "apt-utils" package for creating and updating the repository, and secondly you'll need to install the HTTP server. We'll be using Apache for this example. You can use any web server you like, the repository runs independently of it, and only needs it to host the files. The two software packages can be installed by simply typing the following command into a terminal:
sudo apt-get install apt-utils apache2
Creating the Initial Repository
Once everything is installed, you'll want to then create the initial directories. For this example, we're going to build everything inside a folder called "packages" in the default hosted root directory for Apache. It is simplest to switch into a root terminal to create these directories by doing the following:
sudo -s
mkdir /var/www/packages
cd /var/www/packages
Next, we'll create three main directories needed for the repository. The first is the "pool" directory. Here all of your packages will be placed and organized for downloading in the "main" subdirectory. Several directories can exist, but they must be configured later on. Secondly, the "dists" directory will be created and tailored towards what particular release (in this case, Ubuntu Gutsy 7.10 for i386 architectures) your Ubuntu packages are built for. And last will be the hidden ".cache" directory to be used by the software in the "apt-utils" package for building and updating. Type the following into your root terminal:
mkdir -p pool/main
mkdir -p dists/gutsy/main/binary-i386
mkdir .cache
Configuration Assimilation
Next, you'll need to create the initial configuration files for the "apt-utils" software (mainly the "apt-ftparchive" command) to find and summarize your software. Two configuration files are needed, the "apt-ftparchive.conf" and the "apt-release.conf" files. To create the first configuration file, enter the following command:
sudo gedit apt-release.conf
...and paste this into the text editor:
APT::FTPArchive::Release::Codename "gutsy";
APT::FTPArchive::Release::Origin "Nerdica.com";
APT::FTPArchive::Release::Components "main";
APT::FTPArchive::Release::Label "Nerdica Ubuntu Repository";
APT::FTPArchive::Release::Architectures "i386";
APT::FTPArchive::Release::Suite "gutsy";
The options in this configuration are pretty self explanatory. What architecture, label, and codenames are used can all be changed to your liking.
Much like before, let's create the second configuration file. Enter the following into the terminal:
sudo gedit apt-ftparchive.conf
...and paste this into the text editor:
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/gutsy" {
Sections "main";
Architectures "i386";
}
Or, you can download this configuration file directly from Nerdica if you are having formatting issues by entering this into a terminal:
wget \
http://nerdica.com/wp-content/uploads/2007/11/apt-ftparchive.conf
After looking through this file, there's not much you'll want to tinker with. It's tailored towards the specific directory tree structure used in this tutorial. But as you can tell, the file is broken into several different parts. The "Dir" section obviously shows what directories we will begin working with. The "Default" section gives options for how out software summaries should be compressed. The "TreeDefault" sections defines where our packages are located, and where the summaries and details should be saved. And finally, the "Tree" section defines what kind of packages they are, and where they are located it the pool.
Ready, Set, Go
Now everything is in place for you to copy your packages and build the repository for the first time. You can use packages you've built yourself, or you can mirror other packages you may need. For this particular example, we'll mirror one of my favorite applications, Wine-Doors*. Wine-Doors is an excellent program to helps get your favorite Windows applications running in Linux. Enter the following commands to download the Ubuntu package into the correct directory:
cd /var/www/packages/pool/main
wget http://www.wine-doors.org/releases/wine-doors_0.1.1-1_all.deb
Now that you have at least one package in your repository, you'll want finally build the repository based on the packages you have. Do so by typing the following commands into your terminal:
cd /var/www/packages
apt-ftparchive generate apt-ftparchive.conf
apt-ftparchive -c apt-release.conf release dists/gutsy > \
dists/gutsy/Release
The initial repository has been built. If you ever need to rebuild the repository if you add new packages, or later version of existing packages, just simple type the previous commands into a root terminal.
My Friend Can Has Software?
Now that you have a repository hosted, you can give the address to anyone would like to use it. You can add the repository to anyone existing Ubuntu installation by entering the following command:
sudo gedit /etc/apt/sources.list
..and pasting the following at the end of the file:
deb http://my-server-address.com/packages gutsy main
Remember to replace the server address with your actually domain. Once this line has been added to the "sources.list", the use can then update the repositories and install the new software by entering the following commands:
sudo apt-get update
sudo apt-get install wine-doors
Troubleshooting
If you ever run into any particular problems with adding new software releases or extra software, sometimes the problem can be alleviated by removing what's it the ".cache" directory. You can do so by enterting the following command:
sudo rm - /var/www/packages/.cache/*
Final Notes
Now you've got a repository up to host your own packages, or to help developers by mirroring cool software you enjoy using. Questions? Comments? Let me know by commenting on the article.
Discuss this the forums.

Excellent tutorial you got there. I'm interested to know how to protect the packages with a GPG key there. Could you update your tutorial with that bit of information? I'm sure it will be useful for many others.
i am gonna show this to my friend, dude
How should I connect to internet through my nokia 5300 mobile in Ubuntu OS and where I found nokia pc suit for Ubuntu(linux).
Here I give you a link with a useful tip
http://tips-debian.blogspot.com/2008/04/make-repository.html
Hi,
Thanks for this, it has moved me forward.
I'm making a small repository for essential apps on an SDHC card for an Asus eeePC 4G. Everything worked OK except that I get the message:
WARNING: The following packages cannot be authenticated!
Is this some gpg auth issue? I'll trawl around and see what I can come up with but if you can elighten me I'd appreciate it.
Thx.
Hello webmaster
I would like to share with you a link to your site
write me here preonrelt@mail.ru
After a couple days of banging my head setting up a repository correctly, I found this and it worked perfect (after modifying architectures/suite). Very simple! Thanks! If you want to add GPG keys to the mix:
Note: this was done in Ubuntu 9.04 and is more-or-less specific to my repository. You may have different requirements.
1. Generate a GPG key:
$ gpg --gen-key
Select:
kind of key: (1) DSA and Elgamal
keysize: 1024
key expiration: 0
Enter name, email, comment, and passphrase.
Generate entropy (type a lot, use disk)
2. Export key
Look for the line of output that looks like this after generating the key:
pub 1024D/3FD806D7
Use that last section (3FD806D7) for exporting:
$ gpg --export 3FD806D7 > gpg.key
3. Add the GPG key to your clients. One possible solution is to have the key somewhere in the repository and add the key with wget.
e.g. put gpg.key in /var/www/repositoryname and install on the clients using:
$ wget -q -O- http://sub.domain.com/repositoryname/gpg.key | sudo apt-key add -
You can also add the file locally with:
$ sudo apt-key add path/to/gpg.key
You can confirm that the key added by running:
$ sudo apt-key list
4. On the repository server, sign the Release file under dists/jaunty (or whatever suite you're using) and enter your passphrase when prompted:
$ gpg --sign -bao dists/jaunty/Release.gpg dists/jaunty/Release
5. Done! No more authentication issues when running apt* install!
Very often I visit this blog. It very much is pleasant to me. Thanks the author
-
Welcome to Free-VPN-Unlim.com
http://free-vpn-unlim.com/manuals.html
VPN SOLUTIONS of many problems and inconveniences. And VPN FIREWALL open approaches and make a great secure during the work.
oh!! thnx thnx thnx thnx thnx.........
i start loving this site.........
:D