Installing Your Own Perl
(Geek entry ahead, so if you're not into this kind of thing, then there's nothing really to see here.)
I write Perl for a living. Over the years, one thing I've learned not to do is rely on the version of Perl that shipped with the OS. Instead, I leave it well alone and just install my own version. There are a couple of reasons why.
For one thing, perhaps the system version of Perl is older than you'd like and missing some new features or bugfixes. Perhaps the system version of Perl was compiled with a compiler you don't have installed on the box. Maybe a system upgrade will also upgrade Perl and clobber your existing installation. I don't want to have to worry about any of that.
These days thanks to App::perlbrew, installing your own Perl is ridiculously easy. Let's take a look.
First of all, let's pull down and install the latest version of perlbrew.
shell> curl -L http://xrl.us/perlbrewinstall | bash
perlbrew will be installed in ~/perl5/perlbrew/bin/perlbrew and then you'll need to add the following to your ~/.bashrc:
source ~/perl5/perlbrew/etc/bashrc
The beauty of perlbrew is that you can install different versions of Perl, all separate from each other, and you can switch between them at will. So let's see what versions of Perl we can install with perlbrew.
shell> perlbrew available
perl-5.15.1
perl-5.14.1
perl-5.12.4
perl-5.10.1
perl-5.8.9
perl-5.6.2
perl5.005_04
perl5.004_05
perl5.003_07
Nice, so let's install 5.14.1.
shell> perlbrew install perl-5.14.1
That will crank for a while, but once done, Perl 5.14.1 will be installed in ~/perl5/perlbrew/perls/perl-5.14.1. Which is great, but how do we use it?
shell> perlbrew switch perl-5.14.1
shell> which perl
/Users/kevinspencer/perl5/perlbrew/perls/perl-5.14.1/bin/perl
shell> perl -v
This is perl 5, version 14, subversion 1 (v5.14.1) built for darwin-2level
Nice. If you want to install another version of Perl alongside, just repeat the above and switch to it.
shell> perlbrew switch perl-5.12.1
None of that touched the system version of Perl in any way, it's all self contained in your home directory. Which is the beauty of perlbrew. If for whatever reason though you want to go back and use the system Perl, just turn off perlbrew.
shell> perlbrew off
One last thing I've learned about installing a separate Perl. Don't hardcode the shebang line in your programs, let the environment help you out.
#!/usr/bin/env perl
Need to point out that some OS might have "/bin/env" instead of "/usr/bin/env". From the "perlrun" perldoc, this snippet seems to be very portable among UNIXes
#!/bin/sh
#! −*−perl−*−
eval 'exec perl −x −wS $0 ${1+"$@"}'
if 0;
Impossible to be memorized, however :)
@gugod, thank you mate. And thank you for App::perlbrew.
Hey thanks!!
Great information!!!
@satish, you're welcome.
I use a perlbrew alias to point to my current/favorite perl and point all my shebangs to that alias.
Then when I install a new perl I can adjust the alias and everything will work again.
This ensures that the script will be called from a perl that has the necessary modules installed and works consistently with distributing modules with EUMM.
See my response post for more (rationale, blabbering, etc):
http://blogs.perl.org/users/randy_stauner/2011/09/shebangs-with-perlbrew-aliases-and-eumm-and-without-locallib.html