About Linux FAQ

Browse More FAQs:

How to: Recompiling / Rebuild Debian / Ubuntu Linux Binary Source File Packages

Posted by Vivek Gite [Last updated: January 15, 2008]

Q. I'd like to rebuild a Debian / Ubuntu package called foo with additional option. How do I recompile .deb packages?

A. To build a Debian package, you need the following packages / software installed on system
[a] fakeroot : fakeroot package - runs a command in an environment wherein it appears to have root privileges for file manipulation. This is useful for allowing users to create archives (tar, ar, .deb etc.) with files in them with root permissions/ownership.

[b] dpkg-dev : package building tools for Debian

[c] Development environment - You need gcc, make and all other compiler collection installed on system. Under Debian / Ubuntu package build-essential takes care of everything.

Step #1: Install required packages

Type the following command
$ sudo apt-get install build-essential fakeroot dpkg-dev

Step #2: Install source code package

First, create a directory to store source package, enter:
$ mkdir build
$ cd build

Use apt-get command to install source code for a package called foo
$ sudo apt-get source foo
Install all build-dependencies, enter:
$ sudo apt-get build-dep foo
Unpacks Debian / Ubuntu source archives with Debian source package (.dsc) manipulation tool, enter:
$ dpkg-source -x foo_version-revision.dsc
To just compile the package, you need cd into foo-version directory and issue the command
$ dpkg-buildpackage -rfakeroot -b
If you want to pass custom additonal options to configure, you can set up the DEB_BUILD_OPTIONS environment variable. For instance, if you want pass option called --enable-radio --enable-gui, enter:
$ DEB_BUILD_OPTIONS="--enable-gui --enable-radio" fakeroot debian/rules binary
You can also pass some variables to the Makefile. For example, if you want to compile with gcc v3.4, enter:
$ CC=gcc-3.4 DEB_BUILD_OPTIONS="--enable-gui --enable-radio" fakeroot debian/rules binary

A complete example - mplayer

Let us see how to rebuild mplayer media player package with --enable-radio --disable-ivt options:
# sudo apt-get source mplayer
# sudo apt-get build-dep mplayer
# dpkg-source -x mplayer_version-revision.dsc
# DEB_BUILD_OPTIONS="--enable-gui --enable-radio --disable-ivt" fakeroot debian/rules binary

Now wait for some time as compile procedure going to take its own time. To install the newly-built package, enter:
# dpkg -i ../mplayer_version-revision_arch.deb

Further readings:

Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

Related Other Helpful FAQs:

Discussion on This FAQ

  1. Scott Carlson Says:

    I also use these lines to up the package number for a local deb to indicate what I’ve changed.

    export EMAIL=someemail@gmail.com
    dch -n

  2. vivek Says:

    Scott,

    devscripts make the life of a Debian Package really easy.

  3. housetier Says:

    When I build from source, I create a build script that sets the environment variables and then executes debian/rules. That way I don’t have to find the correct setting again, when I build anew some time later. The script lives in ~/bin and thus is easily found.

  4. atul_iims Says:

    i have one query that is i am having one text file which include lots of version like

    likeCompress-Raw-Zlib-2.001.tar.gz
    Compress-Zlib-2.001.tar.gz
    ConsoleKit-0.2.3.tar.gz
    Convert-ASN1-0.20.tar.gz
    Crypt-SSLeay-0.51.tar.gz

    my problem is how to extract string one place like
    Compress-Zlib & version in other file 2.001.tar.gz
    please if you have any idea about this please mail me

  5. Nilesh Says:

    Is this possible for Fedora 7+ ?

  6. vivek Says:

    Use rpmbuild under RHEL / CentOS / Suse / Fedora Linux

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , , , , , , , , , ,

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.