Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

multi version perl

by Thai Heng (Beadle)
on Jun 06, 2013 at 08:31 UTC ( #1037407=perlquestion: print w/ replies, xml ) Need Help??
Thai Heng has asked for the wisdom of the Perl Monks concerning the following question:

My operation system is ubuntu 12.04 lts, and the default perl version is 5.14.2. I install perl 5.18 in directory ~/localperl.

How can I redirect /usr/bin/perl to the new version perl 5.18 in ~/localperl?

Thanks!

Comment on multi version perl
Re: multi version perl (redirect /usr/bin/perl to ~/localperl )
by Anonymous Monk on Jun 06, 2013 at 08:43 UTC

    What you can do for your programs is change the Shebang to point to #!.../home/localperl/bin/perl --

    or  #!/usr/bin/env perl and adjust your $PATH to include ~/localperl/bin before /usr/bin

    See perlrun, Behind the GUI lives the Shell

    Do not be tempted to link /usr/bin/perl to ~/localperl..., you probably don't have permission, and you'll probably break your ubuntu

Re: multi version perl
by salva (Monsignor) on Jun 06, 2013 at 08:49 UTC
    Don't do that, it would break almost anything using the system perl.

    Also, check perlbrew, it allows you to install alternative perl versions and switch between them easyly.

      You should not redirect /usr/bin/perl for the reasons explained above, but you CAN reasonably redirect /usr/local/bin/perl to your new version of Perl and put that as the path to Perl in the magic perl start line.

      You should also arrange the path search for non-admin users to pick up the local perl instead of the system Perl.

      e.g. in /etc/profile or similar
      export PATH=/usr/local/bin;$PATH

      You may need to add/change other environment variables as well (PERL5INC, PERL5LIBS..)

      If you spot any bugs in my solutions, it's because I've deliberately left them in as an exercise for the reader! :-)
        You should also arrange the path search for non-admin users to pick up the local perl instead of the system Perl

        Why?

        I can see that would make sense in certain environments, but I don't see it as a general rule.

Re: multi version perl
by flexvault (Parson) on Jun 06, 2013 at 20:17 UTC

    Thai Heng,

    Since you are running Linux, you can do the following:

    ln -s /usr/local/bin/perl.5.18.x /usr/local/bin/[ourperl] ## [ ] wha +tever makes sense

    Also you should have a test script with 'use ...' for all CPAN modules that are required for your new Perl to work correctly. When Perl 5.20.x comes out, install/test it and then just change the link with the force parm ('-f') and everyone gets updated to the new Perl.

    Good Luck

    Regards...Ed

    "Well done is better than well said." - Benjamin Franklin

Re: multi version perl
by farang (Hermit) on Jun 06, 2013 at 22:20 UTC

    For a single user under Ubuntu 12.04, or a perl install just for a single user, you can take advantage of that system automagically placing the directory ~/bin/ if it exists at the front of the path. If you do this, no linking or manual fiddling with the path is necessary, and everything can be kept under the home directory.

    #!/bin/bash # doing this manually probably makes more sense :) if (! [ -d ~/bin/ ]; then mkdir ~/bin/; fi # create ~/bin/ if it does +n't already exist mv ~/localperl/* ~/bin/ # move the new perl install th +ere
    See from which path the perl executable will run from the command line:
    which perl
    I like using a shebang line #!/usr/bin/env perl to run scripts under the same version shown by which perl unless hard-coding to a particular version is desired.

    You'll still want to investigate setting PERL5LIB for module installations. Here is a decent simple explanation.

    Perlbrew as mentioned is a good alternative to all this.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1037407]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2014-09-01 12:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (6 votes), past polls