How to specify which version of perl to use on CentOS

I am running CentOS 5.4, which by default has version 5.8 perl, and I have a program that requires perl 5.10, so I compiled perl 5.10 on CentOS. How to specify which perl I want to run the program because the perl command uses default 5.8.

+5
source share
7 answers

I add my vote to recommend against a mess with the perl system in general.

No one mentioned App :: perlbrew . It allows you to have multiple versions of Perl and easily switch between them. Of course, this can be done manually, but it is much easier to make this tool for you; from 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
+13
source

The first line of the program file should refer to the perl binary you want to use: for example.

#!/usr/bin/perl

You can also change your PATH variable so that the directory where your perl 5.10 binary is located is listed before the 5.8 binary. eg.

export PATH=/path/to/perl/5.10:$PATH
+5
source

perl /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

:

$ perl510 script_to_use_with_v5.10.pl
+2

, , . , , . bin.

" " ( yum , ).

+1

PATH, perl. ,

 export PATH=/newpath/perl:$PATH
0

BTW, perlbrew EPEL CentOS 5.x. , , EPEL yum .

0

... myscript.pl,

old
#!/usr/bin/perl

new
#!/usr/bin/env perl

does not affect the normal execution of the script ... when you want a specific version of perl to be used on myscript.pl, create a script wrapper that contains

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

That way, other script calls remain unchanged, and they just use default perl, while the script launch shell executes the same myscript.pl script with the selected version of perl

0
source

All Articles