cpanm 安装 Perl 模块的默认路径是什么?

What is the default path for cpanm to install Perl modules?

在我使用 cpanm 在 "new"(对我来说)系统上安装一些 Perl 模块之前,我想知道它们默认安装在哪里。

我没有看到任何类型的干燥-运行 选项,这正是我所希望的。

perl -V 包含此 %ENV 和 @INC 信息:

%ENV:
  PERL5LIB="/home/randall/perl5/lib/perl5"
  PERL_HOMEDIR="1"
  PERL_LOCAL_LIB_ROOT="/home/randall/perl5"
  PERL_MB_OPT="--install_base /home/randall/perl5"
  PERL_MM_OPT="INSTALL_BASE=/home/randall/perl5"
@INC:
  /home/randall/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

这是否定义了行为,还是有其他注意事项?具体来说,cpanm 的文档包括:

-l, --local-lib
    Sets the local::lib compatible path to install modules to. You don't
    need to set this if you already configure the shell environment
    variables using local::lib, but this can be used to override that as
    well.

但它并没有指出哪些环境变量是重要的。

这会有所帮助:https://metacpan.org/pod/App::cpanminus#Where-does-this-install-modules-to?-Do-I-need-root-access?

Where does this install modules to? Do I need root access?

It installs to wherever ExtUtils::MakeMaker and Module::Build are configured to (via PERL_MM_OPT and PERL_MB_OPT).

By default, it installs to the site_perl directory that belongs to your perl. You can see the locations for that by running perl -V and it will be likely something under /opt/local/perl/... if you're using system perl, or under your home directory if you have built perl yourself using perlbrew or plenv.

If you've already configured local::lib on your shell, cpanm respects that settings and modules will be installed to your local perl5 directory.

At a boot time, cpanminus checks whether you have already configured local::lib, or have a permission to install modules to the site_perl directory. If neither, i.e. you're using system perl and do not run cpanm as a root, it automatically sets up local::lib compatible installation path in a perl5 directory under your home directory.