Posted by Steve on Fri 1 Oct 2004 at 13:09
Most people are happy with the binary packages which Debian provides, as they tend to be setup to cover the common uses. But what happens if you are looking to rebuild an existing package with different options? Well you can rebuild a package from source very easily.
Rebuilding Debian packages is a two step process, first of all you must fetch the source which was used to build the package, and then you must actually rebuild it.
In order to build most common packages you will need a compiler of some description, and you may well find that you need some development libraries which are used in the rebuild process itself.
Thankfully installing the required packages to build a Debian package is a simple process which the apt-get tool will help you with. (If you're new to using apt-get you might find this simple introduction useful).
There are two commands that you will need to use to rebuild a package:
These two steps you will have to perform for each rebuild you need to do, but thankfully they are very simple to remember and automate.
The only other thing you need are the Debian repackaging utilities which you can install with apt-get install devscripts build-essential fakeroot. This command will allow you to have a build environment, which will allow you to convert the sources you downloaded into .deb files you can actually install.
Lets have an example of how you would rebuild the package less.
First we download the source to the current package:
steve@earth:~$ apt-get source less Reading Package Lists... Done Building Dependency Tree... Done Need to get 258kB of source archives. Get:1 http://http.us.debian.org stable/main less 374-4 (dsc) [611B] Get:2 http://http.us.debian.org stable/main less 374-4 (tar) [243kB] Get:3 http://http.us.debian.org stable/main less 374-4 (diff) [14.3kB] Fetched 258kB in 2s (120kB/s) dpkg-source: extracting less in less-374
Now we can download and install the required packages to build it. (Depending on the packages you have installed on the machine you're using you may find you don't need to install anything).
root@earth:~# apt-get build-dep less Reading Package Lists... Done Building Dependency Tree... Done Note, selecting libncurses5-dev instead of libncurses-dev The following NEW packages will be installed: libncurses5-dev 0 packages upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 998kB of archives. After unpacking 4988kB will be used. Do you want to continue? [Y/n] Get:1 http://ftp.us.debian.org stable/main libncurses5-dev 5.2.20020112a-7 [998kB] Fetched 998kB in 5s (177kB/s) Selecting previously deselected package libncurses5-dev. (Reading database ... 21135 files and directories currently installed.) Unpacking libncurses5-dev (from .../libncurses5-dev_5.2.20020112a-7_i386.deb) ... Setting up libncurses5-dev (5.2.20020112a-7) ...
In our case we discovered that we needed to install the libncurses5-dev package in order to compile less.
Now we can actually rebuild the package. We perform a rebuild by using the debuild command. If we are not the maintainer of the package will need to add two flags to this telling the building process not to sign the package. In most cases debuild -us -uc is what you wish to use.
steve@earth:~$ cd less-374/ steve@earth:~$ debuild -us -uc ... ... dpkg-deb: building package `less' in `../less_374-4_i386.deb'. dpkg-genchanges dpkg-genchanges: not including original source code in upload dpkg-buildpackage: binary and diff upload (original source NOT included)
Now if we look in the parent directory we will find a brand new, recompiled, .deb file.
This can be installed with dpkg as follows:
steve@earth:~/less-374$ cd .. steve@earth:~$ su Password: root@earth:~# dpkg --install less_374-4_i386.deb (Reading database ... 21941 files and directories currently installed.) Preparing to replace less 374-4 (using less_374-4_i386.deb) ... Unpacking replacement less ... Setting up less (374-4) ...
of course we did miss out any editing of the package to make it build differently, but if you know already you need to rebuild a package to change its options, or bahaviour, you will know how to do that!