The camel survives!

About installing Perl in hostile environments.

Motivation

Right now I’m working on a Centos 6 Linux box. I have no cpan client

$ cpan
-bash: cpan: command not found

and a deprecated version of Perl :(

$ perl -v

This is perl, v5.10.1 ...

What is worse is that I will deploy on a host with no Internet access, probably with no root permissions … but there is a hope

The camel survives!

Bootstrap

Requirements

You need to install ExtUtils::MakeMaker.

If you get errors like

Can't locate ExtUtils/MakeMaker.pm in @INC

probabily is not installed. That is a silly choice of some Linux distros, yes I said silly cause ExtUtils::MakeMaker is a core module and it should be provided with any Perl distribution.

Get root permissions and install it, on Centos just launch

$ yum install perl-ExtUtils-MakeMaker

If you can’t do it, go straight and compile your own Perl: see .software.

Choose your target

Create a folder that will be your Perl home. To make it easier, I choose local::lib default

$ export PERL_BASE=~/perl5

Get cpanm

As documented in App::cpanminus related section, get a standalone cpanm executable to bootstrap your Perl.

$ mkdir -p $PERL_BASE/bin
$ cd $PERL_BASE/bin
$ curl -LO http://xrl.us/cpanm
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  262k  100  262k    0     0   279k      0 --:--:-- --:--:-- --:--:--  279k
$ chmod +x cpanm

Install local::lib

Now you can install local::lib locally

$ ./cpanm -l $PERL_BASE local::lib

Load special environment variables. Note that ~/.perl_profile file will be overwritten.

$ cd $PERL_BASE/lib/perl5
$ perl -Mlocal::lib=$PERL_BASE > ~/.perl_profile
$ source ~/.perl_profile

Make it permanent, edit your profile. For example you can launch

$ grep 'source ~/.perl_profile' ~/.bash_profile || echo 'source ~/.perl_profile' >> ~/.bash_profile

which will add source ~/.perl_profile to your .bash_profile only once.

Try it

At this point you have your system Perl with a cpanm that can install locally

Give it a try it, install Perl::Tidy

$ cpanm Perl::Tidy
   Working on Perl::Tidy
Fetching http://www.cpan.org/authors/id/S/SH/SHANCOCK/Perl-Tidy-20140328.tar.gz ... OK
Configuring Perl-Tidy-20140328 ... OK
Building and testing Perl-Tidy-20140328 ... OK
Successfully installed Perl-Tidy-20140328
1 distribution installed
$ which perltidy
~/perl5/bin/perltidy

Get CPAN

Now you can choose, to keep cpanm or get the official CPAN client

$ cpanm CPAN

Then maybe you want A CPAN client that works like a charm.

Upgrade Perl

Use Perlbrew to install, upgrade and manage your Perl installation.

$ export PERLBREW_ROOT=$PERL_BASE/perlbrew
$ echo export PERLBREW_ROOT=$PERLBREW_ROOT >> ~/.perl_profile

Install it

$ cpanm App::perlbrew

Then initialize it and add it to your environment with

$ perlbrew init

perlbrew root (~/perl5/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 ~/perl5/perlbrew/etc/bashrc

Simply run `perlbrew` for usage details.

Happy brewing!

$ source ~/perl5/perlbrew/etc/bashrc
$ echo 'source ~/perl5/perlbrew/etc/bashrc' >> ~/.perl_profile

Install patchperl (only once)

$ perlbrew install-patchperl

Now you can install and upgrade Perl easily, for example

$ perlbrew install perl-5.16.0
$ perlbrew switch perl-5.16.0

See also

2 comments:

  1. Why not use RPM package management so it's repeatable and supportable.
    cpanspec -b tarball.tgz or add one of the 100 yum repos out there.

    ReplyDelete
    Replies
    1. Using distros package management is ok if you are the owner of the machine. In my situation, I'm working in an environment where it takes a lot of time to get temporary root permissions to launch a "yum install perl-module-foo".

      Also, production machines does not point to arbitrary yum repo, only to official and trusted RedHat yum repo.

      So motivation is given not by a lack of technology, but rather by an excess of burocracy.

      Delete