Debian Packages

Creating Debian Packages (.deb files) can be tricky business. A .deb file a special file format that holds metadata about the package and its dependencies and the data. The data simply an overlay of the package files to be installed.

Basic Method

The basic method is to create a folder with the name of the new package and then add the program files and metadata. 1

Step 1 Decide on the name of your package. Standard debian notation is all lowercase in the following format:
<project>_<major version>.<minor version>-<package revision>

For example, your first package could be: helloworld_1.0-1

Step 2 Create a directory to make your package in. The name should be the same as the package name.

mkdir helloworld_1.0-1  

Step 3 Pretend that the packaging directory is actually the root of the file system. Put the files of your program where they would be installed to on a system.

mkdir helloworld_1.0-1/usr  
mkdir helloworld_1.0-1/usr/local  
mkdir helloworld_1.0-1/usr/local/bin  
cp "~/Projects/Hello World/helloworld" helloworld_1.0-1/usr/local/bin  

Step 4 Now create a special metadata file with which the package manager will install your program...

mkdir helloworld_1.0-1/DEBIAN  
gedit helloworld_1.0-1/DEBIAN/control  

Put something like this in that file...

Package: helloworld  
Version: 1.0-1  
Section: base  
Priority: optional  
Architecture: i386  
Depends: libsomethingorrather (>= 1.2.13), anotherDependency (>= 1.2.6)  
Maintainer: Your Name <you@email.com>  
Description: Hello World  
 When you need some sunshine, just run this
 small program!

 (the space before each line in the description is important)

Step 5 Now you just need to make the package:

dpkg-deb --build helloworld_1.0-1  

Advanced Method

The other way it build .deb packages is using the debhelper tool suite.

Step 1 Prepare a source code folder for debian packaging

cd my-source-code  
dh_make --createorig  

The dh_make command will create a new debian folder and add a bunch of boilerplate template files. The --createorig will create a tar of the source code. The tar is used by the debhelper scripts to compare diffs later.

The next thing to do is remove a bunch of the option example files:

cd debian  
rm *ex *EX  

Step 2 Configure install step. Most source packages have a install script that copies the binary files to your computer. For example, a lot of source packages use Makefiles and the make install build target to copy binary files to /bin. If your source package does not already have a Makefile with install target, the easiest thing to do is to make one. The dh_auto_install tool will run make install. The $DESTDIR var will point to the path where debhelper scripts are expecting your Makefile to install to ($DESTDIR will resolve to the debian/<package_name>/ inside your source dir).

Step 3 Build the .deb file.

run:

debuild  

If everything goes as expected, there should be a new .deb package created in the parent folder.

Paul Soucy

Read more posts by this author.