Packaging as a .deb

If you’ve been following this blog or the Praxis code site for the last couple of months, you might be forgiven for thinking that not a lot had been happening. Actually that’s far from the case. I’ve been busy with a number of projects, one of which has seen some major additions to the Praxis code, and I’m now in the process of tidying that up for a new release. Some of the audio code has also been extracted and pushed to a separate repository ( of which more soon … but I digress. One thing that changed with the last Praxis LIVE release is that by default the Linux download is a .deb (Debian binary package) file, and I’ve been meaning to write up a how-to (for my benefit as much as yours!) since. So, here goes.

Grasping for control

To be clear before we start, this is a simple way to package a NetBeans platform application (or any Java application) to be installed as a .deb. I was having issues with using the default Linux installer from the NetBeans platform, particularly since moving to Ubuntu 12.04, and wanted a better way to integrate the install into the system. This is probably definitely not a guide to best practice in packaging .debs, not least because I wanted to keep the general structure of the code (also including Windows binaries for the build harness) intact. Oh, and you’ll have to be doing this on Linux with access to the dpkg tools!

So, firstly you need to create a directory within which to structure your package. This directory should be named according to the Debian package name conventions – <PackageName>_<VersionNumber>-<DebianRevisionNumber>_<DebianArchitecture>. As we’re packaging a Java program (even though it contains some native binaries) we can use architecture All. For Praxis LIVE build:121231 this translated as praxis-live_121231-1_all

Inside this directory you need to mirror the structure of how you want your application to be installed (like so).base deb structure

I decided to have all the code of Praxis LIVE itself installed within /usr/lib/praxis-live, so I created this directory within my package directory and extracted the entire contents of the ZIP build of Praxis LIVE into it. Alongside this, I created symlinks in the /usr/bin directory to point to the launchers in /usr/lib/praxis-live/bin (Praxis LIVE has two launchers, one for GUI use and one for CLI use). These should be created as absolute links to where your files will be, ie. using ln -s /usr/lib/praxis-live/bin/praxis praxis – they’ll show up as broken links if you’ve not installed your application yet! I’ll come on to the /usr/share directory in a moment.

Finally, and most importantly, you need to create the DEBIAN directory. This directory won’t show up in your final installation – it contains the files that control how your .deb is built. The only file necessary in here is called control and is a plain text file containing various properties. The contents of the Praxis LIVE control file are as follows.

Package: praxis-live
Version: 121231-1
Architecture: all
Maintainer: Neil C Smith
Installed-Size: 46000
Depends: openjdk-6-jre | openjdk-7-jre | java6-jre
Priority: optional
Description: Open-source, graphical environment for rapid development of intermedia performance tools, projections and interactive spaces.
 Praxis is a Java-based modular framework for live creative play with video, images, audio, and other media.

The Package, Version and Architecture properties should match those you used for your directory naming earlier. The Depends line lists packages that we rely on – here this just requires one of the specified JRE packages. Priority should almost certainly be optional (user installed software). The rest should be fairly self-explanatory – the description can go onto multiple line, with subsequent lines indented.

Can you share some more?

The /usr/share directory contains various files to help integrate your application into the system. These are structured as here.deb share structure

The most important file is the .desktop file in /usr/share/applications  This will install your application in the menu when your .deb is installed.  The contents of the Praxis LIVE .desktop file are

[Desktop Entry]
Name=Praxis LIVE
Comment=Praxis LIVE

Again this should be fairly explanatory. The Icon property just needs the file name and will search for the correct icons under the icons directory as shown. The Exec property points to the actual command that will be run when your desktop item is selected in the menu or elsewhere.

The file at /usr/share/doc/<package>/copyright is just a plain text file with copyright information.

The slightly more cryptic file at /usr/share/lintian/overrides/<package> actually controls how the package is checked during the build process, and stop it complaining about certain things we’re doing that are not following Debian packaging guidelines to the letter (such as including native binaries in an architecture all package). The current Praxis LIVE override file contains the following four items

praxis-live: arch-independent-package-contains-binary-or-object
praxis-live: missing-dependency-on-libc
praxis-live: debian-changelog-file-missing
praxis-live: extended-description-is-empty

Let’s fake it and finish

And finally, we need to build a .deb file out of our directory. For this you’ll need to ensure you have the dpkg-deb and fakeroot commands available. dpkg-deb does the actual building. However, if you look at the ownership of the files in your directory you’ll notice that they’re owned by your user account and not by root (as with other installed applications). The fakeroot command ensures the files in the .deb are now correctly owned by root.

To build your .deb, open a terminal in the parent directory of your package build directory, and execute the following command (inserting your directory name! 🙂 )

fakeroot dpkg-deb -b <your-package-directory>

All being well you should end up with a nice, installable .deb file next to your directory. It’s probably a good idea to open it in an archive manager and check it’s as expected before testing installation!

Keep hold of your package directory. You can copy & paste it to create your next .deb. Just change the version number in the directory name and control file, and replace everything in /usr/lib

Some light .deb-time reading


One thought on “Packaging as a .deb

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s