How to Build Own RPM Package

First Login as regular user like ashutosh or any other normal user-

First Step-: Create a directory hierarchy.

You have two options here to create directory hierarchy.

1. you can download a rpm package "redhat-release-6-" from Internet and then install this to create directory hierarchy.

[ashutosh@server ~]$ rpm -ivh redhat-release-6-


[ashutosh@server ~]$ yum install redhat-release* -y

Now you can check the rpmbuild directory which is created or not.

[ashutosh@server ~]$ ls

Desktop    Music     redhat-release-6-  Videos
Documents  Pictures  rpmbuild
Downloads  Public    Templates

Note-: rpmbuild directory has been created

2. If you don't want to use redhat-release rpm package you can create directory hierarchy manually.

[ashutosh@server ~]$mkdir rpmbuild

[ashutosh@server ~]$mkdir rpmbuild/SOURCES

[ashutosh@server ~]$mkdir rpmbuild/SPECS

Second Step-: Create a directory with some sample files or scripts that you like to build in the package:

[ashutosh@server ~]$mkdir ashutosh-0.1

[ashutosh@server ~]$cd ashutosh-0.1/

[ashutosh@server ashutosh-0.1]$vim ashutosh1
#This is a Simple Script.
yum install festival* -y
echo "Your Welcome" | festival --tts
echo -e "\E[0;34mYour Welcome,\E[0m"
echo   "This ia my test rpm package" | festival --tts
echo -e "\E[32mThis ia my Test RPM Package.\E[0m"
echo "Thanks" | festival --tts
echo -e "\E[1;31mThanks,\E[0m"
echo "Ashutosh" | festival --tts
echo -e "\E[5;35mAshutosh\E[0m"

:wq (save and exit)
[ashutosh@server ashutosh-0.1]$cd

[ashutosh@server ~]$

Now create an archive file-

[ashutosh@server ~]$tar -czvf ashutosh-0.1.tar.gz ashutosh-0.1/

Then copy this source to /home/ashutosh/rpmbuild/SOURCES/

[ashutosh@server ~]$cp ashutosh-0.1.tar.gz /home/ashutosh/rpmbuild/SOURCES/

Third Step: Now Create spec file.

(spec files is to read through some of the huge number of spec files for the source RPMs that come with your Linux distribution)

[ashutosh@server ~]$cd /home/ashutosh/rpmbuild/SPECS/

[ashutosh@server SPECS]$vim ashutosh.spec

Name:           ashutosh
Version:         0.1
Release:        1%{?dist}
Summary:      GOOD
Group:           Ashutosh
License:         GNUv2
Source:          ashutosh-0.1.tar.gz
Buildroot:%(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)

# BuildRequires:
# Requires:


%setup -q

echo " OK "

rm -rf $RPM_BUILD_ashutosh
mkdir -p $RPM_BUILD_root/root/bin
cp ashutosh1 $RPM_BUILD_root/root/bin

rm -rf $RPM_BUILD_root


* Thu Feb 22 2014 test-0.1

Fourth Steps-: Now you have to build the rpm package using this spec file.

[ashutosh@server ~]$su -
[root@servr ~]#rpm -qa rpm-build
[root@server ~]#yum install rpm-build

[root@server ~]#logout

[ashutosh@server ~]$

[ashutosh@server ~]$rpmbuild -ba /home/ashutosh/rpmbuild/SPECS/ashutosh.spec

Finally your RPM has been build. now you can display your RPM package from this path (/home/student/rpmbuild/RPMS/x86_64/) using ls command.

[ashutosh@server ~]$ ls /home/ashutosh/rpmbuild/RPMS/x86_64/

ashutosh-1-1.el6.x86_64.rpm  ashutosh-debuginfo-1-1.el6.x86_64.rpm

Note- You can see following directory, inside the /home/ashutosh/rpmbuild/ directory:

BUILD                - Contains scratch space used to compile software
RPMS                - Contains the binary RPM that is built
SOURCES          - Holds the source code for the RPM
SPECS               - Contains the spec file(s) (one per RPM)
SRPMS               - Contains the source RPM built during the process

Now install rpm package-

[ashutosh@server ~]$su -

[root@server ~]#rpm -ivh /home/ashutosh/rpmbuild/RPMS/x86_64/ashutosh-1-1.el6.x86_64.rpm

After installing rpm package you can use the command.

[root@server ~]#ashutosh1

Your Welcome,
This ia my Test RPM Package.

[ashutosh@server ~]#

More Info...Click

I hope you like it.
So Enjoy............................!

Click Back..                                Click Home..