Building a Debian package using dpkg-deb

Posted by Dave on August 21, 2015

Packaging your application allows you to distribute it for users conveniently. One of the benefits, compared to releasing as a compressed archive, is that you can control how and where your binaries will be installed on the target system.

Installing packages on Linux systems can be highly automated which is yet another reason, if you are looking to ‘push’ applications to multiple hosts.

The solution we are going to discuss is okay if you want to use the created package internally. Should you want to publish your package to one of the Debian repositories please carefully study the contribution guidelines.

Resources

  • I followed this ubuntuforum thread to learn the steps (but I added some more steps for validation)
  • I strongly suggest you keep this page open while working on your package configuration

Step 0.

In this example I would like to create a DEB package of a two-liner perl script for testing purposes. Here is the code:

#! /usr/bin/perl

$msg = "So happy to be packaged!\n";
print $msg;

I saved the file to /tmp/basicdebtest (yes without any file extension).

Step 1.

Create a folder for your package.

mkdir -p basicdebtest_1.0-1

Step 2.

We would like to install the script to /usr/local/bin on the user’s system so we need to mimic that file tree here.

mkdir -p basicdebtest_1.0-1/usr/local/bin

Step 3.

Copy the application file(s). In my case this is only the exacutable perl script.

cp /tmp/basicdebtest basicdebtest_1.0-1/usr/local/bin

Step 4.

Create a folder for the package descriptor file.

mkdir -p basicdebtest_1.0-1/DEBIAN

Step 5.

Create the package descriptor file.

vim basicdebtest_1.0-1/DEBIAN/control

This is where the link I gave you comes handy. You want to be able to know what each of the fields mean and which one you can skip. Here is what I what did:

Package: basicdebtest
Version: 1.0-1
Section: base
Priority: optional
Architecture: i386
Maintainer: Dave <weenjoycustomercomplaints@notmydomain.com>
Description: Basic Deb Test
 This was a triumph!
 I'm making a note here:
 Huge success!

Step 6.

Time to build!

dave@dave-desktop:~/Dropbox/Project/Examples$ dpkg-deb --build basicdebtest_1.0-1
dpkg-deb: building package `basicdebtest' in `basicdebtest_1.0-1.deb'.

As a result you should have a new file called: basicdebtest_1.0-1.deb

Step 7.

If you only create packages for personal use you might don’t care too much for validation error. I still strongly encourage you to check what might be missing / erroneous in your setup.

dave@dave-desktop:~/Dropbox/Project/Examples$ lintian basicdebtest_1.0-1.deb
E: basicdebtest: debian-changelog-file-missing
E: basicdebtest: no-copyright-file
W: basicdebtest: unknown-section base
E: basicdebtest: wrong-file-owner-uid-or-gid usr/ 1000/1000
W: basicdebtest: non-standard-dir-perm usr/ 0775 != 0755
E: basicdebtest: wrong-file-owner-uid-or-gid usr/local/ 1000/1000
W: basicdebtest: non-standard-dir-perm usr/local/ 0775 != 0755
E: basicdebtest: wrong-file-owner-uid-or-gid usr/local/bin/ 1000/1000
E: basicdebtest: dir-in-usr-local usr/local/bin/
W: basicdebtest: non-standard-dir-perm usr/local/bin/ 0775 != 0755
E: basicdebtest: wrong-file-owner-uid-or-gid usr/local/bin/basicdebtest 1000/1000
E: basicdebtest: file-in-usr-local usr/local/bin/basicdebtest
W: basicdebtest: file-in-unusual-dir usr/local/bin/basicdebtest
W: basicdebtest: non-standard-executable-perm usr/local/bin/basicdebtest 0775 != 0755

As you can see in my setup I have all those errors (E). I would have to fix these if I were to publish my application into a repository. Warnings might not get your package refused but hey: we know warnings are there for a reason. Try and fix those using the guide.

Step 8.

It’s time to see if we can actually install our package. Let’s simply double click on the file to bring up the package manager (I am using Ubuntu).

Open the package for installation

Step 9.

As you can see the description we configured is used. If you are doing something for real maybe you want to add an image of your application to impress users.

Click “Install”.

Package opened in the package manager

Step 10.

Don’t say I did not warn you! We tried to install a package without fixing the errors. Now we get a warning message indicating something is fishy with the package.

Popup displaying warnings during installation

Go back to Step 7 and fix those problems. After that is done proceed with the installation.

Step 11.

The package should be installed into /usr/local/bin on your machine:

dave@dave-desktop:~/Dropbox/Project/Examples$ ll /usr/local/bin | grep basic
-rwxrwxr-x  1 dave dave   67 aug   21 09:38 basicdebtest*

Step 12.

That means we must be able to execute our little script from anywhere:

dave@dave-desktop:~/Dropbox/Project/Examples$ basicdebtest 
So happy to be packaged!

Thanks for reading my post. If you have some remarks, errata please ping me using the comment section below.

Happy coding!