How to Compile and Create Binary deb Installer from Source Files tar.gz tar.bz2 in Ubuntu


This simple tutorial would show how to compile source tarballs (*.tar.gz, *.tar.bz2) and create a *.deb installer in Ubuntu.


Make sure you have dh_make and build-essentials installed in your system. To install those in Ubuntu, run below commands:

sudo apt-get install dh-make
sudo apt-get install build-essential

How to create deb file from source packages (e.g tar.gz files)

Follow below steps to compile and create deb file from source package in Ubuntu.

    Setup test directory

  • Create a folder which can be used to keep the source files and other files. You can have it named anything you want. For this tutorial I have named it as “testbox” and kept it in Desktop. Also I will use the source of a software called “qgifer-0.2.1”, this software is used to create gif files from video files. I have downloaded the qgifer-0.2.1-source source files from SF.
  • testbox folder created in desktop

  • Keep your source file (i.e. the compressed tar file) inside testbox folder. Extract the compressed source files.
  • with source extracted

  • You can keep the extracted folder name as it is OR you can change it. For this tutorial I will change the folder name from qgifer-0.2.1-source to qgifer-0.2.1. While renaming the source directory make sure to follow rules: only use lower case letters, numbers, plus, dot and minus characters.
  • Delete the source tar file. We don’t need it anymore.
  • At this stage, your test directory should look like this.
  • start

    Creation of a deb file requires “debian” directory and all the necessary minimum contents of it inside the source directory. Also the source directory should contain the launcher i.e. *.desktop file to make entries in menu and including icon. Typically all the source tarballs comes with these files and sometimes the debian directory and its contents as well.

  • Change any path to destination in source files or in the *.desktop file. E.g. for below desktop file, possible changes you may want to is the “Categories” and “Icons”.
  • desktop file look

  • After all change is done, compress the entire source folder to a tar.gz file type. Then copy the tar.gz file inside the source folder. Then delete the tar.gz file outside of the source folder.
  • copy and delete tar

    Configure debian directory

  • Open terminal and go inside the source folder and run below command to create the basic “debian” directory structure with default values.
  • dh_make -e -c gpl3 -f qgifer-0.2.1.tar.gz 

    Note: You can put down your actual valid email address.
    The above command will ask for certain values:
    Type of package: Choose s for single binary
    dh_make how

  • If you now go back to the source directory, you can see a directory named debian is created with bunch of files inside it. Also a file named *.orig.tar.gz s created outside of the source directory.
  • after dh_make

    after dh_make 2

    Now we need to edit the contents of the created ‘debian’ directory just been created. While compiling a source package, everything depends on the contents of this directory. So it is very important to update the contents as per your needs. Debian packaging is a complex process and has many options to customize a compilation based on user needs. This tutorial would try to keep is as simple as possible to have the concept in place.

  • If you open the debian directory created by dh_make, you can see some files with extension *.ex and other files. These ex files are example files that can be used by modifying them and removing ex extension. If they are not needed, they can be deleted. For this tutorial, we will delete all the ex files and README files.
  • debian dir contents 1

    debian dir contents 2

  • The minimum recommended files needed to compile a source tarballs are: changelog, compat, control, copyright, rules.
  • We need to edit each of these files as per our source tarball. Open all these files in a text editor.
  • changelog is the log of changes in the debian package. It contains the source package name, version, target version, bug number.
  • Before change

    qgifer (0.2.1-1) unstable; urgency=low
      * Initial release (Closes: #nnnn)  
     -- arindam   Thu, 11 Feb 2016 22:37:44 +0530

    After change

    qgifer (0.2.1-1) vivid; urgency=low
      * Initial release (Closes: #1234)  <1234 is the bug number of your ITP>
     -- arindam   Thu, 11 Feb 2016 22:37:44 +0530
  • control file describes source and binary package. It contains information about package name, architecture, dependencies etc. See below for the section descriptions and changes.
  • Before Change
    debian control file change
    After Change

    Source: qgifer
    Section: Graphics
    Priority: optional
    Maintainer: arindam 
    Build-Depends: debhelper (>= 9), libopencv-dev (>= 2.3), libgif-dev (>=4.1), libqt4-dev (>= 4.8.0), cmake (>= 2.6)
    Standards-Version: 3.9.4
    #Vcs-Git: git://
    Package: qgifer
    Architecture: any
    Depends: ${shlibs:Depends}, ${misc:Depends}
    Description: A video-based animated GIF creator
     Creates GIF from a video file.

    Note: Check the readme files of the source package for dependencies needed for the package. Make sure to install all the dependencies in the your system where you are compiling the source before you proceed further.

  • rules file is the most complicated one. However, dh_make makes it as simple as possible. For this tutorial we did not make any changes to it.
  • #!/usr/bin/make -f
    # -*- makefile -*-
    # Uncomment this to turn on verbose mode.
    #export DH_VERBOSE=1
    	dh $@ 

    Note: For sample rule files, go to /usr/share/doc/debhelper/examples.

  • Keep other files unchanged for now, they are source/format, copyright, docs and compat.
  • Save all the changes.
  • Delete the tar.gz file from inside the source folder. This is very important. If you don’t delete this, next buildpackage command will fail with below error.
  • dpkg-source: info: using source format `3.0 (quilt)'
    dpkg-source: info: building qgifer using existing ./qgifer_0.2.1.orig.tar.gz
    dpkg-source: error: cannot represent change to qgifer-0.2.1.tar.gz: binary file contents changed
    dpkg-source: error: add qgifer-0.2.1.tar.gz in debian/source/include-binaries if you want to store the modified binary in the debian tarball
    dpkg-source: error: unrepresentable changes to source
    dpkg-buildpackage: error: dpkg-source -b qgifer-0.2.1 gave error exit status 2


  • Now its time to build the package. Go to source folder from terminal and run below command. We are using fakeroot and not sudo due to various permission issues may occur in target installation system after compile. It is recommended not to use sudo while running dpkg-buildpackage.
  • fakeroot dpkg-buildpackage -F
  • dpkg-buildpackage command will take some time to compile the source depending on how big your project is. Once the command is complete, go one level up from the source folder where you can see bunch of files have been created including the *.deb file for your package. You can now double-click to install the deb file in your system.
  • final deb

You may also like...

Translate »