
How-to: Create and Distribute .deb files
Almost everyone knows what a .deb package is. It's the "installer" for Ubuntu, Debian, MEPIS, and many other Linux distros. In my opinion, it's the best package format out there (Red Hat and Gentoo users may beg to differ!). Unfortunately, many Linux programs don't include a .deb package. They give you only the source code, which often requires downloading bunches of libraries you've never heard of (dependency hell is the term), and they often don't give you the option to uninstall the program. However, it is much easier than you may expect to put together a .deb from scratch.
CheckInstall and Debian Package Tools FE
The easiest (and worst) way is to use a .deb packaging program called CheckInstall. It sounds great on the outside. All you have to do is run make (like you usually would) to compile the source code, then run checkinstall to create the .deb. Unfortunately, there are several problems. First, it will not install dependencies (you can try AutoApt or AutoDeb, both experimental) and it will not let you declare dependencies - so it will not work for other users unless they manually install the dependencies. Therefore, to make quality packages, CheckInstall is the wrong way to go. If, on the other hand, you're just interested in creating basic packages without hassle, CheckInstall can be useful. However, I will not be covering CheckInstall in this article (tutorial at https://help.ubuntu.com/community/CheckInstall).
So is there any other easy way to create quality packages? There's Debian Package Tools FE, a Qt-based app that provides a basic GUI for making packages. It's much better than CheckInstall, but it's still not the way to create a quality package.
Manually creating packages
The first step in manually creating a .deb package is to download the program. Next, compile it (if necessary), and install it. This usually involves running ./configure, make, and sudo make install. Then, find out where it installed itself - open the Makefile file in a text editor, and read the install section. If you can't find it, look around in the /usr/ folder.
Now, it's time to create the control file. Basically, this is the .deb description. Here's a sample control - you need to paste it into a file called "control", without any extension:
Package: fungame
Version: 1.0
Section: games
Priority: optional
Architecture: i386
Essential: no
Depends: libfungame, gamelibrary (>= 1.4.0)
Recommends: fungamesaves1 | fungamesaves2
Suggests: optionalfungame
Installed-Size: 1024
Maintainer: Game Maker [gamer@gamers.net]
Conflicts: stupidfungamethatbreaksthisone
Replaces: oldfungame
Description: A short description of the program
.
A longer description.
Note several things. First, you NEED to have a blank line at the end. This is ESSENTIAL. If you don't, your .deb won't work.
The fields themselves are pretty obvious.
The Package field is the name of the package. If your package name has two words, use a hyphen (-) between them. Package names can have only lowercase letters, numbers, and (believe it or not) "+" and "-".
The Version section is obviously the version of the program. Just make sure you DON'T include a hyphen (-).
The Section field is a list of the categories your program fits in. This includes admin, games, gnome, kde, mail, misc, net, sound, text, utils, and web.
The Priority section denotes what priority it is - most of the time you'll want optional.
Architecture is the architecture the program will run on - usually i386, amd64, and powerpc. Essential is whether it's essential or not - most of the time it's no. Depends, Recommends, and Suggests are all similar. Depends means that your program MUST have that program, Recommends means that your program should probably have it but doesn't NEED it, and Suggests means that it would be nice to have it. You can separate the different dependencies with commas (,). If one of two programs will work, separate them with a |. You can also add a specific version in parenthesis, using << (earlier), <= (earlier or equal to), = (equal to), >= (greater than or equal to), or >> (greater than).
Installed-Size is the size of the program in kilobytes when it is installed.
Maintainer is you (your first name followed by your email in []).
Conflicts shows packages that this particular package won't install next to (programs that will break your package), while Replaces shows which packages this program will replace.
Lastly, Description shows your description.
Now that your control file is done, save it in a /DEBIAN folder. For example, if you're building a package, and your working folder is ~/fungame/, you want to put your control in ~/fungame/DEBIAN/.
It's now time to add the actual program. Copy the game into your working folder. For example, if fungame is located in /usr/local/fungame/, and the binary is at /usr/bin/fungame, and your .deb folder is ~/fungame/, copy everything in /usr/local/fungame/ into ~/fungame/usr/local/fungame/, and /usr/bin/fungame into ~/fungame/usr/bin. You may also want to create a menu entry (a .desktop file), in ~/fungame/usr/share/applications/fungame.desktop. Here's an example of a .desktop:
[Desktop Entry]
Type=Application
Version=1.0
Encoding=UTF-8
Name=Fun Game
Exec=fungame
Comment=
Icon=/usr/local/fungame/fungame.png
Terminal=false
Categories=Application;Game;
StartupNotify=false
MimeType=
If you wish, you can omit the Icon= line.
Now, it's finally time to build your package. To do this, cd to your working folder (e.g. ~/fungame/) and, in a terminal window, run dpkg -b directory packagename.deb. The directory is your directory, e.g. ~/fungame/, and the packagename.deb is the name of the package that will be built. It is critical that you name your package correctly. Here's the proper naming convention:
program-name_version_architecture.deb.
Everything should be identical to their equivalents in the control file.
Distributing you package
Your package will get maximum attention if it's available from packages.debian.org and packages.ubuntu.com. Unfortunately, you can't just upload packages. You need to be a Debian (or Ubuntu) developer. And this is not an easy process. A long article on the topic is at http://www.linux.com/articles/42155. A simpler way is to get a mentor who will upload the package for you - see http://mentors.debian.net/ for more.
So, what happens if you don't want to spend a long time registering as a Debian/Ubuntu developer? If you read my Top5 column at all, you'll know that I love GetDeb.net. They provide 3rd party .debs, and are the ideal place for a non-Debian or non-Ubuntu programmer to post packages. You can find out how to do this at http://wiki.getdeb.net/Building_Packages. Best of all, you don't need to sign up for anything except a Launchpad account.
Andrew Min has been a Linux addict since he first installed openSuSE in VMWare. Learn more about him at http://www.andrewmin.com/
