To install cpanspec

Type the following cpanspec command. First turn on EPEL repo for RHEL/CentOS 7(see how to turn on EPEL repo for RHEL/CentOS 6 here):

$ sudo yum install
$ sudo yum install cpanspec perl-ExtUtils-CBuilder perl-Module-Build perl-Test-Simpl

How to install compilers to build Perl module

You need setup a basic development environment with the following packages on a CentOS Enterprise Linux or Red Hat Enterprise Linux version 7. This is needed to build rpm files for Perl CPAN modules.

$ sudo yum group install "Development Tools"

See “CentOS / RHEL 7: Install GCC (C and C++ Compiler) and Development Tools” for more info.

How to use cpanspec

The syntax is pretty simple:

cpanspec moduleNameHere
cpanspec [options] moduleNameHere

How to build Perl module rpm file with cpanspec on RHEL/CentOS

Let us say we need a perl interface to the lchown() system call, on platforms that support it. For demo purpose I am going to build Lchown Perl CPAN module rpm:

$ cpanspec --follow --packager 'Vyga V <>' -v Lchown

  • --follow – Add build dependencies to the list of modules to process
  • --packager – The name and email address of the packager. Overrides the %packager macro in “~/.rpmmacros”.
  • -v – Be more verbose
  • Lchown – Generate a spec file to build an rpm from a CPAN-style Perl module distribution for Lchown

You should see two files as follows in the current directory using the ls command:

$ ls *.tar.gz *.spec
Lchown-1.01.tar.gz perl-Lchown.spec

A Perl-Lchown.spec file describes to rpmbuild how to build and package the Lchown perl module. You can view it with a text editor or cat command:

$ cat perl-Lchown.spec

Prepare the source directory

Create ~/rpmbuild/SOURCES/ directory using mkdir command:

$ mkdir -pv ~/rpmbuild/SOURCES/

Copy the Lchown-1.01.tar.gz source tar ball into the SOURCES directory, so the rpmbuild command can locate it using the cp command:

$ cp -v ~/Lchown-1.01.tar.gz ~/rpmbuild/SOURCES/

Build the RPM with rpmbuild

Run the following command:

$ rpmbuild -ba perl-Lchown.spec

The -ba option to the rpmbuild command tell to build source and binary packages from given .spec file. You should see lots of output. At the bottom you of the screen you should list of files created:

Now all you have to do is install perl-Lchown-1.01-1.el7.centos.x86_64.rpm file:

$ sudo yum install ~/rpmbuild/RPMS/x86_64/perl-Lchown-1.01-1.el7.centos.x86_64.rpm

You may want to sing RPM with gpg for security (provided that you have GPG configured with a key):

$ rpmsign --addsign ~/rpmbuild/RPMS/x86_64/perl-Lchown-1.01-1.el7.centos.x86_64.rpm


Was this answer helpful? 0 Users Found This Useful (0 Votes)