我得到这个错误:
找不到Foo。pm在@INC
有没有比下载、解压、制作等更简单的方法来安装它?
我得到这个错误:
找不到Foo。pm在@INC
有没有比下载、解压、制作等更简单的方法来安装它?
当前回答
有时你可以使用yum search foo来搜索相对的perl模块,然后使用yum install xxx来安装。
其他回答
有几个人提到了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.
我知道的两种方法:
使用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的命令列表
安全解决方案
许多回答都提到了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 -i module_name
奥托提了个好建议。这也适用于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升级时自动安装。