There are two commands that you will need to use to rebuild a package:
apt-get source foo
apt-get build-dep foo
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:
chuck@etch:~$ 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@etch:~# 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.
chuck@etch:~$ cd less-374/ chuck@etch:~$ 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:
chuck@etch:~/less-374$ cd .. chuck@etch:~$ su Password: root@etch:~# 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!