Martin90 has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I have installed another perl version in 'opt' dir , and I have few question related to work with this newly installed perl.

If I understand correctly in order to use this perl version in my scripts I have to do two things. First add new perl path to environment $PATH variable by shell command "export PATH=$PATH:/opt/perl-version/bin/perl" and second, add this path with shebang to all script "#!/opt/perl-version/bin/perl". Is it ok ?

And the most important question how to install CPAN modules to that fresh instalation ?

Regards.

UPDATE:

SOLVED! ;) As it turned out #!/opt/perl-5.16/bin/perl was right shebang.

Thanks you

  • Comment on Install CPAN module to another perl version

Replies are listed 'Best First'.
Re: Install CPAN module to another perl version
by Anonymous Monk on Aug 14, 2014 at 17:25 UTC

    Your PATH should be pointing at the directory, not the binary, and if you want your system to find that perl first, it should come first in the path. So e.g. PATH="/opt/perl-version/bin:$PATH"

    Your shebang line is fine. You could also use "#!/usr/bin/env perl" to get the perl that comes first in your PATH.

    You can use the regular CPAN to install modules. Check with "which cpan" that you're calling the right version, or call it explicitly via "/opt/perl-version/bin/cpan".

Re: Install CPAN module to another perl version
by Anonymous Monk on Aug 14, 2014 at 19:46 UTC

    To install, this ought to work  /path/to/perl/bin/cpan Module Module

    To install, this ought to work  /opt/perl-version/bin/cpan Module Module

    To run your program you can use  /opt/perl-version/bin/perl program.pl

    Or have as your shebang (first line in your file) #!/opt/perl-version/bin/perl -- then you can run the file like by typing  /path/to/your/file.pl or ./file.pl

    Or prepend these dirs to your $PATH (this program will print them, you export in your shell or .bashrc/.profile as shown below)

    #!/opt/perl-version/bin/perl -- use Config; for my $bin( @Config{qw/ sitebin vendorbin bin/} ){ $seen{$bin}++ or print $bin; } } __END__ export $PATH=/opt/perl-version/bin;...;...;...;$PATH

    then perl yourprogram.pl runs /opt/perl-version/bin/perl yourprogram.pl

    then a shebang of #!/usr/bin/env perl -- runs /opt/perl-version/bin/perl yourprogram.pl

    Running your code from shell is discussed in the following Behind the GUI lives the Shell and perlintro / perlrun and UNIX Man Pages env, export

      Thanks for replies, unfortunately perl doesn't see new installed module.

      I added PATH="/opt/perl-5.16/bin:$PATH" to $PATH variable, saved.

      When I ask: "which perl" I get repsonse "/opt/perl-5.16/bin/perl",

      when I ask: "which cpan", I get resposne "/opt/perl-5.16/bin/cpan" #Hmm is it ok ? Should CPAN be located there ?

      Then I install my module via "CPAN INSTALL MODULE" the whole proces goes ok, but my app doesn't see this new module in @INC and return:

      Can't locate MODULE.pm in @INC (@INC contains: Plugins Modules . /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi /usr/lib/perl5/5.8.8) (..)

      It is still looking in "/usr/lib/perl5", whats wrong ?

      PS: When I change my shebang from "#!/usr/bin/env perl " to "#!/opt/perl-5.16/bin/perl" I get Internal Server Error.

      What's wrong ? ;/