我得到这个错误:
找不到Foo。pm在@INC
有没有比下载、解压、制作等更简单的方法来安装它?
我得到这个错误:
找不到Foo。pm在@INC
有没有比下载、解压、制作等更简单的方法来安装它?
当前回答
另请参见Yes,即使您也可以使用CPAN。它展示了如何在没有root或sudo访问权限的情况下使用CPAN。
其他回答
sudo perl -MCPAN -e安装Foo
在Unix:
通常你在shell中开始cpan:
全面美元
和类型
安装巧克力::比利时
简而言之:
巧克力cpan::比利时
在Windows上:
如果您在Windows上使用ActivePerl, PPM (Perl包管理器)有许多与cpa .pm相同的功能。
例子:
ppm美元 Ppm >搜索net-smtp 安装Net-SMTP-Multipart
参见如何安装Perl模块?在CPAN常见问题解答中
许多发行版以包的形式发布了大量perl模块。
Debian/Ubuntu: apt-cache search 'perl$' Arch Linux: pacman -Ss '^perl-' Gentoo: category dev-perl
您应该总是喜欢它们,因为您可以从自动(安全)更新和易于删除中受益。这对于cpan工具本身来说是相当棘手的。
对于Gentoo,有一个很好的工具叫做g-cpan,它可以从CPAN构建/安装模块,并为你创建一个Gentoo包(ebuild)。
如果你在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
在带有Perl的ActiveState发行版的Windows上,使用ppm命令。
看起来你已经得到了答案,但我想我应该插句话。这是我在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";
}
}
这对我来说很好,也许这里有你可以使用的东西。