How to start building your first RPM

Post Written by
Aleksandar Matić
Last modified on July 2nd, 2020 at 10:04 am

What is an RPM?

One of the main benefits of open source software is that it lets you access each application's core. Yet, even with that level of access, there's a need to run simple tasks (running scripts, starting system services...) in a more simple way. That simplified code is referred to as packages (RPM). The packages are not universal - they are designed to fit each operating system's (OS) particular framework. For this to work, each OS comes with its own packet manager. For example, Debian distributions use Advanced Packaging Tool ( APT) while Fedora employs the RPM packet manager. Fedora, OpenSUSE, Red Hat Entreprise Linux and many others make use of the RPM packet manager. Even the acronym used today - RPM - comes from Red Hat Packaging Manager.

Installing the tools and adding a 'mock' user

Before creating your first RPM package, you'll need to install two tools by running

dnf install fedora-packager fedora-review

from your terminal. This installs:

  • fedora-packager - which helps you build packages
  • fedora-review - which reviews the package's quality

After installing the tools, we're going to go ahead and add a new user to the 'mock' group by running

usermod -a -G mock yourusername

as under no circumstances should you build and/or test RPMs with the ROOT user.

Building the RPM

For creating the RPM, we'll need to create a directory to hold the package and .spec file. Spec files contain metadata and information needed to install and compile the software. The file is being named by adding .spec to the package's name.

mkdir -p ~/test-package/hello
cd ~/test-package/hello
cat << EOF > hello
echo "Hello world!"
chmod 644 hello

Running bash hello should return the desired output - Hello world! Now that we have something worth packaging, we'll create a file named hello.spec within the directory. Important: Use spaces, not tabs! The indentation is not important with spec files:

Name: hello
Version: 1
Release: 1%{?dist}
Summary: Say hello to the world

License: Public Domain
Source0: hello

A simple program to greet the user.




You can now run a local build with

fedpkg --release f25 local

This leaves us with a small and not so much functional RPM package that we can use. The next tutorial will explore building RPMs in mock and koji, along with more complex (and useful) RPMs.

Contact Us

Fill out the enquiry form and we'll get back to you as soon as possible.