Make your own DEB and RPM packages
We’ll show you how to manufacture the two most common types of Linux package for software distribution so you can become your own package maintainer
We’re going to take you through the process of making software packages for the two most popular packing systems, DEB and RPM. You can use these techniques to package your own software or even to become a package maintainer for software projects that you feel are being overlooked.
We’ll start with a guide to building DEB (.deb) files for Debian-derived distributions – we’re using Xubuntu as our base for that. Following that, we’ll detail the methods needed for the creation of RPM packages for use on Red Hat- derived distributions, and we’ll use Fedora for that. You can often create a package on one distribution and then install it on a related one (Ubuntu>Debian, for example), but it might be worth testing it yourself, if this is crucial.
As for the software, we’re going to use Dillo, a lightweight web browser, as an example package to build from source code. As is often the case when building from source, you may have to look around on the web for solutions if the build doesn’t go as it should. For example, in the case of Dillo 3.0.3, we had to add ‘LIBS=-lX11’ to the front of the build commands to get it work, due to an oversight in the source code archive.
Ubuntu & Fedora instalation (or VM)
Step by step
Step 01 Employ a virtual machine
Using a virtualiser such as VirtualBox or VMware is often the best approach to building packages for other systems. For one thing, it allows you to maintain a relatively clean, reference installation that is comparable to a setup that other people are likely to be running. This also means that you can keep a selection of target environments, using a different distributions. In addition, most virtualisation products allow the emulation of different architectures, and this can even extend to running a 64-bit OS on a 32-bit platform, although performance will suffer.
Step 02 Starting from scratch
If things go wrong, with Ubuntu or Fedora, it is perfectly safe to simply delete the source directory and start again. Note that the Debian tools do alter the source archive, so you’ll have to start with a fresh copy.
Part 1: Debian
Step 03 Install build environment
We’ll start by installing most of the tools that we need for to make software from source code. Type:
$ sudo apt-get install build-essential autoconf automake autotools-dev
Now we have to install tools that are used for handling DEB packages. Do this with the following command…
$ sudo apt-get install dh-make debhelper devscripts fakeroot xutils lintian pbuilder
Step 04 Create a GPG key
If you haven’t created a created a public GPG key in the past, you must create one now so that you can sign packages. Start by typing gpg –gen-key. Accept the default settings,and fill in your real name and contact details when prompted. Make a note of these details, as we need an exact match for a later configuration file. Following this, type ls ~/.gnupg to make sure the new key exists (it’s firstname_lastname.gpg). Create a public key from this with:
gpg -a --output ~/.gnupg/[your key].gpg --export '[your name]'
Import this with:
gpg --import ~/.gnupg/[your key].gpg
Step 05 Fetch package
In this example, we’re going to fetch and build the latest version of the Dillo web browser. Navigate to the Dillo website (www.dillo.org) and download the most recent .tar.bz tarball. Create adirectoryforsourcecodewithmkdir ~/srcand move the archive into it.
Step 06 Unpack the archive
Unpack the archive with tar -xjvf [archive name].tar.bz2. Note that the naming conventionofthedirectory(packagename-version) is crucial for our purposes, and fortunately Dillo complies with this. It’s also crucial that the source archive is one level above the source directory.
Step 07 Add Debian compliance
Move into the directory that we have just unpacked with cd. dh_make is a script that takes care of much of work of adding the configuration file and directory structure that we need, and it’s part of the debhelper suite that we added earlier.
dh_make -e [your email address] -c licence -f ../[source language="archive"][/source]
In our example, the command line is:
dh_make -c gpl3 -e firstname.lastname@example.org -f ../dillo-3.0.3.tar.bz2
When prompted, select single binary. The helper script should have created a directory called Debian within the source code directory.
Step 08 Open the control file
Open the file control in the debian subdirectory in a text editor. Fill in the homepage section (Google for complete list of Debian software sections) and description fields of this file.
Step 09 Discover dependencies
You can discover the dependencies needed to run the software in the package by moving into the source directory and typing dpkg-depcheck -d ./configure into a terminal. Doing this may produce errors that indicate that a package needed in order to build the software (a separate issue) is missing. You can discover these packages by typing sudo apt-get build-dep [name of package], and this should help if there is some support for this software in the repository of the distribution. If not, you’ll have to repeatedly run dpkg-depcheck -d ./configure and add packages manually by typing sudo apt-get install [name of package].
Step 10 Add dependencies to the control file
When the command from the previous step has completed, it should present you with a list under the packages needed heading. Add this list of dependencies to the depends: section of the control file. Each item on the list must be separated by a comma and a space.
Step 11 Edit the copyright file
Try to complete this step as comprehensively as you can, and don’t skip it. Source: is usually the homepage of the project. Within the Files: * section, replace the copyright information with the names of the authors of the project. You can see the required format for this by examining the Files: debian/* section, which should have your details in it. You may have to do a bit of detective work to find the information you need. Look for files such as AUTHORS and COPYING within the source directory.
Step 12 Edit the changelog file
Open the changelog file and make sure that the name and email address match those that you entered when creating your GPG key. Typically, the helper script may have added your username rather than your real name to the file. As with the copyright file, don’t skip over this section as doing so may halt the packaging process or lead to a non-compliant package.
Step 13 Edit the changelog file
If everything is set up correctly, we can finally build the DEB. Move into the source directory and type dpkg-buildpackage -b to build the package, which is deposited in the ~/src/ directory. Example package by typing dpkg -I [package]. Run Lintian on it with lintian [package] to check for Debian policy compliance. Note that this tool is notoriously strict and it’s up to you to decide if you can live with some minor non-compliance warnings. Finally, install it with sudo dpgk -i [package].
Part 2: Creating RPMs with Fedora
Step 14 Open the control file
Become root by typing su. Begin with yum groupinstall “Development Tools”,andfollow this up with yum install gcc-c++ fedora- packager. Type usermod -a -G mock
Step 15 Create build environment
Press Ctrl+D to log out of root. Type rpmdev-setuptree to create the directory tree (under ~/rpmbuild) that we need.
Step 16 Fetch the archive and move it
Download Dillo from the Dillo website and move the archive into the into the proper directory by typing mv [name of archive] ~/rpmbuild/SOURCES.
Step 17 Create .spec file
Red Hat derived distros such as Fedora use .spec files to specify the build process. Move into the directory that contains these files with cd ~/rpmbuild/SPECS/andcreateablank.spec filebytypingrpmdev-newspec dillo.
Step 18 Edit .spec file
Type gedit dillo.spec. Fill in the Version, Summary and Licence (GPLv3+ in this case) fields. URL is the project homepage; Source0 is the URL of the source code there. Comment out BuildRequires and Requires. Add a full description in the %description area.
Step 19 Build source code
If the package is supported at all in the system, run yum-builddep [name of package]. Otherwise, you’ll have to repeat the build command to generate errors or search the documentation in the source archive. In the SPEC directory, type rpmbuild -ba [name of package].spec. If this build fails and reports about extra, unpackaged files, cut and paste this list of files into the %files section of the .spec file and repeat the build command. The package is now in the RPMS directory. Type rpm -ivh [package] to install it. Type rpm -qa | grep [package] to make sure that it is installed.