Chapter 1. Getting started with RPM packaging


The following section introduces the concept of RPM packaging and its main advantages.

1.1. Introduction to RPM packaging

The RPM Package Manager (RPM) is a package management system that runs on RHEL, CentOS, and Fedora. You can use RPM to distribute, manage, and update software that you create for any of the operating systems mentioned above.

1.2. RPM advantages

The RPM package management system brings several advantages over distribution of software in conventional archive files.

RPM enables you to:

  • Install, reinstall, remove, upgrade and verify packages with standard package management tools, such as Yum or PackageKit.
  • Use a database of installed packages to query and verify packages.
  • Use metadata to describe packages, their installation instructions, and other package parameters.
  • Package software sources, patches and complete build instructions into source and binary packages.
  • Add packages to Yum repositories.
  • Digitally sign your packages by using GNU Privacy Guard (GPG) signing keys.

1.3. Creating your first rpm package

Creating an RPM package can be complicated. Here is a complete, working RPM Spec file with several things skipped and simplified.

Name:       hello-world
Version:    1
Release:    1
Summary:    Most simple RPM package
License:    FIXME

%description
This is my first RPM package, which does nothing.

%prep
# we have no source, so nothing here

%build
cat > hello-world.sh <<EOF
#!/usr/bin/bash
echo Hello world
EOF

%install
mkdir -p %{buildroot}/usr/bin/
install -m 755 hello-world.sh %{buildroot}/usr/bin/hello-world.sh

%files
/usr/bin/hello-world.sh

%changelog
# let's skip this for now

Save this file as hello-world.spec.

Now use these commands:

$ rpmdev-setuptree
$ rpmbuild -ba hello-world.spec

The command rpmdev-setuptree creates several working directories. As those directories are stored permanently in $HOME, this command does not need to be used again.

The command rpmbuild creates the actual rpm package. The output of this command can be similar to:

... [SNIP]
Wrote: /home/<username>/rpmbuild/SRPMS/hello-world-1-1.src.rpm
Wrote: /home/<username>/rpmbuild/RPMS/x86_64/hello-world-1-1.x86_64.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.wgaJzv
+ umask 022
+ cd /home/<username>/rpmbuild/BUILD
+ /usr/bin/rm -rf /home/<username>/rpmbuild/BUILDROOT/hello-world-1-1.x86_64
+ exit 0

The file /home/<username>/rpmbuild/RPMS/x86_64/hello-world-1-1.x86_64.rpm is your first RPM package. It can be installed in the system and tested.

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.