25 October 2013
Alternate Perls Revisited
https://techinfo.brainbuz.org/posts/alternate-perls/
Since then my approach has refined.
First, I’ve switched from using perl5 as the alternate location of my custom perl to setting my environment to use the correct Perl and env perl in the shebang line. I find this is more maintainable because scripts installed via package management usually specify the path to the system installed perl, but scripts that expect a custom perl can still try to use system perl. While the perl5 approach was very explicit, it became confusing when I moved scripts to new hosts that didn’t have perl5 linked, the env approach falls back to system perl when no alternate perl is set in the environment.
The other change is that I like the plenv and perl-build combination better than I like perlbrew.
For development I use plenv to manage my perls, and install perl-build as a plug-in to actually install them. For deployment I can use perl-build standalone.
The documentation for both plenv and perl-build is on cpan but the author recommends installing them both from github. I recommend following the directions for installing plenv to manage user copies of perl.
Plenv has a few nice features that PerlBrew lacks, for me the killer is the ability to migrate modules, which actually reinstalls them. While this can remain a problem for some of the hard to build modules you might have installed from package management, it still saves you having to remember or document everything you installed.
When it is time to deploy an alternate Perl, you only need perl-build, run this as the user that is going to manage the installation, likely either yourself or root. In cases where you’re going to only use one system-wide custom Perl I recommend not using plenv, because you won’t need the switching functionality. The nice thing about perl-build is it lets you specify exactly where to install Perl (even if when used in conjunction with plenv the latter wants to bury them in your home directory) so you can pick something nice and clean like /opt/perl or /opt/perl-x.xx.
Once you’ve installed your perl just add a line to the end of /etc/profile or bash.bashrc: source PATH="/opt/perl/bin:$PATH". Then in your scripts use the shebang line: #!/usr/bin/env perl.
Another nice part of this approach is that it is extremely easy to tar /opt/perl and copy it to another system running the same architecture.