Skip to content

Practice of Creating RPM Packages

September 19, 2012

Last time, I built two packages from source. Today, I am going to create their RPM packages.

First, to create an RPM package, we need install the required packages (need root privilege ) :

# yum groupinstall “Fedora Packager”
# yum groupinstall “Development Tools” “Development Libraries”
# yum install rpmlint yum-utils

Then quite from supper user and run command below to create the ~/rpmbuild directories and the ~/.rpmmacros file:

# exit
$ rpmdev-setuptree

You can check the directories you created by:

$ tree ~/rpmbuild
/home/zyu26/rpmbuild
├── BUILD
├── RPMS
├── SOURCES
├── SPECS
└── SRPMS

Now let’s start to create the first RPM package “diffutils”.

  1. Download the source code.$ yumdownloader –source diffutils-3.2
  2. Install the download SRPM:.$ rpm -i diffutils-3.2-6.fc17.src.rpm

In this step, I got warning:
warning: user mockbuild does not exist – using root
warning: group mockbuild does not exist – using root
warning: user mockbuild does not exist – using root
warning: group mockbuild does not exist – using root
warning: user mockbuild does not exist – using root
warning: group mockbuild does not exist – using root
warning: user mockbuild does not exist – using root
warning: group mockbuild does not exist – using root

  1. Go to SPECS directory and create a new diffutils.spec file and edit it

$ cd ~/rpmbuild/SPRCS
$ rpmdev-newspec diffutils.spec
$ vi diffutils.spec
Name: diffutils
Version: 3.2
Release: 7%{?dist}
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Summary: A GNU collection of diff utilities
License: GPLv2+
URL: http://www.gnu.org/software/diffutils/diffutils.html
Source: ftp://ftp.gnu.org/gnu/diffutils/diffutils-%{version}.tar.gz
%description
Diffutils includes four utilities: diff cmp, diff3 and sdiff.

%prep
%setup -q

%build
%configure
make PR_PROGRAM=%{_bindir}/pr

%install
rm -rf $RPM_BUILD_ROOT
make DESTDIR=$RPM_BUILD_ROOT install
rm -f $RPM_BUILD_ROOT%{_infodir}/dir

%files
%doc
%{_bindir}/*
%{_datadir}/*
%{_mandir}/*/*
%{_infodir}/diffutils.info*gz

%changelog
* Tue Sep 19 2012 Changed the version number
– built for SBR600 course

  1. Building RPMs:

a) Using this specfile to build all binary RPMS and SRPMS.

$ rpmbuild -ba diffutils.spec

b) If just want built the spec file

$ rpmbuild -bs diffutils.spec

c) To build the RPMs and SRPM directly from an SRPM

$ rpmbuild –rebuild diffutils*.src.rpm

  1. Testing the RPM

Test the spec file

$ rpmlint ~/rpmbuild/SPECS/diffutils

Test the source RPM

$ rpmlint ~/rpmbuild/SRPMS/diffutils*.src.rpm

Test the binary RPMs

$ rpmlint ~/rpmbuild/RPMS/*/diffutils*.rpm

Now, I am going to build my second RPM package “which”

  1. Wipe out the rpmbuild tree:$ rpmdev-wipetree
  2. Download the source code of which-2.20.tar.gz and copy it to SOURCES directory
  3. Create a new spec file in SPECS directory and edit it$ rpmdev-newspec which.spec

$ vi which.spec

Name: which
Version: 2.20
Release: 4%{?dist}
Summary: Which shows the full path of commands
License: GPLv+2
URL: http://www.gnu.org/software/diffutils/which.html
Source0: ftp://ftp.gnu.org/gnu/diffutils/which-%{version}.tar.gz

%description
Which shows the commands’ full path

%prep
%setup -q

%build
%configure
make %{?_smp_mflags}

%install
rm -rf $RPM_BUILD_ROOT

%make_install

%files
%doc
%{_bindir}/*
%{_datadir}/*

%changelog
* Wed Sep 19 2012 Changed for SBR600 Course version 2.2-4
– built for course SBR600

4. Building RPMs:

$ rpmbuild -ba which.spec

5.Testing the RPMs

$ rpmlint ./which.spec
$ rpmlint ~/rpmbuild/SRPMS/which*.src.rpm

From → Uncategorized

Leave a Comment

Leave a comment