DEV Community

Cover image for HOW TO MAKE A RPM PACKAGE
Lucas Puntillo
Lucas Puntillo

Posted on • Originally published at lucaspuntillo.blogspot.com

HOW TO MAKE A RPM PACKAGE

How to make a RPM package

RPM is a versatile Linux packaging originally meant for Red Hat Linux (now RHEL) but now ported to Fedora Linux, Clear linux, and many more distro's. In my opinion, it is more cleaner and refined than the .deb format, DPKG, and APT, (used by Debian Linux and it's derivatives.)

NOTE: The package was made on a CentOS 7 Virtual machine and was tested on a Fedora Linux 33 virtual machine.

Step one, dependencies:

yum install rpm-build rpm-devel rpmlint make diffutils patch rpmdevtools
Enter fullscreen mode Exit fullscreen mode

Step two, setup build directory

mkdir $HOME/rpmmaker
Enter fullscreen mode Exit fullscreen mode

Step three, create a specifications file:

Name:       test
Version:    1
Release:    1
Summary:    a test RPM package
License:    None

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

%prep
# We have nothing to prepare.

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

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

%files
/usr/bin/hello-world

%changelog
#This is version 1.0!
Enter fullscreen mode Exit fullscreen mode

Save it as helloworld.spec in the rpmmaker directory

Step four, make the rpm:

cd $HOME/rpmmaker
rpmdev-setuptree
rpmbuild -ba helloworld.spec
Enter fullscreen mode Exit fullscreen mode

The directory /home/YourName/rpmbuild/RPMS/x86_64/ should hold your RPM file.

Step 5, testing the file:

cd into the directory where the rpm is

sudo rpm -i filename.rpm
hello-world
Enter fullscreen mode Exit fullscreen mode

If it says "Hello World!" then the file works.

The RPM is now ready to be shared.

Top comments (0)