English Spanish
How to Create a GNU Hello World RPM Package
This is a short hands-on tutorial on writing RPM files, showing how to quickly set up and create simple source and binary software packages. It assumes some familiarity with using pre-made RPM packages, and with the FOSS building process.
For comprehensive information on how to create RPM files, including more detailed tips, refer to xref:creating-rpm-packages.adoc[How to create an RPM package]. If you plan to create an RPM package for the Fedora repository, follow the process for link:https://docs.fedoraproject.org/en-US/package-maintainers/Joining_the_Package_Maintainers/[Join the Package Maintainers], including following the various Fedora guidance.
This tutorial demonstrates packaging of the GNU "Hello World" project. While the C program printing "Hello World" to standard output is trivial, the GNU version contains most of the usual peripheral components associated with a typical FOSS project, including the configuration/build/install environment, documentation, internationalization, etc. The GNU version, however, traditionally consists of a `tar` file containing the source code and configure/make scripts, but it does not include the packaging information. Therefore, it's a reasonable vehicle to practice building RPMs on.
To build RPMs we need a set of development tools.
Make sure you run the following command as the `root` user!
This is a one-time-only setup, installed by running these commands from a system administration (`root`) account:
# dnf install fedora-packager @development-tools
To be able to test the build procedure in a clean chroot you need to configure your non-privileged account to be a member of the 'mock' group:
# usermod -a -G mock <your username>
Those are the only commands requiring `root` privileges. All the remaining work should be done from your regular, non-privileged account, or even from a separate account created just for development work. Modern RPM-based systems, including Fedora, are set up to build and test RPM packages purely from within a non-privileged account. The following command sets up an RPM build area in your `~/rpmbuild` directory. This directory will contain several subdirectories, for the project source code, RPM configuration files and for the resulting source and binary packages.
$ rpmdev-setuptree
Building a "Hello World" RPM
We need the source code of the project we are packaging, often referred to as the 'upstream' source. We will download it from the project's website into the `~/rpmbuild/SOURCES` directory. We are getting the compressed tarball archive, which happens to be the preferred distribution form for most FOSS projects.
$ cd ~/rpmbuild/SOURCES
$ wget http://ftp.gnu.org/gnu/hello/hello-2.10.tar.gz
The RPM package is configured by `.spec` files. We will create a template file `hello.spec` in the appropriate directory:
$ cd ~/rpmbuild/SPECS
$ rpmdev-newspec hello
Recent versions of `Emacs` and `vi` have .spec file editing modes which will also bring up a similar template upon creating a new file. So you can just use the following command for example to use the template automatically.
$ emacs hello.spec
Inside a Spec File