简体   繁体   English

如何指定在CentOS上使用哪个版本的perl

[英]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 CentOS. 我正在运行CentOS 5.4,默认情况下只有版本5.8的perl可用,我有一个需要perl 5.10的程序,所以我在CentOS上编译了perl 5.10。 How do I specify which perl I want to run the program with because the perl command uses 5.8 by default. 如何指定我想运行程序的perl,因为perl命令默认使用5.8。

I add my voice to recommending against messing with the system perl at all. 我加上我的声音,建议不要乱用系统perl。

No one mentioned App::perlbrew yet. 没有人提到App :: perlbrew It allows you to have several versions of Perl and switch between them easily. 它允许您拥有多个Perl版本并轻松切换它们。 This can be done manually of course but it's much easier to have this tool to do it for you; 这当然可以手动完成,但是使用这个工具为你做这件事要容易得多; from the Pod– 来自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: eg 程序文件的第一行应该引用您想要使用的perl二进制文件:例如

#!/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. 您可能还想更改PATH变量,以便在5.8二进制目录之前列出perl 5.10二进制文件所在的目录。 eg 例如

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

I like to make symbolic links to my different perl executables in /usr/local/bin : 我喜欢在/usr/local/bin我的不同perl可执行文件的符号链接:

$ [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 eg your bin directories. 它基本上为您提供了一种通过操作例如bin目录中的符号链接在不同版本的应用程序之间切换的简便方法。

Say "man alternatives" in a terminal (or yum install alternatives, if you don't have it installed). 在终端中说“man alternative”(或者如果你没有安装yum安装替代品)。

set your PATH environment variable to point to your new perl executable. 设置PATH环境变量以指向新的perl可执行文件。 For instance 例如

 export PATH=/newpath/perl:$PATH

solution has two parts ... first edit myscript.pl which wants specific version 解决方案有两个部分...首先编辑需要特定版本的myscript.pl

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 上面对脚本的正常执行没有影响...当你想要上面的myscript.pl使用特定的perl版本时,创建一个包含脚本的包装脚本

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 这样,脚本的其他调用保持不变,它们只使用默认的perl,而启动器包装脚本使用选择的perl版本执行相同的myscript.pl脚本

BTW, The perlbrew package is available for installation from the EPEL repository for CentOS 5.x. BTW,perlbrew包可从CentOS 5.x的EPEL存储库安装。 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. 我最初尝试安装这个rpm,但它有许多依赖项,所以我选择将EPEL存储库添加到我的盒子上的yum repos列表中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不安装perlbrew的情况下指定用于脚本的perl版本 - How to specify which version of perl to use for a script without installing perlbrew 在CentOS 6.6上更新Perl版本 - Update Perl version on CentOS 6.6 如何指定链接时要使用的库版本? - How to specify the library version to use at link time? 如何在Linux中指定用于套接字的接口 - how to specify which interface to use for a socket in linux 如何强制PHP使用iconiconv版本的iconv而不是CentOS安装的glibc版本? - How can I force PHP to use the libiconv version of iconv instead of the CentOS-installed glibc version? 如何指定在Eclipse链接时使用的库版本? - How to specify the library version to use at link time in eclipse? 强制在 centos 中使用特定版本的 JAVA - Force to use specific version of JAVA in centos 如何指定要使用的基于OS的Java库? - How can I specify which OS based Java Library to use? 如何使用旧版本的glibc,以便在CentOS6上使用PyInstaller在REHL 3上运行Python脚本 - How to use an older version of glibc, for Python script to work on REHL 3, using PyInstaller on CentOS6 在Linux Centos 7下安装tcl / tk以与Perl 5一起使用-缺少步骤了吗? - Installing tcl/tk under Linux Centos 7 for use with Perl 5 - Missing a step?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM