How to Create an RPM Package for Beginners

Introduction:

RPM (Red Hat Package Manager) is the package management system used by Red Hat-based Linux distributions like Fedora and CentOS. Building your RPM package can simplify the distribution and installation of your software on these systems.

Prerequisites:

Before you start, make sure you have the following tools installed on your system:

  1. rpmbuild: Install the RPM build tool.bashCopy codesudo dnf install rpm-build
  2. rpmdevtools: Install development tools for RPM packages.bashCopy codesudo dnf install rpmdevtools

Step 1: Set Up the Package Directory Structure

Create a directory for your package and navigate into it:

mkdir mypackage cd mypackage

Inside this directory, create the necessary subdirectories:

mkdir -p BUILD RPMS SOURCES SPECS SRPMS

  • BUILD: Where the build process will take place.
  • RPMS: Where the binary RPMs will be placed.
  • SOURCES: Where the source files will reside.
  • SPECS: Where the spec file will be located.
  • SRPMS: Where the source RPMs will be stored.

Step 2: Create the Spec File

Inside the SPECS directory, create a file named mypackage.spec:

nano SPECS/mypackage.spec

Add the following content, adjusting the values accordingly:

Name: mypackage Version: 1.0 Release: 1%{?dist} Summary: Short description of your package License: Your License URL: https://example.com Source0: %{name}-%{version}.tar.gz %description Long description providing more details about your package. %prep %autosetup %build # Add build commands here %install # Add installation commands here rm -rf $RPM_BUILD_ROOT install -d $RPM_BUILD_ROOT/usr/bin install -m 755 usr/bin/* $RPM_BUILD_ROOT/usr/bin/ %files %defattr(-,root,root,-) /usr/bin/* %changelog * Date Your Name <your@email.com> - version-release - Changelog entry

Save the file and exit.

Step 3: Prepare Source Files

Place your source files in the SOURCES directory. For example, if your program is in a directory named myprogram, create a tarball:

tar -czvf SOURCES/mypackage-1.0.tar.gz myprogram

Step 4: Build the RPM Package

Navigate back to the main package directory and build the RPM package:

rpmbuild -bb SPECS/mypackage.spec

This will create the RPM package in the RPMS directory.

Step 5: Install and Test the RPM Package

Install the package using:

sudo dnf install RPMS/<architecture>/mypackage-1.0-1.<architecture>.rpm

Replace <architecture> with the appropriate architecture for your system.

Now, test your program:

myprogram

Conclusion:

You’ve successfully created and installed your RPM package! This guide provides a basic introduction to RPM packaging, and as you gain more experience, you can explore advanced features and optimizations.

For a deeper understanding, refer to the official RPM packaging documentation and explore additional RPM packaging tools available.

Happy packaging!


Beitrag veröffentlicht

in

von

Schlagwörter: