In the Red Hat Enterprise Linux (RHEL) world, you can install software packages using a package management tool such as yum or the default package manage – rpm.

This tutorial will focus on the latter. RPM stands for Red Hat Package Manager. With RPM, you can install packages using .rpm files. However RPM does not resolve dependencies, if the software you're trying to package up has a dependency on another package being installed; it's best to use YUM.

For a single purpose software which does not rely on other packages RPM would be the best choice.

Getting Started

  1. Create a user that will create the RPM package. For this tutorial, I will use rpmuser.
useradd -m rpmuser
passwd rpmuser

2. Install packages to create RPM packages. You will need the following packages:

  • gcc
  • rpm-build
  • rpm-devel
  • rpmlint
  • make
  • coreutils
  • diffutils
  • patch
  • rpmdevtools
yum install gcc rpm-build rpm-devel rpmlint make python bash coreutils diffutils patch rpmdevtools

3. Change to the user that will create the RPM package.

sudo su - rpmuser

4. Navigate to the home directory. This will be the location of the RPM build directory.

cd ~

5. Create the RPM build tree.

rpmdev-setuptree

When this command completes there should be a new directory named rpmbuild, verify the directories have been created.

ll rpmbuild

You should see the following directories in rpmbuild:

BUILD
BUILDROOT
RPMS
SOURCES
SPECS
SRPMS

6. Create a spec file. Mine is called mycustom.spec.

vim ~/rpmbuild/SPECS/mycustom.spec
Name:           hello
Version:        1
Release:        0%{?dist}
Summary:        Ayy Lmao

License:        GPL
URL:            https://www.pafable.com
Source0:        hello-1.tar.gz


%description
output hello followed by a name

%prep
%setup -q

%install
mkdir -p "$RPM_BUILD_ROOT"
cp -R * "$RPM_BUILD_ROOT"

%files
%doc
/usr/local/bin/hello.py
%define _unpackaged_files_terminate_build 0

#%clean
#rm -rf $RPM_BUILD_ROOT
#rm -rf $RPM_BUILD_ROOT/hello.pyc
#rm -rf $RPM_BUILD_ROO/hello.pyo

%changelog
* Wed Aug 21 2019 pafable 1.0
  - Initial release

7. Build the RPM package with the rpmbuild command.

rpmbuild -v -bb SPECS/mycustom.spec

8. After the build completes, time to test it!

rpm -ivh <package_name>

And that is it! To be completely honest this post has been in limbo since late summer so mistakes may have occur. I'll update this post as I go along. :)