Building Simple RPM Packages

A very simple exercise to build a basic RPM package. We’re not going to dive into package signing, or some of the lower level topics of packaging RPM’s - rather, our objective for now is to simply generate a file and drop it on the filesystem.

In this case, we don’t care about the platform, the OS release, or the architecture.

Install dependencies

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

Sample Spec File

Name:           local-release
Version:        2019.09
Release:        8
Summary:        local patching cycle release
License:        GPL
URL:            https://example.com
BuildArch:      noarch

%description
Local release: 2019.09.2

%build
cat > local_release <<EOF
2019.09.8
EOF

%install
install -m 0775 -d $RPM_BUILD_ROOT/etc
install -m 0644 local_release $RPM_BUILD_ROOT/etc/local_release

%clean
rm -rf $RPM_BUILD_ROOT

%files
/etc/local_release

%doc
%changelog
* Mon Sep 23 2019 Linux Team <linux-team@example.com>
- Release cycle 2019.09

Save this file as local-release.spec

Setup build tree

$ rpmdev-setuptree

This will result in a structure like this:

$ tree rpmbuild/

rpmbuild/
├── BUILD
├── BUILDROOT
├── RPMS
├── SOURCES
├── SPECS
└── SRPMS

Build the RPM

$ rpmbuild -ba local-release.spec

This will result in:

rpmbuild/RPMS/noarch/local-release-2019.09-8.noarch.rpm

Install & Validate

$ yum localinstall rpmbuild/RPMS/noarch/local-release-2019.09-8.noarch.rpm
$ cat /etc/local_release