I'm reproducing a little tutorial I wrote for the zabbix wiki in the hope that it is useful.
Rebuilding a package from source in Debian and derivatives (Mepis, Mint, Ubuntu)
This guide will focus primarily in Debian, although building from source in
other derivatives should be basically the same process. The upstream
documentation
on package management is ultimately the most authoritative source of wisdom.
Why should you choose packaging over "make install"?
Packages make your life easier in many aspects:
- You can deploy packages easily on many systems by using a repository
- You can install and remove them in a clean way
- Dependencies on other packages are tracked for you
- There's a policy for updating configuration files
Where are the source packages?/
Check what versions can be found in the official repositories of
Debian and
Ubuntu
This guide addresses the following scenarios
- You are using Debian stable, and want to rebuild from source to change some default options
- You are using Debian stable, and want to use the version in testing or unstable
- You want to build a deb package from upstream sources
- Alternatives to the official Debian packaging system
The rest of the guide will assume the commands are being run by a non-root user with sudo access
$ sudo -l
- Activate the source repository, in your sources.list
Install the required infrastructure for building, recompiling and packaging
$ sudo aptitude install build-essentials devscripts quilt
1. You are using Debian stable, and want to rebuild the sources
This would be the case when you want to activate/deactivate some feature that's
built by default in the precompiled binaries, apply an extra patch, backport a
feature, use compile-time optimizations (target an specific platform, hardening options). The steps would be:
Create a temporary directory to work in
$ mkdir ~/temp && cd ~/temp
Get the source package
$ apt-get source curl
or alternatively (if you don't have a deb-src
line in your sources.list
pointing to the stable release), you can get the .dsc file from the web,
for current stable this would be
$ dget http://security.debian.org/debian-security/pool/updates/main/c/curl/curl_7.21.0-2.1+squeeze3.dsc
Any of the two alternative methods will
- fetch the sources from the repositories
- validate the cryptographic signature of the package
- apply all distro specific patches
Check the debian/rules makefile
$ cd curl*
$ vi debian/rules
This is the main makefile for the packaging process, here you can review
optional configure options, and can also enable/disable features regarding
all the packages that will be built (server, agent, proxy)
Review the patches with quilt
Let's suppose you are interested in one or more of the distro patches
not being applied. To check what patches are available in the sources, use
$ quilt series
Check for the already applied patches (at this stage the list should be identical)
$ quilt applied
Revert all the patches
$ quilt pop -a
Optionally remove the unwanted ones
$ quilt delete -r $patch_name
Apply the rest of the patches
$ quilt push -a
Install the dependencies of the package you are going to recompile
$ apt-get build-dep curl
Optionally tag the package
$ dch -l +local 'Rebuilt from sources'
Check the dch manpage if you need to add a more elaborated changelog entry.
Finally, recompile the package
$ debuild -us -uc
After the process, outside the zabbix-* directory, you will find the deb
packages you just compiled, ready to install
$ sudo dpkg -i $deb_package
2. You are using Debian stable, and want to use the version in testing or unstable
This process is known as backporting
The following precautions apply
- The package might not build for you at all
- In order to build it might need updated dependencies
- In order to build it might need additional packages
- The packaging layout might have changed
The process is the same as rebuilding for the stable release, with the
exception of the source package, which can be obtained either from apt
repositories using a line like this in your sources.list (note, only one of the
two alternatives)
deb-src http://ftp.de.debian.org/debian/ testing main non-free contrib
deb-src http://ftp.de.debian.org/debian/ unstable main non-free contrib
or again, using the web
$ dget http://ftp.de.debian.org/debian/pool/main/c/curl/curl_7.30.0-1.dsc
An extra precaution would be tagging the packages to ease identification in
case uninstallation is needed.
$ dch -l ~local 'Sid backport'
The rest of the process is identical, and the result will be backported
packages that can be installed along the rest.
3. You want to build a deb package from upstream sources
If you want or need a more recent version than the one that can be found in
Sid, you can still check the experimental
repository, and the git
repository of the mantainer(s) to see if there's something in the works.
Beyond that, you need to use the upstream project repo, but yet one
can benefit from the Debian packaging structure. To that end, a snapshot of the
latest stable or alpha release can be downloaded.
So, after having downloaded the source package from the distro (Debian or Ubuntu, as appropriate) repo as outlined
above, the next steps would be (differences in the versions in use might apply):
$ wget https://github.com/bagder/curl/archive/curl-7_30_0.zip
$ mv master.zip curl-7.30.0.zip
$ cd curl-${stable}
$ uupdate ../curl-7.30.0.zip -v 7.30.0
$ cd ../curl-7.30.0
After this, all the patches in the debian/patches must be reviewed in order to
determine if they still are useful or have to be discarded. Use quilt as described
above. Finish the recompile process tagging
$ dch -l ~local 'Upstream packaging'
rebuilding
$ debuild -us -uc
and installing
$ sudo dpkg -i $deb_package
the package(s).
4. Alternatives to the official Debian packaging system
Some people find the Debian packaging system excessively complicated but still
want to benefit from the advantages of using a packaged software. Some projects
exist that try to address this situation. A list is given here, but the
details of using these tools is left as an exercise for the reader.