How to specify which version of perl to use on Cen

2019-03-20 19:06发布

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 CentOS. How do I specify which perl I want to run the program with because the perl command uses 5.8 by default.

7条回答
够拽才男人
2楼-- · 2019-03-20 19:11

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

 export PATH=/newpath/perl:$PATH
查看更多
我命由我不由天
3楼-- · 2019-03-20 19:12

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
查看更多
ら.Afraid
4楼-- · 2019-03-20 19:21

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
查看更多
放荡不羁爱自由
5楼-- · 2019-03-20 19:21

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.

查看更多
我想做一个坏孩纸
6楼-- · 2019-03-20 19:22

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

查看更多
冷血范
7楼-- · 2019-03-20 19:30

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).

查看更多
登录 后发表回答