Creating Debian/Ubuntu .deb packages

In this post, I will show you how to create a .deb package from some binary files.

Step 1: Create the directories
Create a directory for your package. Also, create a directory DEBIAN.

mkdir helloworld && mkdir helloworld/DEBIAN
mkdir helloworld && mkdir helloworld/DEBIAN

Step 2: Copy files into your package
You can copy the files into your package with the full paths on the destination filesystem. E.g. if you want to put a file in /usr/local/bin/ you put it in helloworld/usr/local/bin/

mkdir -p helloworld/usr/local/bin cp /usr/local/bin/helloworld.sh helloworld/usr/local/bin/
mkdir -p helloworld/usr/local/bin cp /usr/local/bin/helloworld.sh helloworld/usr/local/bin/

Step 3: Create the control file
Create a file 'control' in the DEBIAN directory

Package: helloworld
Version: 0.2
Maintainer: King Foo
Architecture: all
Description: hello world
Package: helloworld Version: 0.2 Maintainer: King Foo Architecture: all Description: hello world

These are the mandatory fields in the control file. For more options see:
http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-binarycontrolfiles

Step 4: Add a post-installation script
You can create a file 'postinst' in the DEBIAN directory. Make sure it is executable. It will run when the installation is complete.

Step 5: Create the package

dpkg-deb --build helloworld
dpkg-deb --build helloworld

This creates a helloworld.deb file, which you can now install on any Debian installation with following command:

dpkg -i helloworld.deb
dpkg -i helloworld.deb

Dit blog is geschreven door de specialisten van Intracto.

Inmiddels is Intracto onderdeel van iO. Meer weten? Neem gerust contact op!

logo iO