我得到这个错误:

找不到Foo。pm在@INC

有没有比下载、解压、制作等更简单的方法来安装它?


当前回答

对CPAN有很多建议。pm,这很好,但如果您使用的是Perl 5.10,那么您还可以访问CPANPLUS。pm,类似于CPAN。总理,但更好。

当然,对于仍在使用旧版本Perl的用户,可以在CPAN上找到它。为什么不试试呢:

$ cpan CPANPLUS

其他回答

在带有Perl的ActiveState发行版的Windows上,使用ppm命令。

很多时候,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";
    }
}

这对我来说很好,也许这里有你可以使用的东西。

如果您希望将新模块放入cpan shell未配置为使用的自定义位置,那么以下操作可能会很方便。

 #wget <URL to the module.tgz>
 ##unpack
 perl Build.PL
./Build destdir=$HOME install_base=$HOME
./Build destdir=$HOME install_base=$HOME install

即使它应该工作:

cpan -i module_name