Creating Debian/Ubuntu .deb packages

In this blog post, we will guide you on how to create a .deb package for Debian/Ubuntu systems from binary files. With a .deb package, you can easily install and manage software on your system.

Step 1: Create the directories
To begin, let's start with creating the necessary directories. You will need to create a directory for your package and a sub-directory called DEBIAN. You can do this by running the following command in your terminal:

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

Step 2: Copy files into your package
Next, you can copy the binary files into your package. You should use the full paths on the destination filesystem when copying files. For instance, if you want to put a file in /usr/local/bin/, you can do so by creating the directory in your package and copying the file like this:

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
After copying the files, you will need to create a control file in the DEBIAN directory. This file contains important information about the package such as its name, version, maintainer, architecture, and a short description. You can create the control file using your favorite text editor and naming it 'control'. Here is an example of a basic control file:

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
Additionally, you can create a post-installation script that runs after the installation is complete. To do so, you can create a file named 'postinst' in the DEBIAN directory and make sure it is executable.

Step 5: Create the package
Finally, you can create the .deb package by running the following command:

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

This will create a helloworld.deb file in the current directory. You can now install the package on any Debian/Ubuntu system using the following command:

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

By following these steps, you should be able to create your own .deb packages and manage your software installations easily. For more advanced options and configurations, you can refer to the Debian policy manual.

Need help creating your own Debian/Ubuntu .deb package or managing your software installations? Contact us for expert guidance!

Dit blog is geschreven door de specialisten van Intracto.

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

logo iO