Debian Packages Tutorial (2/2)
Binary Packages

Introduction

On this page we show how to create two basic Debian binary packages using dpkg-deb.

An Empty Binary Package

We will start with an example of the minimum needed to successfully create a package using the dpkg-deb tool.

This example will be built incrementally by executing dpkg-deb --build until it doesn't report any errors and successfully creates a package. The resulting package will be a package that can be installed but is actually empty so no files will be installed.

Step 1

Let's start by running dpkg-deb --build as shown below.

Step 1 commands

xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ dpkg-deb --build
dpkg-deb: error: --build needs a <directory> argument

Type dpkg-deb --help for help about manipulating *.deb files;
Type dpkg --help for help about installing and deinstalling packages.
xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ 

dpkg-deb --build complains that no directory was provided because it expects as argument a directory where the package metdata and contents are stored.

Step 2

We attempt to fix the issue reported at step 1 by creating a directory that we name "empty1" and then run dpkg-deb --build empty1.

Step 2 commands

xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ mkdir empty1
xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ dpkg-deb --build empty1
dpkg-deb: error: failed to open package info file 'empty1/DEBIAN/control' for reading:
No such file or directory
xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ 

dpkg-deb --build now complains about not finding the "control" file. The control file stores the package metadata including basic information such as the package name, author and version. We will see what goes in the control file shortly.

Step 3

We create an empty "empty1/DEBIAN/control" file and rerun dpkg-deb --build.

Step 3 commands

xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ mkdir empty1/DEBIAN
xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ touch empty1/DEBIAN/control
xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ dpkg-deb --build empty1
dpkg-deb: error: no package information in 'empty1/DEBIAN/control'
xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ 

The control file is now found but it is missing a required piece of information: the package field.

Step 4

We edit the control file and add a package field to it. The package field contains the name of the package.

File: empty1/DEBIAN/control at step 4

Package: empty1

We run dpkg-deb --build yet again and now it complains about three more missing fields: description, maintainer and version.

Step 4 commands

xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ dpkg-deb --build empty1
dpkg-deb: warning: parsing file 'empty1/DEBIAN/control' near line 2 package 'empty1':
 missing description
dpkg-deb: warning: parsing file 'empty1/DEBIAN/control' near line 2 package 'empty1':
 missing maintainer
dpkg-deb: error: parsing file 'empty1/DEBIAN/control' near line 2 package 'empty1':
 missing version
xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ 

Step 5

We add the description, maintainer and version fields as shown below.

File: empty1/DEBIAN/control at step 5

Package: empty1
Description: A dpkg sample package
Maintainer: Xavier Leclercq <xavier.leclercq@needfulsoftware.com>
Version: 1.1-1

We run dpkg-deb --build and it now complains about the absence of the architecture fields but it actually created the package now as this is only a warning. However we're going to add this field just to avoid any warnings.

Step 5 commands

xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ dpkg-deb --build empty1
dpkg-deb: warning: parsing file 'empty1/DEBIAN/control' near line 5 package 'empty1':
 missing architecture
dpkg-deb: warning: ignoring 1 warning about the control file(s)
dpkg-deb: building package 'empty1' in 'empty1.deb'.
xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ 

Step 6

We now make the final addition to the control file as shown below. This is the minimal control file that will build a binary package successfully without any warnings and will be the final version of this example. The full example is available from our Codeplex repository at dpkg/empty1.

File: empty1/DEBIAN/control

Package: empty1
Description: A dpkg sample package
Maintainer: Xavier Leclercq <xavier.leclercq@needfulsoftware.com>
Version: 1.1-1
Architecture: all

We run dpkg-deb --build one last time to create the final working version of our minimal binary package.

Step 6 commands

xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ dpkg-deb --build empty1
dpkg-deb: building package 'empty1' in 'empty1.deb'.
xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$

Using dpkg with the empty package

We can now show that the empty package we have just created can be used successfully with dpkg.

First we will install the package as shown below.

Installing the empty package

xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ sudo dpkg -i empty1.deb
[sudo] password for xl: 
Selecting previously unselected package empty1.
(Reading database ... 245539 files and directories currently installed.)
Preparing to unpack empty1.deb ...
Unpacking empty1 (1.1-1) ...
Setting up empty1 (1.1-1) ...
xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ 

The package is now installed and we can get its details as shown below.

Getting the information about the installed empty package

xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ dpkg -s empty1
Package: empty1
Status: install ok installed
Maintainer: Xavier Leclercq <xavier.leclercq@needfulsoftware.com>
Architecture: all
Version: 1.1-1
Description: A dpkg sample package
xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ 

We can also get the list of files belonging to the package and as expected it is empty.

Getting the list of files belonging to the empty package

xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ dpkg -L empty1
/.
xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ 

And finally we can uninstall the empty package.

Removing the empty package

xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ sudo dpkg -r empty1
(Reading database ... 245538 files and directories currently installed.)
Removing empty1 (1.1-1) ...
xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ dpkg -s empty1
dpkg-query: package 'empty1' is not installed and no information is available
Use dpkg --info (= dpkg-deb --info) to examine archive files,
and dpkg --contents (= dpkg-deb --contents) to list their contents.
xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ 

A Binary Package with a Single File

Now that we have successfully built a minimal package let's see another very basic example. Our next binary package will install a single text file in "/usr/share/singlefile1/file1.txt". The full example is available from our Codeplex repository at dpkg/singlefile1.

Creating the package

For this example the directory we will build the package from will be called "singlefile1". The control file is very similar to the one we created for the empty package, only the package name has been changed. The complete file is shown below.

File: singlefile1/DEBIAN/control

Package: singlefile1
Description: A dpkg sample package
Maintainer: Xavier Leclercq <xavier.leclercq@needfulsoftware.com>
Version: 1.1-1
Architecture: all

Adding files to a binary package is easy. We simply put the file at the right place in the "singlefile1" directory. The relative path of the file will become the absolute path of the file when the package is installed. So in our case since we want to install the file in "/usr/share/singlefile1/file1.txt" we place the file in "singlefile1/usr/share/singlefile1/file1.txt". The contents of the file are shown below but they don't matter much, it's just a simple text file.

File: singlefile1/usr/share/singlefile1/file1.txt

Hello World!

The binary package is now ready to be built.

Building the package

xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ dpkg-deb --build singlefile1
dpkg-deb: building package 'singlefile1' in 'singlefile1.deb'.
xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ 

Installing the package

The package can now be installed with dpkg.

Building the package

xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ sudo dpkg -i singlefile1.deb 
Selecting previously unselected package singlefile1.
(Reading database ... 245539 files and directories currently installed.)
Preparing to unpack singlefile1.deb ...
Unpacking singlefile1 (1.1-1) ...
Setting up singlefile1 (1.1-1) ...
xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ 

Once the package is installed you can verify that the file has been copied to "/usr/share/singlefile1/file1.txt".

Checking that the file has been installed.

xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ ls /usr/share/singlefile1/
file1.txt
xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ 

Getting the package details

We can also use dpkg -s to get the package details once it's been installed.

Getting the package information.

xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ dpkg -s singlefile1
Package: singlefile1
Status: install ok installed
Maintainer: Xavier Leclercq <xavier.leclercq@needfulsoftware.com>
Architecture: all
Version: 1.1-1
Description: A dpkg sample package
xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ 

And we can see the list of files in the package with dpkg -L.

Getting the files belonging to the package.

xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ dpkg -L singlefile1
/.
/usr
/usr/share
/usr/share/singlefile1
/usr/share/singlefile1/file1.txt
xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ 

And we finish by removing the package.

Removing the package.

xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$ sudo dpkg -r singlefile1
(Reading database ... 245540 files and directories currently installed.)
Removing singlefile1 (1.1-1) ...
xl@Sojourner:~/GitRepositories/needfulsoftwaretutorials/dpkg$

Further Reading


blog comments powered by Disqus

Copyright(c) 2006-2015 Xavier Leclercq | Privacy policy

Home
Contact Us
Search