简体   繁体   English

perl cpan模块安装

[英]perl cpan module installation

I have a server where I've installed some perl modules. 我有一台服务器,其中已经安装了一些perl模块。 I installed the first few via CPAN, ie perl -MCPAN -e 'install Module::Name' as a non-root user. 我通过CPAN安装了前几个,即以非root用户身份使用perl -MCPAN -e'install Module :: Name'。

Then I ran into some issues, and just started installing them via sudo or root. 然后我遇到了一些问题,并开始通过sudo或root安装它们。

I found out last night via some output from a cron job, that some of the scripts are failing because they can't locate the modules in the @INC array. 昨晚我从cron作业的一些输出中发现,某些脚本失败了,因为它们无法在@INC数组中找到模块。

I discovered that on the server in question, perl -V shows the following: 我发现有问题的服务器上,perl -V显示以下内容:

as root: 作为根:

%ENV:
  PERL5LIB="/root/perl5/lib/perl5:"
  PERL_LOCAL_LIB_ROOT=":/root/perl5"
  PERL_MB_OPT="--install_base /root/perl5"
  PERL_MM_OPT="INSTALL_BASE=/root/perl5"
@INC:
  /root/perl5/lib/perl5/x86_64-linux-thread-multi
  /root/perl5/lib/perl5
  /usr/local/lib64/perl5
  /usr/local/share/perl5
  /usr/lib64/perl5/vendor_perl
  /usr/share/perl5/vendor_perl
  /usr/lib64/perl5
  /usr/share/perl5

and as a non-root user: 并以非root用户身份:

%ENV:
  PERL5LIB="/home/user/perl5/lib/perl5:"
  PERL_LOCAL_LIB_ROOT=":/home/user/perl5"
  PERL_MB_OPT="--install_base /home/user/perl5"
  PERL_MM_OPT="INSTALL_BASE=/home/user/perl5"
@INC:
  /home/user/perl5/lib/perl5/x86_64-linux-thread-multi
  /home/user/perl5/lib/perl5
  /usr/local/lib64/perl5
  /usr/local/share/perl5
  /usr/lib64/perl5/vendor_perl
  /usr/share/perl5/vendor_perl
  /usr/lib64/perl5
  /usr/share/perl5

I checked another server, where installation of perl modules has never had a problem, and it shows the same output whether run as a non-root user or root, and only has @INC, no $ENV defined. 我检查了另一台服务器,其中的perl模块安装从未出现问题,并且无论以非root用户或root身份运行,它都显示相同的输出,并且仅具有@INC,未定义$ ENV。

@INC:
  /usr/local/lib64/perl5
  /usr/local/share/perl5
  /usr/lib64/perl5/vendor_perl
  /usr/share/perl5/vendor_perl
  /usr/lib64/perl5
  /usr/share/perl5

So my question is, How can I configure CPAN on the server I'm having problems to not have different Environments and @INC values for different users. 所以我的问题是,如何在服务器上配置CPAN遇到问题,即对于不同的用户没有不同的环境和@INC值。 I'd rather it just have one default system location for perl modules that are accessible by all. 我希望它对所有人都可以访问的perl模块只有一个默认系统位置。 I assume I need to run o conf init from the CPAN shell, or edit /root/.cpan/CPAN/MyConfig.pm and /home/user/.cpan/CPAN/MyConfig directly, but not too sure what exact edits I need to make. 我假设我需要从CPAN Shell运行conf init,或者直接编辑/root/.cpan/CPAN/MyConfig.pm和/home/user/.cpan/CPAN/MyConfig,但不太确定我需要什么确切的编辑做。

Thank you, 谢谢,

Since cron tasks could be defined as "system" related I'd do as @ikegami suggests and stick with the system perl and use the package manager to keep the environment consistent across users. 由于可以将cron任务定义为与“系统”相关的任务,因此我将按照@ikegami的建议进行操作,并坚持使用系统perl并使用程序包管理器来保持用户之间环境的一致性。 It's best to keep root and /root out of the picture: if root is installing to their $HOME you might as well just use system packages. 最好不要使用root/root :如果root正在安装到其$ HOME,则最好使用系统软件包。

If you are creating custom scripts for cron and running them as a user then you can create a consistent perl environment (or several) for that user with perlbrew , local::lib (which you seem to already have installed) and cpanminus (which can be installed alongside and work seamlessly with perlbrew ). 如果要为cron创建自定义脚本并以用户身份运行它们,则可以使用perlbrewlocal::lib (您似乎已经安装)和cpanminus (可以为该用户)创建一个一致的perl环境(或多个)。并排安装,并与perlbrew无缝配合)。

As a quick fix you can extend your @INC with -I (but a non-root user is not going to be able to access /root obviously) and your %ENV with other switches and environment variables. 作为快速解决方案,您可以使用-I扩展@INC (但非root用户显然不能访​​问/root ),并使用其他开关和环境变量来扩展%ENV See perlrun for some of those - eg : 请参阅perlrun中的一些perlrun - 例如

  • -Idirectory

    Directories specified by -I are prepended to the search path for modules ( @INC ). -I指定的目录位于模块( @INC )的搜索路径之前。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM