Building my first Linux package

Posted under tech On By xpk

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 and it will be installed to /usr/local/bin/


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.

│   └── control
└── usr
    └── local
        └── bin

The control file

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

Package: goldenRatio
Version: 0.1.2
Maintainer: XPK
Architecture: all
Depends: python3
Description: Script to calculate golden ratio 

Build & install the package

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

$ cd /root
$ dpkg-deb --build goldenRatio /tmp
dpkg-deb: building package 'goldenratio' in '/tmp/goldenratio_0.1.2_all.deb'.
$ apt install /tmp/goldenratio_0.1.2_all.deb


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.

Name: goldenRatio
Summary: Shell script for calculating golden ratio
Version: 0.1
Release : 3
License: GPLv3
Requires: python36

Shell script for calculating golden ratio

* Thu Jul 26 2018 XPK [email protected] 0.1-3
- Second build, adding python dependency

mkdir -p %{buildroot}%{_prefix}/local/bin
cp -pf %{buildroot}%{_prefix}/local/bin/
chmod 755 %{buildroot}%{_prefix}/local/bin/


Install the build tool

$ yum install rpm-build

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.

│   └──
├── RPMS
│   └──

Build and install the package

$ cd /root/rpmbuild/SPECS
$ rpmbuild  -ba
$ yum localinstall /root/rpmbuild/RPMS/x86_64/goldenRatio-0.1-3.x86_64.rpm

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.

 302 total views,  4 views today