Howto: create a deb package

Write tutorials and howtos in here
There are more tutorials here
Forum rules
Do not start a support topic here please. Before you post please read this

Howto: create a deb package

Postby Bas King on Wed Apr 16, 2014 3:48 am

Creating a package for debian/mint is a little bit confusing for noobs like me, so I did some research and created this howto.
It packages one single command, that just echos some line.

Go to home directory (or any location you have all permissions to)
Code: Select all
cd ~

Create a new folder, testpackage, with inside a folder structure /usr/bin, where the command shall be after install.
The file structure inside 'testpackage' will be re-created in the real file hierarchy, all files included, once the package gets installed.
Code: Select all
mkdir -p testpackage/usr/bin

Create a very simple command, for demonstration purposes. This will just echo a line of text.
Code: Select all
echo '#!/bin/sh
echo "Running Some Command..."' > testpackage/usr/bin/somecommand

Inspect it:
Code: Select all
cat testpackage/usr/bin/somecommand

Should return:
echo "Running Some Command..."

Run it with bash:
Code: Select all
bash testpackage/usr/bin/somecommand

Should return:
Running Some Command...

Run it 'as is'
Code: Select all

Will return:
bash: testpackage/usr/bin/somecommand: Permission denied

We have already hinted to use #!/bin/sh in the first line (the shebang). But to invoke it directly we also, as superuser, have to set the 'allow execution' flag of the file with chmod: for owner (Read+Write+eXecute=7), group-members (Read+eXecute=5), and the rest (Read+eXecute=5) (See ) like this:
Code: Select all
sudo chmod 755 testpackage/usr/bin/somecommand

Run it 'as is' again:
Code: Select all

Should now return:
Running Some Command...

Try to build it:
Code: Select all
dpkg-deb --build testpackage

dpkg-deb: error: failed to open package info file `testpackage/DEBIAN/control' for reading: No such file or directory

To create control file, first create DEBIAN folder:
Code: Select all
mkdir -p testpackage/DEBIAN

Then create control file there (use your email and name):
Code: Select all
echo 'Package: testpackage
Version: 1.1-1
Section: education
Priority: optional
Architecture: all
Maintainer: Your Name <>
Description: Almost empty test package.
 This package is only used
 to show how packages work.' > testpackage/DEBIAN/control

Try to build package again:
Code: Select all
dpkg-deb --build testpackage

Should return:
dpkg-deb: building package `testpackage' in `testpackage.deb'.

So, all is fine? Not so! Lets install lintian:
Code: Select all
sudo apt-get install -y lintian

And inspect our package with it
Code: Select all
lintian testpackage.deb

Will return:
E: testpackage: debian-changelog-file-missing
E: testpackage: no-copyright-file
E: testpackage: wrong-file-owner-uid-or-gid usr/ 1000/1000
E: testpackage: wrong-file-owner-uid-or-gid usr/bin/ 1000/1000
E: testpackage: wrong-file-owner-uid-or-gid usr/bin/somecommand 1000/1000
W: testpackage: binary-without-manpage usr/bin/somecommand

To handle the E: testpackage: debian-changelog-file-missing, create folder /usr/share/doc/PACKAGENAME inside package:
Code: Select all
mkdir -p testpackage/usr/share/doc/testpackage

Create initial changelog, note: SPACES MATTER! 2 spaces before each *, 1 space before --, 2 spaces between email and date like so:
Code: Select all
echo 'testpackage (1.1-1) unstable; urgency=low
  * Initial Release. Closes: #14223
 -- Your Name <>  Fri, 11 Apr 2014 08:38:32 +0100' > testpackage/usr/share/doc/testpackage/changelog.Debian

Must be gzipped with maximum compression:
Code: Select all
gzip -9 testpackage/usr/share/doc/testpackage/changelog.Debian

To handle the E: testpackage: no-copyright-file, I choose GPL-2: ... reLicenses
(no compressing is allowed on this file, it should be readily readable):
Code: Select all
echo 'This package was first put together by Your Name <> in 2014.

testpackage is Copyright (C) 2014 Your Name <>.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the
    Free Software Foundation, Inc.,
    51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.

On Debian GNU/Linux systems, the complete text of the GNU General
Public License can be found in "/usr/share/common-licenses/GPL-2".' > testpackage/usr/share/doc/testpackage/copyright

Now the W: testpackage: binary-without-manpage usr/bin/somecommand
Code: Select all
mkdir -p testpackage/usr/share/man/man1

Code: Select all
echo '.\" Manpage for somecommand.
.\" Contact to correct errors or typos.
.TH SOMECOMMAND 1 "11 Apr 2014" "1.1-1" "somecommand man page"
somecommand \- just some command.
.B somecommand
Somecommand is an stub command to show how a packages works. It simply echoes "Running Some Command..."
Somecommand does not take any options.
No known bugs.
Your Name (' > testpackage/usr/share/man/man1/somecommand.1

Check to see if the manpage makes any sense:
Code: Select all
man -l testpackage/usr/share/man/man1/somecommand.1

Zip with maximum compression:
Code: Select all
gzip -9 testpackage/usr/share/man/man1/somecommand.1

Now the wrong-file-owner-uid-or-gid errors: as superuser, CHange the OWNer and group of all files in the package folder to root:root, recursively (-R):
Code: Select all
sudo chown -R root:root testpackage

Code: Select all
dpkg-deb --build testpackage

And inspect our package
Code: Select all
lintian testpackage.deb

Should return: nothing!
No errors or warnings! Hurray!

Now we can install package as superuser (admin):
Code: Select all
sudo dpkg -i testpackage.deb

Try out our command:
Code: Select all

Should now return:
Running Some Command...

Check your PATH variable for /usr/bin
Code: Select all
echo $PATH

Normally /usr/bin is already in your PATH, so you can run commands from /usr/bin from anywhere without having to give the full path. Just try:
Code: Select all

Should also return:
Running Some Command...

And try the manual-page for it like so:
Code: Select all
man somecommand
Bas King
Level 1
Level 1
Posts: 7
Joined: Mon Jan 20, 2014 2:38 am

Linux Mint is funded by ads and donations.

Return to Tutorials / Howtos

Who is online

Users browsing this forum: No registered users and 9 guests