我得到这个错误:

找不到Foo。pm在@INC

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


当前回答

看起来你已经得到了答案,但我想我应该插句话。这是我在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";
    }
}

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

其他回答

我知道的两种方法:

使用PPM:

在Windows (ActivePerl)中,我使用ppm

从命令行输入ppm。在ppm提示符下…

ppm> install foo

or

ppm> search foo

获取可用的foo模块列表。为所有命令键入help

使用cpan:

你也可以这样使用CPAN (*nix系统):

perl -MCPAN -e 'shell'

给你一个提示

cpan>

听到提示音…

cpan> install foo  (again to install the foo module)

输入h以获得cpan的命令列表

看起来你已经得到了答案,但我想我应该插句话。这是我在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 -i module_name

安全解决方案

许多回答都提到了cpan实用程序的使用(它使用cpan .pm),而没有提到安全性。CPAN 2.27及更早版本默认配置urllist使用http URL(即http://www.cpan.org/),允许MITM攻击,因此是不安全的。这是用来下载checksum文件的,因此需要将其更改为安全URL(例如https://www.cpan.org/)。

因此,在运行cpan并接受默认配置之后,您需要修改生成的MyConfig。PM文件(输出全路径)如下所示。取代

'urllist' => [q[http://www.cpan.org/]],

by

'urllist' => [q[https://www.cpan.org/]],

注意:https是不够的;你还需要一个你可以信任的网站。所以,如果你想选择任意的镜子,要小心。

然后就可以按常规方式使用cpan了。

我在rt.cpan.org上关于不安全URL的错误报告。

如果您希望将新模块放入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