如何将CPAN模块安装到本地目录中?

7 浏览
0 Comments

如何将CPAN模块安装到本地目录中?

我使用的是托管的Linux机器,因此我没有权限将文件写入/usr/lib目录。\n当我尝试通过以下常规方法安装CPAN模块时:\n

perl Makefile.PL
make test
make install

\n该模块被提取到一个blib/lib/文件夹中。我保留了

use
blib/lib/ModuleName

,但编译器仍然显示找不到模块。我尝试将.pm文件复制到本地目录并保留require ModuleName,但仍然出现错误。\n如何将模块安装到其他目录并使用它?

0
0 Comments

问题的出现:local::lib是一个能够帮助用户将CPAN模块安装到本地目录的工具。然而,在尝试安装local::lib时,它未能通过'make test'测试。

解决方法:尽管local::lib无法通过'make test'测试,但仍然强烈推荐使用它来解决安装CPAN模块到本地目录的问题。local::lib会让"make install"(和"Build install")将模块安装到用户可以写入的目录,并告诉perl如何访问这些模块。如果想使用blib/目录中的模块,则需要使用perl -Mblib ...命令来调用脚本。使用local::lib能够处理所有细节,确保安装过程顺利进行。

以下是中文输出的整理文章:

问题:如何将CPAN模块安装到本地目录?

解决方法:可以使用local::lib工具来解决此问题。local::lib能够让用户将CPAN模块安装到本地目录,并告诉perl如何访问这些模块。不过,当尝试安装local::lib时,它未能通过'make test'测试。

尽管local::lib未能通过测试,但仍然强烈推荐使用它来解决安装CPAN模块到本地目录的问题。local::lib会让"make install"(和"Build install")将模块安装到用户可以写入的目录,并告诉perl如何访问这些模块。

如果想使用blib/目录中的模块,可以使用perl -Mblib ...命令来调用脚本。使用local::lib能够处理所有细节,确保安装过程顺利进行。

0
0 Comments

CPAN (Comprehensive Perl Archive Network) is a repository of over 190,000 modules that can be installed on Perl. However, sometimes it is necessary to install a CPAN module into a local directory instead of the system-wide Perl library directory. This may be required in cases where the user doesn't have administrative privileges or wants to keep the module installation separate from the system libraries.

One way to install a CPAN module into a local directory is by using the PREFIX option during the installation process. The PREFIX option specifies the installation directory for the module. For example, the following commands can be used to install a module into a local directory called "modulos":

perl Makefile.PL PREFIX=./modulos
make
make install

After the installation, the module can be used in a Perl script by adding the directory to the module search path using the `use lib` directive. For example, if the script is in the current directory and the module was installed in `./modulos/share/perl/5.8.8/`, the following lines can be added to the script:

use lib qw(./modulos/share/perl/5.8.8/); # You may need to change this path
use module::name;

This allows the script to use the module without any further modifications.

Alternatively, the PERL5LIB environment variable can be set instead of using `use lib`. This can be done by running the following command before executing the script:

export PERL5LIB=./modulos/share/perl/5.8.8/

It's worth mentioning that for newer versions of Perl, the INSTALL_BASE parameter can be used instead of PREFIX. However, in Perl v5.8.8, INSTALL_BASE is not supported. To determine the supported parameters, the documentation for MakeMaker can be consulted.

In conclusion, installing a CPAN module into a local directory can be achieved by specifying the installation directory using the PREFIX option during the installation process and adding the directory to the module search path in the Perl script using `use lib` or setting the PERL5LIB environment variable.

0
0 Comments

问题的原因是用户没有root访问权限,因此无法直接安装CPAN模块到系统目录中。解决方法是将模块安装到本地目录中。

对于基于Makefile.PL的分发,可以在生成Makefile时使用INSTALL_BASE选项:

perl Makefile.PL INSTALL_BASE=/mydir/perl

也可以在CPAN.pm配置中设置该选项,这样当使用CPAN.pm shell时,模块会自动安装到私有库目录中:

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

对于基于Build.PL的分发,可以使用--install_base选项:

perl Build.PL --install_base /mydir/perl

同样,也可以配置CPAN.pm自动使用该选项:

% cpan
cpan> o conf mbuildpl_arg '--install_base /mydir/perl'
cpan> o conf commit

最后,还有一个用户提到的问题是如何在cpan选项中实现相同的功能。

0