In this tutorial I will be showing how to build a basic Debian package from source code. For the example I chose Midori 0.50 which is the latest release of small and fast web-browser branch.
Midori is a good choice if you run hardware which does not get along very well with high system and resource demands or if you just want a fast web browser which does it’s job well.
1. First step: Get the tools to build a package
sudo apt-get install devscripts build-essential make fakeroot automake dh-make subversion git-core
Note: Depending on your needs you might need more tools than above but these should get you started very well.
2. Get the source code of the program you are going to package and safe it to a “good location”
Once we get down to packaging things we first need to provide some clear location where we can actually place the sources easily without mixing them up with the other stuff inside our home folder so create a folder where you can but your source code. For example in terminal as a regular user:
mkdir source
Now it is time to get the source code in to our newly created folder and then unzip it
Download the midori source archive from here http://twotoasts.de/index.php/midori// and place it inside the source folder as an archive and also as an unzipped folder.
3. Building the Debian package
cd in to the newly created midori directory which is now inside the source directory we created moments ago. Once you are inside the midori directory the fun of building a package can begin. First we need to prepare the archive and our midori directory to debianization with dh_make
dh_make -f place_the_full_path_of_midori_archive.tar.bz2_here
Example: dh_make -f ‘/home/tester/source/midori-0.50.tar.bz2’
Next we will see the following notes:
Type of package: single binary, indep binary, multiple binary, library, kernel module, kernel patch?
[s/i/m/l/k/n]
Note: Choose s here
And then we will see something like this:
Maintainer name : Tester
Email-Address : tester@debian
Date : Sun, 21 Apr 2013 03:17:31 +0300
Package Name : midori
Version : 2.32.2
License : blank
Type of Package : Single
Hit <enter> to confirm:
Just hit enter here. We will edit the entries later.
The process of dh_make will end with this note:
Done. Please edit the files in the debian/ subdirectory now. midori
uses a configure script, so you probably don’t have to edit the Makefiles.
The debian directory which has now appeared inside our midori directory is the one we are going to tweak. It contains three files which we are especially interested. Some basic explanations about the contents of these files are given below.
1. The control file: this file tells, for example, what is the package name, what are it’s build time dependencies and what is the general purpose of the package.
2. changelog: What changes were made to the source code? What is the version number of the package? Who uploaded/packaged it for Debian and when was it done?
3. copyright: What is the copyright? You can usually find a file COPYRIGHT inside the original source code so you can just rename it as copyright and replace
the skeleton copyright file with it (the skeleton copyright file is inside the debian directory). NOTE: in some cases the copyright file might be implanted correctly
inside the debian directory by dh_make. So if you are lucky you do not need to edit anything there.
Modifying the control file.
As we are still inside the midori directory we can start the tweaking of the control file. First we need to check the program’s (midori) build-dependencies. In terminal:
dpkg-depcheck ./configure
The previous command checks if the configuring of the midori program can be done and then gives a list of the packages which are needed to in order to build midori. In some cases the dependency list can be quite big but luckily then you can take a shortcut and tell apt-get to find all the needed dependencies of the program x
in terminal as root or sudo:
apt-get build-dep x –> where x is the name of the program
To make things easier to follow see my midori control file example below.
Source: midori
Section: main
Priority: extra
Maintainer: JJ Posti <>
Build-Depends: debhelper (>= 8.0.0), autotools-dev, hardening-wrapper, libxext-dev:i386, libxfixes-dev, libmpc2:i386, libglib2.0-0:i386, libjavascriptcoregtk-1.0-dev, libcairo2-dev, libvala-0.16-0:i386, libxcb1:i386, libxml2-dev:i386, cpp-4.7, gcc-4.7, locales, libxss-dev:i386, perl-modules, python-support, libxinerama-dev:i386, binutils, coreutils, libnotify-dev, x11proto-fixes-dev, libxdmcp-dev:i386, libfreetype6-dev, python2.7, x11proto-damage-dev, x11proto-input-dev, libxrender-dev:i386, libx11-dev:i386, libffi5:i386, libpixman-1-dev, libxcomposite-dev, libsoup2.4-dev, libxdmcp6:i386, libpango1.0-dev, libc-bin, python-gst0.10, x11proto-composite-dev, x11proto-randr-dev, x11proto-core-dev, libwebkitgtk-dev, libpthread-stubs0-dev:i386, libxau-dev:i386, libxi-dev, libxau6:i386, libgtk2.0-dev, libxcursor-dev:i386, libgdk-pixbuf2.0-dev, libglib2.0-dev, libatk1.0-dev, x11proto-scrnsaver-dev, libunique-dev, python2.7-minimal, debianutils, x11proto-xext-dev, pkg-config, libc6:i386, dash, x11proto-kb-dev, libxext6:i386, python-gobject-2, x11proto-xinerama-dev, libfontconfig1-dev, python-minimal, libxrandr-dev, libgcc1:i386, libgmp10:i386, libc6-dev:i386, libxcb1-dev:i386, perl-base, libssl1.0.0:i386, libxcb-shm0-dev:i386, libxcb-render0-dev:i386, libpcre3:i386, libmpfr4:i386, libpng12-dev, libsqlite3-dev, linux-libc-dev:i386, x11proto-render-dev, libpopt0:i386, libpcre3-dev:i386, libzeitgeist-dev, zlib1g:i386, gcc, libx11-6:i386, libxdamage-dev
Standards-Version: 3.9.4
Homepage: http://twotoasts.de/index.php/midori//
#Vcs-Git: git://git.debian.org/collab-maint/midori.git
#Vcs-Browser: http://git.debian.org/?p=collab-maint/midori.git;a=summary
Package: midori
Architecture: i386
Version: 12:0.5.0
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: Midori is a lightweight web browser. i386 for personal use.
Some elaborations about the fields:
Maintainer field. Of course change the name of maintainer to something else. If you want to place your email address to the package’s contact information but it inside the <>
Build-Depends. Build time dependencies. The entries listed here are the dependencies needed to build the program we are currently trying to build as Debian package.
Package: The name of the package once it is installed in the system.
Architecture. Which architecture the computer operation system is running? Common options are i386 (32bit) and amd64 (64bit)
Depends. The programs you put here will be installed alongside your package.
Note: If you get an error saying field something is not found in control then you need the check your control file. This error usually means that your Debian control file is incorrectly formatted. For example the control while formatted as below would most certainly cause an error during the build of Midori:
Source: midori
Section: main
Priority: extra
Maintainer: JJ Posti <>
Build-Depends: debhelper (>= 8.0.0), autotools-dev, hardening-wrapper, libxext-dev:i386, libxfixes-dev, libmpc2:i386, libglib2.0-0:i386, libjavascriptcoregtk-1.0-dev, libcairo2-dev, libvala-0.16-0:i386, libxcb1:i386, libxml2-dev:i386, cpp-4.7, gcc-4.7, locales, libxss-dev:i386, perl-modules, python-support, libxinerama-dev:i386, binutils, coreutils, libnotify-dev, x11proto-fixes-dev, libxdmcp-dev:i386, libfreetype6-dev, python2.7, x11proto-damage-dev, x11proto-input-dev, libxrender-dev:i386, libx11-dev:i386, libffi5:i386, libpixman-1-dev, libxcomposite-dev, libsoup2.4-dev, libxdmcp6:i386, libpango1.0-dev, libc-bin, python-gst0.10, x11proto-composite-dev, x11proto-randr-dev, x11proto-core-dev, libwebkitgtk-dev, libpthread-stubs0-dev:i386, libxau-dev:i386, libxi-dev, libxau6:i386, libgtk2.0-dev, libxcursor-dev:i386, libgdk-pixbuf2.0-dev, libglib2.0-dev, libatk1.0-dev, x11proto-scrnsaver-dev, libunique-dev, python2.7-minimal, debianutils, x11proto-xext-dev, pkg-config, libc6:i386, dash, x11proto-kb-dev, libxext6:i386, python-gobject-2, x11proto-xinerama-dev, libfontconfig1-dev, python-minimal, libxrandr-dev, libgcc1:i386, libgmp10:i386, libc6-dev:i386, libxcb1-dev:i386, perl-base, libssl1.0.0:i386, libxcb-shm0-dev:i386, libxcb-render0-dev:i386, libpcre3:i386, libmpfr4:i386, libpng12-dev, libsqlite3-dev, linux-libc-dev:i386, x11proto-render-dev, libpopt0:i386, libpcre3-dev:i386, libzeitgeist-dev, zlib1g:i386, gcc, libx11-6:i386, libxdamage-dev
Standards-Version: 3.9.4
Homepage: http://twotoasts.de/index.php/midori//
#Vcs-Git: git://git.debian.org/collab-maint/midori.git
#Vcs-Browser: http://git.debian.org/?p=collab-maint/midori.git;a=summary
Package: midori
Architecture: i386
Version: 12:0.5.0
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: Midori is a lightweight web browser. i386 for personal use.
Modifying the changelog file
An example of my changelog file is seen below.
midori (12:0.5.0-1) unstable; urgency=low
* Initial release (Closes: #nnnn) <nnnn is the bug number of your ITP>
— JJ Posti <> Mon, 11 Mar 2013 01:55:03 +0200
See the entry midori (12:0.5.0-1). The 12 directly in front of the version numbering prevents the system from upgrading our custom built midori to the version which might be available in repositories. Of course the value in front of version numbering can be anything you desire as long as it is a number which is higher than the one available in repositories. Note: You should also change the maintainer/builder from the changelog for the obvious reasons.
Building the package
As we are still inside our midori directory we are going to build our Debian package with a simple terminal command (as a normal/regular user)
debuild -i -us -uc -b
More from debuild see the man pages: man debuild
If we do not want to use debuild we can alternatively use a bit less complex command to build our package:
dpkg-buildpackage -rfakeroot
More from dpkg-buildpackage see the man pages: man dpkg-buildpackage
In short the difference of the commands is that debuild does more checks to verify the build integrity and the quality and dpkg-buildpackage skips some of them.Once you are done you should have your debian package inside the source directory which we created when we began. You can install the package with graphical tool like gdebi or via terminal as root or sudo by doing the following
dpkg -i packagename.deb
If you get errors while installing in terminal saying that some dependency is not found just do: apt-get -f install and all should be fine.