www.jdmz.net troy.jdmz.net

Multiple Perl Installations
Why Would You?
As a system administrator, I like keeping the Perl installation from a vendor pristine, whether it is from Sun or a Linux distribution, because they typically package tools that depend on the packaged Perl and Perl modules. They try to keep that Perl, and the modules they choose to package with it, stable and secure for everyone who uses their OS. For most folks, the packaged Perl is enough, but some people need newer (or older) versions of packaged modules, or they need to install modules that are not packaged. Upgrading packaged modules outside of the packaging scheme, or installing new and/or non-packaged modules, could have a destabilizing effect on your packaged Perl installation.
Also, I like to change default Perl installs quickly and easily. I have had to upgrade Perl for a bunch of scripts that used the #!/usr/local/bin/perl she-bang line. Modifying each script to test with the new Perl version, then replacing the "Old Perl" with the "Test Perl" and modifying the scripts again was "too much fooling around".
It turns out that having your own custom Perl, or even a few of them, isn't very costly. I'll use an example with four different Perl versions.
If it turns out that you are not a system administrator, but you want to excersize the same amount of control over your Perl installations, then give Perlbrew a try!
Perl 5.8.x
For Perl 5.8.8 (5.8.9 didn't work for me) I did this:
sudo mkdir /usr/local/perl/5.8.8
sudo chown $USER:$USER /usr/local/perl/5.8.8
cd /usr/local/perl/5.8.8/
mkdir build cpan
cd build/
wget http://www.cpan.org/src/5.0/perl-5.8.8.tar.gz
tar xzvf perl-5.8.8.tar.gz
cd perl-5.8.8
rm -f config.sh Policy.sh ; sh Configure -de -Dprefix=/usr/local/perl/5.8.8
make && make test && make install
/usr/local/perl/5.8.8/bin/perl -MCPAN -e shell
Now I could answer all the "file path" related questions with /usr/local/perl/5.8.8/cpan/ instead of /home/$USER/.cpan/, but I will edit the file later, so I let it "autoconfigure" as much as it can, including finding the closest mirrors. At the end of the configuration process I type exit at the prompt.

I edit it the file name the configuration process said it wrote at the end:

vi /usr/local/perl/5.8.8/lib/5.8.8/CPAN/Config.pm

and I change the paths:

to the /usr/local/perl/5.8.8/cpan/ prefix if I "autoconfigured" everything, and I will put my mirror (leave it alone if you don't have one) at the front of the "urllist" variable: and I will save it.

I then execute the CPAN shell again, making sure there are no errors:

/usr/local/perl/5.8.8/bin/perl -MCPAN -e shell

At the prompt I ask CPAN to install the CPAN and LWP "bundles" (and required supporting modules):

install Bundle::CPAN Bundle::LWP

I will observe whether the file fetching parts used my mirror or not. If not, my mirror may be down, or more likely I mis-keyed the configuration file.

Perl 5.10.x

For Perl 5.10.1 I did this:

sudo mkdir /usr/local/perl/5.10.1
sudo chown $USER:$USER /usr/local/perl/5.10.1
cd /usr/local/perl/5.10.1/
mkdir build cpan
cd build/
wget http://www.cpan.org/src/5.0/perl-5.10.1.tar.gz
tar xzvf perl-5.10.1.tar.gz
cd perl-5.10.1
rm -f config.sh Policy.sh ; sh Configure -de -Dprefix=/usr/local/perl/5.10.1
make && make test && make install
/usr/local/perl/5.10.1/bin/perl -MCPAN -e shell

Now I could answer all the "file path" related questions with /usr/local/perl/5.10.1/cpan/ instead of /home/$USER/.cpan/, but I will edit the file later, so I let it "autoconfigure" as much as it can, including finding the closest mirrors. At the end of the configuration process I type exit at the prompt.

I edit it the file name the configuration process said it wrote at the end:

vi /usr/local/perl/5.10.1/lib/5.10.1/CPAN/Config.pm

and I change the paths:

to the /usr/local/perl/5.10.1/cpan/ prefix if I "autoconfigured" everything, and I will put my mirror (leave it alone if you don't have one) at the front of the "urllist" variable: and I will save it.

I then execute the CPAN shell again, making sure there are no errors:

/usr/local/perl/5.10.1/bin/perl -MCPAN -e shell

At the prompt I ask CPAN to install the CPAN and LWP "bundles" (and required supporting modules):

install Bundle::CPAN Bundle::LWP

I will observe whether the file fetching parts used my mirror or not. If not, my mirror may be down, or more likely I mis-keyed the configuration file.

Perl 5.12.x

For Perl 5.12.2 I did this:

sudo mkdir /usr/local/perl/5.12.2
sudo chown $USER:$USER /usr/local/perl/5.12.2
cd /usr/local/perl/5.12.2/
mkdir build cpan
cd build/
wget http://www.cpan.org/src/5.0/perl-5.12.2.tar.gz
tar xzvf perl-5.12.2.tar.gz
cd perl-5.12.2
rm -f config.sh Policy.sh ; sh Configure -de -Dprefix=/usr/local/perl/5.12.2
make && make test && make install
/usr/local/perl/5.12.2/bin/perl -MCPAN -e shell

Now I could answer all the "file path" related questions with /usr/local/perl/5.12.2/cpan/ instead of /home/$USER/.cpan/, but I will edit the file later, so I let it "autoconfigure" as much as it can, including finding the closest mirrors. At the end of the configuration process I type exit at the prompt.

I edit it the file name the configuration process said it wrote at the end:

vi /usr/local/perl/5.12.2/lib/5.12.2/CPAN/Config.pm

and I change the paths:

to the /usr/local/perl/5.12.2/cpan/ prefix if I "autoconfigured" everything, and I will put my mirror (leave it alone if you don't have one) at the front of the "urllist" variable: and I will save it.

I then execute the CPAN shell again, making sure there are no errors:

/usr/local/perl/5.12.2/bin/perl -MCPAN -e shell

At the prompt I ask CPAN to install the CPAN and LWP "bundles" (and required supporting modules):

install Bundle::CPAN Bundle::LWP

I will observe whether the file fetching parts used my mirror or not. If not, my mirror may be down, or more likely I mis-keyed the configuration file.

Perl 5.14.x

For Perl 5.14.2 I did this:

sudo mkdir /usr/local/perl/5.14.2
sudo chown $USER:$USER /usr/local/perl/5.14.2
cd /usr/local/perl/5.14.2/
mkdir build cpan
cd build/
wget http://www.cpan.org/src/perl-5.14.2.tar.gz
tar xzvf perl-5.14.2.tar.gz
cd perl-5.14.2
rm -f config.sh Policy.sh ; sh Configure -de -Dprefix=/usr/local/perl/5.14.2
make && make test && make install
/usr/local/perl/5.14.2/bin/perl -MCPAN -e shell

Now I could answer all the "file path" related questions with /usr/local/perl/5.14.2/cpan/ instead of /home/$USER/.cpan/, but I will edit the file later, so I let it "autoconfigure" as much as it can, including finding the closest mirrors. At the end of the configuration process I type exit at the prompt.

I move the file name the configuration process said it wrote at the end to a common location and then edit it:

mv $HOME/.cpan/CPAN/MyConfig.pm /usr/local/perl/5.14.2/lib/5.14.2/CPAN/Config.pm
vi /usr/local/perl/5.14.2/lib/5.14.2/CPAN/Config.pm

and I change the paths:

to the /usr/local/perl/5.14.2/cpan/ prefix if I "autoconfigured" everything, and I will put my mirror (leave it alone if you don't have one) at the front of the "urllist" variable: and I will save it.

I then execute the CPAN shell again, making sure there are no errors:

/usr/local/perl/5.14.2/bin/perl -MCPAN -e shell

At the prompt I ask CPAN to install the CPAN and LWP "bundles" (and required supporting modules):

install Bundle::CPAN Bundle::LWP Task::Plack

I will observe whether the file fetching parts used my mirror or not. If not, my mirror may be down, or more likely I mis-keyed the configuration file.

Perl 5.34.x

For Perl 5.34.1 I did this:

sudo mkdir /usr/local/perl/5.34.1
sudo chown $USER:$USER /usr/local/perl/5.34.1
cd /usr/local/perl/
mkdir build cpan
cd build/
wget http://www.cpan.org/src/perl-5.34.1.tar.gz
tar xzvf perl-5.34.1.tar.gz
cd perl-5.34.1
rm -f config.sh Policy.sh ; sh Configure -de -Dprefix=/usr/local/perl/5.34.1
make && make test && make install
/usr/local/perl/5.34.1/bin/perl -MCPAN -e shell

Now I could answer all the "file path" related questions with /usr/local/perl/5.34.1/cpan/ instead of /home/$USER/.cpan/, but I will edit the file later, so I let it "autoconfigure" as much as it can, including finding the closest mirrors. At the end of the configuration process I type exit at the prompt.

I move the file name the configuration process said it wrote at the end to a common location and then edit it:

mv $HOME/.cpan/CPAN/MyConfig.pm /usr/local/perl/5.34.1/lib/5.34.1/CPAN/Config.pm
vi /usr/local/perl/5.34.1/lib/5.34.1/CPAN/Config.pm

and I change the paths:

to the /usr/local/perl/5.34.1/cpan/ prefix if I "autoconfigured" everything, and I will put my mirror (leave it alone if you don't have one) at the front of the "urllist" variable: and I will save it.

I then execute the CPAN shell again, making sure there are no errors:

/usr/local/perl/5.34.1/bin/perl -MCPAN -e shell

At the prompt I ask CPAN to install the CPAN and LWP "bundles" (and required supporting modules):

install Bundle::CPAN Bundle::LWP Task::Plack

I will observe whether the file fetching parts used my mirror or not. If not, my mirror may be down, or more likely I mis-keyed the configuration file.

Common Flexible Binary

To make the different versions of Perl easy to use and change, the Perl binaries have to be in the PATH. Typically /usr/local/bin/ is in the path, so that is where I want to put my Perl binaries. Because I want to use my custom Perl binaries by default, I will check my path and make sure /usr/local/bin/ comes before /usr/bin/ (or wherever the packaged Perl binaries are located) [1].

I will then create a default Perl symbolic link at /usr/local/perl and point it at the Perl version I want to use by default.

su -
cd /usr/local/perl
ln -s 5.34.1 current
I also want the other versions to be available without typing the full path, so I will do this:
cd /usr/local/bin/
for f in /usr/local/perl/5.8.8/bin/* ; do echo $f ; b=`basename $f` ; ln -s $f ${b}588 ; done
for f in /usr/local/perl/5.10.1/bin/* ; do echo $f ; b=`basename $f` ; ln -s $f ${b}5101 ; done
for f in /usr/local/perl/5.12.2/bin/* ; do echo $f ; b=`basename $f` ; ln -s $f ${b}5122 ; done
for f in /usr/local/perl/5.14.2/bin/* ; do echo $f ; b=`basename $f` ; ln -s $f ${b}5142 ; done
for f in /usr/local/perl/5.34.1/bin/* ; do echo $f ; b=`basename $f` ; ln -s $f ${b}5341 ; done

but, then again, typing the full path is not too hard (and that is a lot of links). I will then make the default binary links:

cd /usr/local/bin/
for f in /usr/local/perl/current/bin/* ; do echo $f ; b=`basename $f` ; if [ ! -f $b ]; then ln -s $f $b ; fi ; done

The if avoids name collisions with version specific binaries.

Install A Snapshot

I usually want the same modules installed in all versions of Perl I have installed. If you already have the modules installed in one installation of Perl (and the modules are in CPAN), you can make a snapshot of your installation and easily install it in another. Lets say that I have all the modules I want installed in my 5.10.1 installation of Perl. If so, I can:

/usr/local/perl/5.10.1/bin/perl -MCPAN -e autobundle

A whole lot of output will be produced and at the end it will print Wrote bundle file and a file path (in this instance /usr/local/perl/5.10.1/cpan/Bundle/Snapshot_2010_09_16_00.pm). I will take this file and use it to install the listed modules in my new 5.12.2 installation of Perl:

if [ ! -d /usr/local/perl/5.12.2/cpan/Bundle ]; then mkdir /usr/local/perl/5.12.2/cpan/Bundle; fi
cp /usr/local/perl/5.10.1/cpan/Bundle/Snapshot_2010_09_16_00.pm /usr/local/perl/5.12.2/cpan/Bundle/
/usr/local/perl/5.12.2/bin/perl -MCPAN -e "install Bundle::Snapshot_2010_09_16_00"

If there are a lot of modules to install it could take a considerable amount time. I often use screen to make it easier on me.

Keeping Perl Up To Date

This process I layout is "uncareful" with regard to Perl installation stability. Somethings may break when you install all the newest versions of every module installed. If this prospect bothers you, you may want to install a "Test Perl" (the same version as the one you want to keep stable, maybe at /usr/local/perl/5.12.2test/) and try out the upgrade there first.

If you don't care, and just want the latest of everything, just do this:

/usr/local/perl/5.8.8/bin/perl -MCPAN -e upgrade
/usr/local/perl/5.10.1/bin/perl -MCPAN -e upgrade
/usr/local/perl/5.12.2/bin/perl -MCPAN -e upgrade
/usr/local/perl/5.14.2/bin/perl -MCPAN -e upgrade
/usr/local/perl/5.34.1/bin/perl -MCPAN -e upgrade

Each process could take a considerable amount of time. Again, I often use screen to make it easier on me.

Managing Ownership Of Perl

I like having my Perl installations owned by someone other than root. Running a ton of code as root can be avoided here, and so it should [2].

On my own personal servers, I don't mind that person being me (but I see that it could be a risk), but that arrangement may not work for groups larger than one.

For those situations, I think making a perladm user and group might serve:

sudo groupadd perladm
sudo useradd -m -g perladm -c "Perl Install Administrator" perladm

Then apply the permissions to the installations:

cd /usr/local/
sudo chown -R perladm:perladm perl

When you need to update or change an installation in some way, you will then want to become the 'perladm' user with su or sudo.

Notes:
[1] Different shells want the PATH set in different places. You'll probably be modifying a file within the /etc/ directory to change the default path for the entire system.
[2] The more limited the user, the less risk. I want my updates to work within the filesystem tree it owns and not outside it.
© 2022 Troy Johnson
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license should be available here and here.
The current copy of this document should be available here.
www.jdmz.net troy.jdmz.net