Recently, I made a simple debian package. I noticed that there werent any simple tutorials for making a package. I had to go through many sources to make a simple package, and so I decided to write this.
This is not comprehensive by any means. Its just a quick guide to making simple, small debian packages for beginners. Packages built using just this tutorial arent going to make it into official debian repos, but I think its a good place for beginners to start.
You will need the dpkg package. If you are using a debian system (such as Ubuntu) this should be installed already. If youre using OS X you can install it from homebrew (brew install dpkg). Note that if you want to build a complete binary you should build the package on the same environment that youre targeting.
Essentially, a debian file holds data regarding your package and files that your package needs. It copies the files that are required onto the target system. It may execute some commands before and after installation.
First, you will need to create a folder which is going to be packaged. We will call this the PACKAGE folder. It contains all your package files and data. Inside this, you should create a folder named DEBIAN. This folder will contain all the meta data pertaining to your package and all the install scripts.
You directory structure should look something like this.
Control file contains the most vital information about the package such as package name, maintainer. version number, description, etc. A sample control file is provided below. It contains a few of the fields that a control file can have. For more information regarding the fields, you can check the debian website.
Package: MyPackageDepends: python-devVersion: 0.0.1Section: tutorialArchitecture: allEssential: noMaintainer: email@example.comDescription: This is a debian packaging tutorial.
The control file should be named control and placed in the PACKAGE/DEBIAN directory. Your directory structure will look like this.
.PACKAGE/||--DEBIAN/ | |-control
Now to your code. You should treat the PACKAGE directory as the root (i.e. /) of the file system on which the package is going to be installed. Meaning, if you put a file in PACKAGE/var/www/html/, the file will appear in /var/www/html/ when the package is installed.
Since the installation is done with super user permissions, files can be placed anywhere in the file system.
Temporary files should be placed in the /tmp directory.
Your directory structure may look like this.
.PACKAGE/ | |--var/ | | | |--www/ | | | |--html/ | | | |--hello_world.html | |--my_blog.html | |--DEBIAN/ | |-control
You may wish to run certain scripts before or after the files in the PACKAGE directory are copied to the target file system. These are preinst and postinst files.
Post and pre install files should start with a shebang (#!/bin/bash). Pre install scripts are run before the package is installed. Post install scripts are run after the packages files are copied.
An example postinst file:
#!/bin/bashcd /tmp/my_packagepython setup.py install # install the packageecho "MyPackage has been installed"
The postinst file and preinst file should have permissions between 555 and 755. These files also have to be put in the PACKAGE/DEBIAN directory.
Your package structure may look like this.
.PACKAGE/ | |--var/ | | | |--www/ | | | |--html/ | | | |--hello_world.html | |--my_blog.html | |--DEBIAN/ | |-control |-postinst |-preinst
Navigate to the parent directory of PACKAGE and execute the dpkg-deb command.
$ dpkg-deb --build PACKAGE
Your package should have been built as a.deb file.
To test your package, you can install it localling using:
$ dpkg -i MyPackage.deb
For an in-depth guide to packaging, you can read the official Debian packaging guide.
I hope this helped you in getting a quick understanding of how to make simple debian packages. You can also use CheckInstall. If you spot any mistakes or corrections, please feel free to write to me here.