简体   繁体   English

如何告诉cpan更改模块安装的目标?

[英]How can I tell cpan to change the target for the module installation?

When I installed perl from the source the first nice surprise was that without doing something all module installed from now on were available to the new perl. 当我从源代码安装perl时,第一个令人惊喜的是,没有做任何事情,从现在开始安装的所有模块都可用于新的perl。 Since I didn't find one module on cpan that comes with my OS I have to use for some scripts the onboard-perl. 由于我没有在我的操作系统附带的cpan上找到一个模块,我必须使用onboard-perl的一些脚本。 For one of these scripts I would like to install Text::Format or Text::Autoformat (didn't find the docu for that module on cpan). 对于其中一个脚本,我想安装Text :: Format或Text :: Autoformat(没有在cpan上找到该模块的文档)。 My question: how can I tell cpan to install the module this one time for the OS-distro-perl? 我的问题:我怎么能告诉cpan这次为OS-distro-perl安装模块?

There isn't a special way to tell cpan to install modules in a new location for just the one invocation. 没有一种特殊的方法可以告诉cpan在一个新位置安装模块,只进行一次调用。 That feature, however, is on my to do list, along with local::lib support. 但是,该功能在我的待办事项列表中,以及local :: lib支持。 I truly understand your pain and want the same feature. 我真的明白你的痛苦并想要同样的功能。 I just need the time (or the patch) to make it work. 我只需要时间(或补丁)来使其工作。

Until then, you have to enter the CPAN.pm shell and change the values for mbuild_arg and makefilepl_arg as noted in perlfaq8: How do I keep my own module directory? 在此之前,您必须输入CPAN.pm shell并更改mbuild_argmakefilepl_arg的值,如mbuild_arg所述:如何保留自己的模块目录? :


When you build modules, tell Perl where to install the modules. 构建模块时,请告诉Perl在哪里安装模块。

For Makefile.PL-based distributions, use the INSTALL_BASE option when generating Makefiles: 对于基于Makefile.PL的发行版,在生成Makefile时使用INSTALL_BASE选项:

perl Makefile.PL INSTALL_BASE=/mydir/perl

You can set this in your CPAN.pm configuration so modules automatically install in your private library directory when you use the CPAN.pm shell: 您可以在CPAN.pm配置中进行设置,以便在使用CPAN.pm shell时模块自动安装在您的私有库目录中:

% cpan
cpan> o conf makepl_arg INSTALL_BASE=/mydir/perl
cpan> o conf commit

For Build.PL-based distributions, use the --install_base option: 对于基于Build.PL的发行版,请使用--install_base选项:

perl Build.PL --install_base /mydir/perl

You can configure CPAN.pm to automatically use this option too: 您可以配置CPAN.pm以自动使用此选项:

% cpan
cpan> o conf mbuild_arg "--install_base /mydir/perl"
cpan> o conf commit

/ path / to / system / perl -MCPAN -e shell

Each Perl installation has its own idea of where libraries should "live", which the CPAN module uses as a guide for where to perform its installations. 每个Perl安装都有自己的想法,库应该“生存”,CPAN模块使用它作为执行其安装的指南。 You can see what these values are by executing perl -V , and look for the value of @INC (at the bottom). 您可以通过执行perl -V来查看这些值是什么,并查找@INC的值(在底部)。 If you invoke CPAN with a different Perl (eg your system-installed Perl), you will automatically install modules into that Perl's preferred location: 如果使用不同的Perl调用CPAN(例如,系统安装的Perl),您将自动将模块安装到Perl的首选位置:

/usr/bin/perl -MCPAN -e shell

or to simply install one module without having to invoke the CPAN shell explicitly: 或者只需安装一个模块而无需显式调用CPAN shell:

/usr/bin/cpan <modulename>

There are also CPAN configuration options available where you can temporarily or permanently change the install location, but this should not be necessary in your case. 您还可以使用CPAN配置选项临时或永久更改安装位置,但在您的情况下这不是必需的。

I'm assuming you want to simply install modules to a different location and then run them from that location -- your question wasn't too clear to me. 我假设您只想将模块安装到其他位置,然后从该位置运行它们 - 您的问题对我来说不太清楚。

Read the perldoc fully on local::lib . local::lib上完全读取perldoc。 It would be a major failure on my part to try to write that better. 试着写得更好,这将是我的一个重大失败。 This is also the most recent and advanced way to achieve this task. 这也是实现此任务的最新和最先进的方法。 If another solution doesn't reference this module, then my personal suggestion would be to avoid it like the plague. 如果另一个解决方案没有引用这个模块,那么我个人的建议是避免它像瘟疫一样。

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

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