RPM Tips

Traditional Chinese Version

Be forewarned, I am not going to write anything on how to create an RPM spec file. There are enough howtos in the Internet on this regard. Writing an RPM spec file can be very simple, but it can also be very complicated, depending on the program you want to write an RPM spec file for. No matter what, this requires quite a lot of time.

When I do write an RPM spec file, my main references are:

http://www.rpm.org/max-rpm/
http://www.rpm.org/RPM-HOWTO/

I never ever want to install a program from source. It is not because it is difficult. On the contrary, it is quite easy to install from source. It is just that I do not want to mess up my system. When I update a program installed from source, quite often enough, there are old files around not deleted. And sometimes, this may cause some problems. If I want to uninstall this program, where do you go to make sure that all the installed files are really removed?

If at all possible, I would rather install an RPM. RPM updates and uninstalls programs very cleanly.

So, what I want to talk about is when you only have a source program available, are there ways to convert it to an RPM package?

If I need a particular program, I would first go to the installation CD to check if this program is already available. If not, I would then go to freshmeat, to sourceforge.net or maybe google.

If there is no RPM package available, I would search rpmfind.

But, if I am unable to find an RPM package of the program, what to do then? The following discussion might solve the problem, i.e., building the RPM package is possible after all.

But before you can build or rebuild an RPM, you need to install the rpm-build package:

rpm   -Uvh   rpm-build-4.4.2.2-7.fc8.i386.rpm

Note: The following howto works for Redhat/Fedora.

It is always recommended to build/rebuild an RPM package as a regular, not root, user. You also need to create the RPM build directories. Now login as a regular user and do the following:

mkdir   rpmbuild
mkdir   rpmbuild/BUILD
mkdir   rpmbuild/RPMS
mkdir   rpmbuild/RPMS/athlon
mkdir   rpmbuild/RPMS/i386
mkdir   rpmbuild/RPMS/i486
mkdir   rpmbuild/RPMS/i586
mkdir   rpmbuild/RPMS/i686
mkdir   rpmbuild/RPMS/noarch
mkdir   rpmbuild/SOURCES
mkdir   rpmbuild/SPECS
mkdir   rpmbuild/SRPMS

Now create the file .rpmmacros (look closely it is a dot file, i.e., the filename is preceded by a period) and the content is:

%_topdir   /home/username/rpmbuild

Replace username with the actual user account name.

We are now ready to build an RPM package. Please see this for reference.

Source RPM

If you want to install ClamAV anti-virus program, you may download the RPM package from crash-hat. It also provides a source rpm (.src.rpm). I prefer to download the source RPM and then rebuild it against my own server.

To do this, just execute the following command:

rpmbuild   --rebuild   clamav-0.93.1-1.src.rpm

After rebuilding the source RPM, you have the RPM files in:

rpmbuild/RPMS/i386/clamav-0.93.1-1.i386.rpm
rpmbuild/RPMS/i386/clamav-milter-0.93.1-1.i386.rpm
rpmbuild/RPMS/i386/clamav-devel-0.93.1-1.i386.rpm

Source Tarball with spec file

If, for example, you want to install SpamAssassin. No RPM package is made available. But what is provided contains the RPM spec file (Mail-SpamAssassin-3.2.5.tar.bz2 and Mail-SpamAssassin-3.2.5.tar.gz).

How do you know if an RPM spec file is included in the source tarball? Taking the two files above as an example, execute the following:

tar   fzt   Mail-SpamAssassin-3.2.5.tar.gz   |   grep   .spec
tar   fjt   Mail-SpamAssassin-3.2.5.tar.bz2   |   grep   .spec

Build the RPM packaged this way:

rpmbuild   -tb   Mail-SpamAssassin-3.2.5.tar.gz
rpmbuild   -tb   --define   "srcext   .bz2"   Mail-SpamAssassin-3.2.5.tar.bz2

Source tarball without spec file

I mentioned above that I do not want to install from source. So, what to do? Install CheckInstall and let it make an RPM for you.

The procedure for creating an RPM program is as follows:

tar   xvfz   program_name-version.tar.gz
cd   program_name-version
./configure
make

Now instead of executing:

make install

Execute instead:

checkinstall

Perl Modules

How I hate perl! It is very difficult to manage the perl module packages installed in your system. I absolutely refuse to install perl modules from source. It has been a cause of many problems. If you upgrade to a newer version from source, you might find that your application does not work anymore.

But I need a particular perl module package. What can I do? For example, we are using OpenWebMail in our school to access our emails. It requires a perl module Text-Iconv. As I do not want to install from source, I searched the Internet and found an RPM perl-Text-Iconv package. I downloaded and installed it. But OpenWebMail was still complaining that it could not find Text-Iconv. After a few days of scratching my head, I found out that the RPM perl-Text-Iconv that I downloaded and installed was compiled against a different version of perl. So it does not work. Now what to do?

I finally found the program cpan2rpm that solved my problem. Download and install it. And then just execute:

cpan2rpm   Text-Iconv-1.4.tar.gz

And it will create the following files:

rpmbuild/RPMS/i386/perl-Text-Iconv-1.4-1.i386.rpm
rpmbuild/SRPMS/perl-Text-Iconv-1.4.1.src.rpm

Note: The rpm package created by cpan2rpm are installed at /usr/local/lib/perl5 and not the standard Redhat/Fedora location at /usr/lib/perl5. This really does not matter since perl will find the modules anyway.


cpan2rpm note (2008/06/27):

cpan2rpm is broken since Fedora 8. According to this post:

https://bugzilla.redhat.com/show_bug.cgi?id=279251

you need to edit /usr/bin/cpan2rpm and change Pod::Text to Pod::Parser (2 places) and this solves the problem.


Perl Modules 2

Since Fedora 7, Fedora offers the tool cpanspec to build a spec file from cpan (perl module) which you can use to build an rpm package.

As an example, I will be creating the rpm package IP-Country-2.24.tar.gz.

Install cpanspec:

yum install cpanspec

yum will then install cpanspec and all its required file.

Download the cpan package (IP-Country-2.24.tar.gz) at:

http://search.cpan.org/~nwetters/IP-Country-2.24/lib/IP/Country.pm

Create the .spec file:

cpanspec --packager="you name here" IP-Country-2.24.tar.gz

cpanspec will create perl-IP-Country.spec

Building the rpm package:

  1. cp IP-Country-2.24.tar.gz rpmbuild/SOURCES/
  2. rpmbuild -ba perl-IP-Country.spec
  3. The newly built .rpm and .src.rpm packages are located at:
    rpmbuild/RPMS/noarch/perl-IP-Country-2.24-1.fc9.noarch.rpm
    rpmbuild/SRPMS/perl-IP-Country-2.24-1.fc9.src.rpm

Note: The rpm package created using cpanspec are installed at /usr/local/lib/perl5 and not the standard Redhat/Fedora location at /usr/lib/perl5. This really does not matter since perl will find the modules anyway.

Now you can install the RPM package without any problem.

Fr. Visminlu Vicente L. Chua, S.J.
2005/03/21
Updated: 2008/06/29