我得到这个错误:

找不到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";
    }
}

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

其他回答

如果你在Ubuntu上,你想安装预打包的perl模块(例如,geo::ipfree),试试这个:

    $ apt-cache search perl geo::ipfree
    libgeo-ipfree-perl - A look up country of ip address Perl module

    $ sudo apt-get install libgeo-ipfree-perl

另请参见Yes,即使您也可以使用CPAN。它展示了如何在没有root或sudo访问权限的情况下使用CPAN。

我注意到一些人建议在sudo下运行cpan。在过去,安装到系统目录中是必须的,但是CPAN shell的现代版本允许您配置它,只使用sudo进行安装。这要安全得多,因为这意味着测试不会以根用户身份运行。

如果您有一个旧的CPAN shell,只需安装新的CPAN(“install CPAN”),当您重新加载shell时,它将提示您配置这些新指令。

现在,当我在一个有旧CPAN的系统上时,我要做的第一件事是更新shell并将其设置为这样做,这样我就可以作为一个普通用户完成大部分CPAN工作。

另外,我强烈建议Windows用户研究草莓Perl。这是一个Perl版本,附带一个预配置的CPAN外壳和一个编译器。它还包括一些难以编译的Perl模块及其外部C库依赖项,特别是XML::Parser。这意味着当涉及到安装模块时,您可以像其他Perl用户一样做同样的事情,而且事情往往会“工作”得更频繁。

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

奥托提了个好建议。这也适用于Debian,以及任何其他Debian衍生物。缺失的部分是当apt-cache搜索没有找到一些东西时该怎么做。

$ sudo apt-get install dh-make-perl build-essential apt-file
$ sudo apt-file update

然后,当你有一个随机的模块,你想安装:

$ cd ~/some/path
$ dh-make-perl --build --cpan Some::Random::Module
$ sudo dpkg -i libsome-random-module-perl-0.01-1_i386.deb

这将给你一个deb包,你可以安装它来获得Some::Random::Module。这里最大的好处之一是,除了模块本身之外,手册页和示例脚本将被放置在您的发行版所选择的位置。如果发行版发布了新版本的Some::Random::Module的官方包,它将在你apt-get升级时自动安装。