我得到这个错误:
找不到Foo。pm在@INC
有没有比下载、解压、制作等更简单的方法来安装它?
我得到这个错误:
找不到Foo。pm在@INC
有没有比下载、解压、制作等更简单的方法来安装它?
当前回答
有几个人提到了cpan实用程序,但它不仅仅是启动一个shell。只要给它你想安装的模块,让它做它的工作。
$prompt> cpan Foo::Bar
如果你不给它任何参数,它就会启动CPAN。点壳。这可以在Unix、Mac上工作,在Windows上应该也可以(特别是Strawberry Perl)。
cpan工具还可以做其他一些事情。下面是当前特性的总结(可能比CPAN附带的特性更新)。PM和perl):
-a
Creates the CPAN.pm autobundle with CPAN::Shell->autobundle.
-A module [ module ... ]
Shows the primary maintainers for the specified modules
-C module [ module ... ]
Show the Changes files for the specified modules
-D module [ module ... ]
Show the module details. This prints one line for each out-of-date module (meaning,
modules locally installed but have newer versions on CPAN). Each line has three columns:
module name, local version, and CPAN version.
-L author [ author ... ]
List the modules by the specified authors.
-h
Prints a help message.
-O
Show the out-of-date modules.
-r
Recompiles dynamically loaded modules with CPAN::Shell->recompile.
-v
Print the script version and CPAN.pm version.
其他回答
在Fedora Linux或Enterprise Linux上,yum还跟踪perl库依赖关系。因此,如果perl模块可用,并且某些rpm包导出该依赖项,它将为您安装正确的包。
yum install 'perl(Chocolate::Belgian)'
(很可能是perl- chocolate - belgium包,甚至是ChocolateFactory包)
很多时候,cpan install命令失败,出现类似这样的消息 “使测试已返回坏状态,不强制将不会安装”
在这种情况下,下面是安装模块的方法:
perl -MCPAN -e "CPAN::Shell->force(qw(install Foo::Bar));"
看起来你已经得到了答案,但我想我应该插句话。这是我在Ubuntu(或debian服务器)上的一些脚本中所做的事情。
#!/usr/bin/perl
use warnings;
use strict;
#I've gotten into the habit of setting this on all my scripts, prevents weird path issues if the script is not being run by root
$ENV{'PATH'} = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin';
#Fill this with the perl modules required for your project
my @perl = qw(LWP::Simple XML::LibXML MIME::Lite DBI DateTime Config::Tiny Proc::ProcessTable);
chomp(my $curl = `which curl`);
if(!$curl){ system('apt-get install curl -y > /dev/null'); }
chomp(my $cpanm = system('/bin/bash', '-c', 'which cpanm &>/dev/null'));
#installs cpanm if missing
if($cpanm){ system('curl -s -L http://cpanmin.us | perl - --sudo App::cpanminus'); }
#loops through required modules and installs them if missing
foreach my $x (@perl){
eval "use $x";
if($@){
system("cpanm $x");
eval "use $x";
}
}
这对我来说很好,也许这里有你可以使用的东西。
尝试应用::cpanminus:
# cpanm Chocolate::Belgian
它非常适合安装东西。它不提供CPAN或CPANPLUS的任何复杂功能,因此只要知道要安装哪个模块,就很容易使用。如果你还没有cpanminus,只需输入:
# cpan App::cpanminus
安装它。
也可以完全不使用cpan来安装它。基本的引导程序是,
curl -L http://cpanmin.us | perl - --sudo App::cpanminus
欲了解更多信息,请访问App::cpanminus页面,并查看安装部分。
即使它应该工作:
cpan -i module_name