How to build RPM packages from Spec files

Let’s take nginx as an example. First, let’s prepare the following building environment:

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

Now under your home directory there is a rpmbuild directory, under which there are sub-directories:

  • BUILD
  • BUILDROOT
  • RPMS
  • SOURCES
  • SPECS
  • SRPMS

Since we build the RPM package from natively compiled source files, we then prepare the following nginx source package/files under the SOURCES directory(these source files are packaged at here):

  • nginx-1.15.8.tar.gz
  • nginx.service
  • nginx.logrotate
  • nginx.conf
  • nginx-upgrade
  • nginx-upgrade.8
  • index.html
  • poweredby.png
  • nginx-logo.png
  • 404.html
  • 50x.html

and nginx.spec file under the SPECS directory. Finally, we can build the RPM package with a single command:

rpmbuild -bb ~/rpmbuild/SPECS/nginx.spec

If it complains errors like “Failed build dependencies: …”, just yum install them. More details please see:

  1. Creating RPM packages
  2. RPM Packaging Guide

Leave a comment

Your email address will not be published. Required fields are marked *