How to create rpm package

Install required tools

rpm -qa | grep rpmdevtools
yum list | grep rpmdevtools
yum install rpmdevtools

Create directory structure required for rpm build if not exist

rpmdev-setuptree
rpmbuild/
├── BUILD
├── RPMS
├── SOURCES
├── SPECS
└── SRPMS

Create source package under SOURCES

mkdir hello-0.0.1
cd hello-0.0.1

hello.sh

#!/bin/sh
echo "Hello world"
tar -cvzf hello-0.0.1.tar.gz hello-0.0.1

Create spec file and make necessary changes

cd ~/rpmbuild/SPECS
rpmdev-newspec hello.spec
Name:           hello
Version:        0.0.1
Release:        1%{?dist}
Summary:        A simple hello world script
BuildArch:      noarch

License:        GPL
Source0:        %{name}-%{version}.tar.gz

Requires:       bash

%description
A demo RPM build

%prep
%setup -q

%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/opt/hello
cp * $RPM_BUILD_ROOT/opt/hello

%clean
rm -rf $RPM_BUILD_ROOT

%files
/opt/hello/*

%postun
rm -vrf /opt/hello

%changelog
* Sun Feb 04 2024 
- First version being packaged

Now directory structure should look like this

/home/tux/rpmbuild/
├── BUILD
├── BUILDROOT
├── RPMS
├── SOURCES
│   └── hello-0.0.1.tar.gz
├── SPECS
│   └── hello.spec
└── SRPMS

Build rpm using following command

rpmbuild -ba SPECS/hello.spec

where -b is build a is for both source and binary
if you want only binary then put -bb flag
if you want only source then put -bs flag

Install the rpm using following command

sudo rpm -ivh ~/rpmbuild/RPMS/noarch/hello-0.0.1-1.el8.noarch.rpm

Verify rpm installed successfully using following command

rpm -qi hello
tree /opt/hello

The %changelog entry of a package can be viewed, too:

rpm -q hello –changelog

Uninstall or erase installed rpm

sudo rpm -q | grep hello
sudo rpm -ve hello

Troubleshoot

To extract files and directories from rpm

rpm2cpio hello-0.0.1-1.el8.noarch.rpm | cpio -idmv

21 Replies to “How to create rpm package”

  1. Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates. I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this. Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.

  2. I love your blog.. very nice colors & theme. Did you make this website yourself or did you hire someone to do it for you? Plz answer back as I’m looking to construct my own blog and would like to find out where u got this from. cheers

  3. Hey there would you mind sharing which blog platform you’re using? I’m going to start my own blog soon but I’m having a tough time making a decision between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design and style seems different then most blogs and I’m looking for something unique. P.S Sorry for being off-topic but I had to ask!

  4. Привет всем! Сегодня затронем тему — выбор материала для крыши. Суть в том, что выбирать дешёвое — аукнется потом. Не хочешь рисковать — могу рекомендовать: установка мембранной кровли. На практике вижу: ПВХ покрытие — окупается за счёт долговечности. Допустим постоянные ремонты — а мембрана стоит 25-30 лет. Основные этапы: нанять опытную бригаду. Вот и соответственно: высокоэффективный инструмент для долговечной кровли.

  5. Приветствую! На первом этапе нужно разобраться — почему течёт у стен и парапетов. Дело в том, что: большинство проблем — некачественная обработка узлов. Ищешь тех кто умеет — могу рекомендовать: https://montazh-membrannoj-krovli-spb.ru. Зачем это: обход труб — всё сваривается. Допустим труба на крыше — обрамляется мембраной — опять же вода не пройдёт. Мы используем — фасонные детали из ПВХ. Что в итоге: удаётся достигать классных результатов — узлы надёжны.

  6. Very nice post. I just stumbled upon your weblog and wished to say that I have really loved surfing around your weblog posts. After all I’ll be subscribing on your feed and I hope you write once more very soon!

  7. Hey! I know this is kinda off topic but I was wondering which blog platform are you using for this site? I’m getting sick and tired of WordPress because I’ve had problems with hackers and I’m looking at alternatives for another platform. I would be awesome if you could point me in the direction of a good platform.

  8. Aw, this was an exceptionally nice post. Taking a few minutes and actual effort to generate a superb article… but what can I say… I put things off a whole lot and don’t seem to get nearly anything done.

  9. I was recommended this blog through my cousin. I am now not positive whether or not this put up is written by means of him as no one else realize such exact approximately my difficulty. You’re wonderful! Thanks!

  10. Hi, I do believe this is a great blog. I stumbledupon it 😉 I will come back yet again since I book-marked it. Money and freedom is the best way to change, may you be rich and continue to help other people.

  11. Everyone loves what you guys are up too. This kind of clever work and exposure! Keep up the wonderful works guys I’ve incorporated you guys to my personal blogroll.

  12. You could certainly see your expertise within the work you write. The arena hopes for more passionate writers like you who aren’t afraid to say how they believe. At all times go after your heart.

Leave a Reply

Your email address will not be published.