Let’s take a look at how to build a really simple Linux package. The most common package formats are definitely .deb and .rpm. One will find them on Debian-variants and Redhat-variants respectively.

In the following examples, a package will be created and it will contain 1 script.The script depends on Python so I want the package management tool to handle that for me too. The script’s name is goldenRatio.sh and it will be installed to /usr/local/bin/

DEB

Create a directory structure for building

Here is what I created. Will talk about the control file in a minute. The usr subdirectory contains the path to where I want this script installed.

The control file

This file describe the package. It is pretty much self-explanatory.

Build & install the package

We are ready to build the deb package. The following command will create a package under /tmp/.

RPM

The RPM version is more involved. For rpm, we’ll need to write a spec file.

The spec file

The spec file does not just describe the package. It contains instructions to compile a software or in this case to copy the script to the target location.

Install the build tool

The build directory

After the previous step is performed, /root/rpmbuild is automatically created. Here, I’ll need to put my spec file in the SPECS directory, and my script under the BUILD directory.

Build and install the package

Wrapping up

In both case, apt and yum will automatically resolve the dependency for Python, and prompt you to install them if you don’t have it already.

These are very simply examples. I’ll do a follow-up post once I learn more.