Wednesday, April 30, 2008

Rebuild a Debian Package

If you use Debian, Ubuntu, or some other Debian derived Linux distribution, there may come a time when a packages default configuration options don't meet your needs. This generally leaves you two options. You can either build from source and no longer have the luxury of the package manager maintaining your package, or you can rebuild the package with the custom options included in the build. This is easier than it sounds and really only involves a few steps. In this example, I'll rebuild netcat.

1) make sure you have the packages required to re-build a .deb

apt-get install devscripts build-essential fakeroot

2) fetch the source for the package to re-build

apt-get source netcat

3) fetch dependent packages for the build

sudo apt-get build-dep netcat

4) unpack vendor specific source archives

# determine appropriate dsc file
ls *dsc
netcat_1.10-33.dsc
# run dpkg-source on dsc file
dpkg-source -x netcat_1.10-33.dsc

5) cd into source directory

cd netcat-1.10

6) modify source if necessary, apply patches, etc...

7) set custom build options if desired (optional)

# fake DEB_BUILD_OPTIONS here, just for the sake of example...
DEB_BUILD_OPTIONS="--enable-sockets" CC=gcc-3.4 fakeroot debian/rules binary

8) build the package

dpkg-buildpackage -rfakeroot -b

9) install the package ;-)

sudo dpkg -i ../netcat_1.10-33_i386.deb

No comments: