Creating a Test RPM Package: A Step-by-Step Guide

Muhammad khan
2 min readFeb 13, 2024

Want to learn the basic mechanics of creating RPM packages without diving into complex functionalities? Let’s create a simple “Hello World” test RPM!

Directory Structure:

~ ─ rpmbuild
├── RPMS

├── SOURCES
├── SPECS
└── test-rpm.specs
└── SRPMS
  1. rpmbuild directory: This is the main workspace for building RPMs. Create it in your home directory: mkdir ~/rpmbuild.
  2. SPECS directory: This holds the spec file. Inside rpmbuild, create mkdir ~/rpmbuild/SPECS.
  3. RPMS directory: This will store the built RPM file after successful build.

Steps:

  1. Create the Spec File:
  • Inside ~/rpmbuild/SPECS, create a file named hello-test-rpm.spec with the following content:
Name: hello-test-rpm 
Version: 1.0.0
Release: 1
Summary: A simple test RPM
License: GPL # Modify if necessary, but license is needed

%description
This is a basic RPM displaying "Hello World!" upon installation.

%files

%license %{name}/LICENSE # Add LICENSE file if relevant

%pre

%post echo "Hello World!" # Display the message

%clean

%prep

%build

%install # No files to install for this test
mkdir -p %{buildroot}/%doc/{empty-test-rpm}
cp -r LICENSE %{buildroot}/%doc/empty-test-rpm/ # Include LICENSE if relevant
  • Replace [PLACEHOLDER: License description] with your chosen license description (e.g., "GPLv3+").
  • You can skip the cp line in install if you don’t have any license file.

Build the RPM:

  • Open a terminal and navigate to ~/rpmbuild/SPECS.
  • Run the build command: rpmbuild -bb hello-test-rpm.spec.
  • If successful, a .rpm file will be created in ~/rpmbuild/RPMS.

Install the RPM (on a test machine):

  • Copy the .rpm file to your test machine.
  • Install it with sudo dnf install <filename> (or sudo yum install depending on your system).

Verify the Message:

  • Open a terminal on the test machine and check the installation log: tail -n 1 /var/log/rpm-install. You should see "Hello World!".

Congratulations! You’ve built and installed a test RPM package.

Remember:

  • This is a simplified example for learning purposes. Adapt the spec file for your specific needs.
  • For complex functionalities like file installations or scripting, use appropriate sections in the spec file.
  • Always include a valid license for open-source packages.

Explore further:

--

--