Installing perlbrew on Centos/Rhel/Fedora

Published on Author gryzli

Why you may need perlbrew ?

Perlbrew gives you the ability to maintain multiple perl versions, each having different set of install perl modules. The concept is not any new, we have already seen such things in Python (virtualenv) or Ruby (rvm).

Basically you get the following benefits (as state in the perlbrew site also):

  • No need to use ‘sudo’ in order to install packages from cpan
  • You could have as much versions as you like
  • Easily switch between perl versions or version with custom module sets
  • Getting out from the DIstro-shipped perl version
  • Setup seamless environment for all of your perl scripts running on different distro versions (for example if you have multiple Centos 5, 6,7 servers)

Installing perlbrew in custom directory

Installing of perlbrew is straight forward and easy. I prefer using user-defined custom directory for my perlbrew installation.

By default it will be installed in ~/perl5/perlbrew , which I don’t want.

For the current example, I’m going to install perlbrew in /usr/local/perlbrew .

root@server [/usr/src]# curl -k  -L https://install.perlbrew.pl > perlbrew_install.sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1247 100 1247 0 0 1026 0 0:00:01 0:00:01 --:--:-- 1026

 

root@server [/usr/src]# chmod u+x perlbrew_install.sh 
root@server [/usr/src]# export PERLBREW_ROOT="/usr/local/perlbrew"
root@server [/usr/src]# ./perlbrew_install.sh 
## Download the latest perlbrew

## Installing perlbrew
perlbrew is installed: /usr/local/perlbrew/bin/perlbrew

perlbrew root (/usr/local/perlbrew) is initialized.

Append the following piece of code to the end of your ~/.bash_profile and start a
new shell, perlbrew should be up and fully functional from there:

    source /usr/local/perlbrew/etc/bashrc

Simply run `perlbrew` for usage details.

Happy brewing!

## Installing patchperl

## Done.

 

Install custom perl version (5.24.0) under perlbrew

 

Now, as we already have perlbrew, we must go on and install alternative version. In the current example, I will install version “5.24.0”, but  you could install any other version.

 

1| Activate the perlbrew environment

root@server [/usr/src]# source /usr/local/perlbrew/etc/bashrc

 

2| Install perl 5.24.0

Installing the custom version is as easy as executing the following:

 

perlbrew install 5.24.0

If you want to speed up the process (in my case about 5x times), you could disable testing and use multi-thread compilation .

This is the faster way to install your custom perl version:

perlbrew -n -j4 install 5.24.0

-n - Stays for "not doing tests"

-j4 - Use 4 cores for parallel compilation

 

3| Install some custom modules

I prefer installing custom modules by using “cpanm”.

First you need to install cpanm:

perlbrew install-cpanm

Then you can easy install some custom module, for example “LWP::Protocol”

cpanm  LWP::Protocol

 

 

Using the newly installed perl

Here is example of how to use the newly installed version:

root@server [~]# perl -v  

This is perl, v5.8.8 built for x86_64-linux 

Copyright 1987-2006, Larry Wall 

Perl may be copied only under the terms of either the Artistic License or the 
GNU General Public License, which may be found in the Perl 5 source kit. 

Complete documentation for Perl, including FAQ lists, should be found on 
this system using "man perl" or "perldoc perl".  If you have access to the 
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

root@manvps [~]# perlbrew  list

* perl-5.24.0

root@server [~]#  source /usr/local/perlbrew/etc/bashrc 
root@server [~]# perlbrew  switch perl-5.24.0                       
root@server [~]# perl -v  

This is perl 5, version 24, subversion 0 (v5.24.0) built for x86_64-linux 
(with 1 registered patch, see perl -V for more detail) 

Copyright 1987-2016, Larry Wall 

Perl may be copied only under the terms of either the Artistic License or the 
GNU General Public License, which may be found in the Perl 5 source kit. 

Complete documentation for Perl, including FAQ lists, should be found on 
this system using "man perl" or "perldoc perl".  If you have access to the 
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

 

Using perlbrew perl in cron

You may need to setup some cron scripts, where you want to use your newly installed alternative perl version. One easy way to do this is by using: “perlbrew-cron”, which could be found here:

perlbrew-cron