Last updated

How to: Compile packages on Debian/Ubuntu by hand

In some very rare situations you may find yourself in the need to recompile a Debian (or Ubuntu) package. Luckily for all of use, the great Debian packaging system makes this a piece of cake.

Let’s say we want to recompile mod_python for apache 2 to hook in to python 2.5, instead of the default 2.4.

First, get every thing installed you may need to build the libapache2-mod-python package.

1$ apt-get build-dep libapache2-mod-python

Okay, next let’s grab the source for the package. The source will be unpacked to your current working directory, so it may be a good idea to create a seperate directory for this.

1$ mkdir src
2$ cd src
3$ apt-get source libapache2-mod-python

In the case of this example, you don’t need to do anything special to get python 2.5 linked. Just install the python2.5 and python2.5-dev packages.

If you need to apply patches to the source or need to make any other modifications, this is the time!

Okay, now go to the source directory and build the package. This is the tricky command here:

1$ cd libapache2-mod-python
2$ dpkg-buildpackage -rfakeroot -b

This will build the package. You will get some warnings and errors about missing GPG keys. This is okay. You are not the package maintainer, so your packages should not be marked as ‘original’.

You’re now ready to install your compiled package.

1dpkg -i ../libapache2-mod-python-3.3.1-3-i386.deb

That’s all! You compiled and installed a package from source!