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

廉价感情. 提交于 2019-12-05 13:42:54

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. You can see what these values are by executing perl -V, and look for the value of @INC (at the bottom). If you invoke CPAN with a different Perl (e.g. your system-installed Perl), you will automatically install modules into that Perl's preferred location:

/usr/bin/perl -MCPAN -e shell

or to simply install one module without having to invoke the CPAN shell explicitly:

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

There isn't a special way to tell cpan to install modules in a new location for just the one invocation. That feature, however, is on my to do list, along with local::lib support. 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?:


When you build modules, tell Perl where to install the modules.

For Makefile.PL-based distributions, use the INSTALL_BASE option when generating Makefiles:

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
cpan> o conf makepl_arg INSTALL_BASE=/mydir/perl
cpan> o conf commit

For Build.PL-based distributions, use the --install_base option:

perl Build.PL --install_base /mydir/perl

You can configure CPAN.pm to automatically use this option too:

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

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

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!