开发者

How to specify which version of perl to use on CentOS

I am running CentOS 5.4 which only has version 5.8 of perl available by default, and I have a program which requires perl 5.10, so I compiled perl 5.10 on CentO开发者_运维技巧S. How do I specify which perl I want to run the program with because the perl command uses 5.8 by default.


I add my voice to recommending against messing with the system perl at all.

No one mentioned App::perlbrew yet. It allows you to have several versions of Perl and switch between them easily. This can be done manually of course but it's much easier to have this tool to do it for you; from the Pod–

# Install some Perls
perlbrew install perl-5.12.2
perlbrew install perl-5.8.1
perlbrew install perl-5.13.6

# See what were installed
perlbrew list

# Switch perl in the $PATH
perlbrew switch perl-5.12.2
perl -v

# Switch to another version
perlbrew switch perl-5.8.1
perl -v

# Switch to a certain perl executable not managed by perlbrew.
perlbrew switch /usr/bin/perl

# Or turn it off completely. Useful when you messed up too deep.
perlbrew off

# Use 'switch' command to turn it back on.
perlbrew switch perl-5.12.2


The first line of the program file should reference the perl binary you wish to use: e.g.

#!/usr/bin/perl

You may also want to change your PATH variable so that the directory your perl 5.10 binary is in is listed prior to the 5.8 binary directory. e.g.

export PATH=/path/to/perl/5.10:$PATH


I like to make symbolic links to my different perl executables in /usr/local/bin:

$ [sudo] ln -s /path/to/perl5.10.1.exe /usr/local/bin/perl510
$ [sudo] ln -s /path/to/perl5.13.8.exe /usr/local/bin/perl513
$ ... etc. ...
$ # and just for completeness
$ ln -s /usr/bin/perl /usr/local/bin/perl58

and then just invoke:

$ perl510 script_to_use_with_v5.10.pl


There is a tool called alternatives that was designed to deal effectively with exactly this kind of problem. It basically gives you an easy way of switching between different version of applications by manipulating symbolic links in e.g. your bin directories.

Say "man alternatives" in a terminal (or yum install alternatives, if you don't have it installed).


set your PATH environment variable to point to your new perl executable. For instance

 export PATH=/newpath/perl:$PATH


BTW, The perlbrew package is available for installation from the EPEL repository for CentOS 5.x. I tried to install just this rpm initially but it has a number of dependencies so I opted to add the EPEL repository to my list of yum repos on my box.


solution has two parts ... first edit myscript.pl which wants specific version

old
#!/usr/bin/perl

new
#!/usr/bin/env perl

above has no impact on normal executions of the script ... when you want above myscript.pl to use a specific perl version create a wrapper script which contains

export PATH=/cool/new/version/perl:$PATH
#  now execute script on following line
/path/to/myscript.pl

this way other invocations of the script remain unchanged and they just use default perl whereas launcher wrapper script executes same myscript.pl script with chosen perl version

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜