安装缺少的 Perl 模块的最简单方法是什么?

I get this error:

Can't locate Foo.pm in @INC

Is there an easier way to install it than downloading, untarring, making, etc?

转载于:https://stackoverflow.com/questions/65865/whats-the-easiest-way-to-install-a-missing-perl-module

csdnceshi69
YaoRaoLov If the module in question is a core module, consult How to fix “Can't locate Archive/Tar.pm”.
接近 3 年之前 回复

23个回答

On Unix:

usually you start cpan in your shell:

# cpan

and type

install Chocolate::Belgian

or in short form:

cpan Chocolate::Belgian

On Windows:

If you're using ActivePerl on Windows, the PPM (Perl Package Manager) has much of the same functionality as CPAN.pm.

Example:

# ppm
ppm> search net-smtp
ppm> install Net-SMTP-Multipart

see How do I install Perl modules? in the CPAN FAQ

Many distributions ship a lot of perl modules as packages.

  • Gentoo: category dev-perl
  • Debian: apt-cache search 'perl$'

You should always prefer them as you benefit from automatic (security) updates and the ease of removal. This can be pretty tricky with the cpan tool itself.

For Gentoo there's a nice tool called g-cpan which builds/installs the module from CPAN and creates a Gentoo package (ebuild) for you.

csdnceshi62
csdnceshi62 For UNIX and MacOS, need to execute as root or with sudo. Otherwise, there will be a permission error.
大约 3 年之前 回复
csdnceshi70
笑故挽风 bash: cpan: command not found
3 年多之前 回复
csdnceshi54
hurriedly% ppm uses hyphens - because you specify the distribution that you want to install, which is a lot more honest. For instance, if you use cpan to install LWP, LWP::Simple or LWP::UserAgent it will install the distribution libwww-perl for you. The majority of distributions contain a single module with an equivalent name, but there are several exceptions like that
6 年多之前 回复
csdnceshi64
游.程 Note that ppm uses dashes for the module path separator not the usual double colons. (Perhaps because colons mean drives in dos?) That has got me a few times ;)
大约 7 年之前 回复
weixin_41568127
?yb? For Debian this is a great resource: deb.perl.it/debian/cpan-deb
大约 7 年之前 回复
csdnceshi69
YaoRaoLov Cpan command line also works on cygwin under windows.
7 年多之前 回复
csdnceshi58
Didn"t forge Just "ppm" opens the GUI, but followed by commands it stays at the command line. So, "ppm help", "ppm install ...", etc.
8 年多之前 回复
csdnceshi56
lrony* IIRC the latest ActivePerl no longer has command-line ppm, it now opens a fancy GUI.
接近 12 年之前 回复
csdnceshi50
三生石@ The short form is just "cpan Chocolate::Belgian" from the command line :)
大约 12 年之前 回复

sudo perl -MCPAN -e 'install Foo'

If you're on Ubuntu and you want to install the pre-packaged perl module (for example, geo::ipfree) try this:

    $ 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
csdnceshi71
Memor.の This is great. Thank you.
接近 3 年之前 回复

A couple of people mentioned the cpan utility, but it's more than just starting a shell. Just give it the modules that you want to install and let it do it's work.

$prompt> cpan Foo::Bar

If you don't give it any arguments it starts the CPAN.pm shell. This works on Unix, Mac, and should be just fine on Windows (especially Strawberry Perl).

There are several other things that you can do with the cpan tool as well. Here's a summary of the current features (which might be newer than the one that comes with CPAN.pm and 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.

On Windows with the ActiveState distribution of Perl, use the ppm command.

Already answered and accepted answer - but anyway:

IMHO the easiest way installing CPAN modules (on unix like systems, and have no idea about the wondows) is:

curl -L http://cpanmin.us | perl - --sudo App::cpanminus

The above is installing the "zero configuration CPAN modules installer" called cpanm. (Can take several minutes to install - don't break the process)

and after - simply:

cpanm Foo
cpanm Module::One
cpanm Another::Module

2 ways that I know of :

USING PPM :

With Windows (ActivePerl) I've used ppm

from the command line type ppm. At the ppm prompt ...

ppm> install foo

or

ppm> search foo

to get a list of foo modules available. Type help for all the commands

USING CPAN :

you can also use CPAN like this (*nix systems) :

perl -MCPAN -e 'shell'

gets you a prompt

cpan>

at the prompt ...

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

type h to get a list of commands for cpan

weixin_41568126
乱世@小熊 You can also just say "$ cpan Foo::Bar" to install directly from the command line. No fancy one-liner or CPAN shell necessary. :)
大约 12 年之前 回复

On Fedora you can use

# yum install foo

as long as Fedora has an existing package for the module.

Even it should work:

cpan -i module_name

Use cpan command as cpan Modulename

$ cpan HTML::Parser

To install dependencies automatically follow the below

$ perl -MCPAN -e shell
cpan[1]>  o conf prerequisites_policy follow
cpan[2]>  o conf commit
exit

I prefer App::cpanminus, it installs dependencies automatically. Just do

$ cpanm HTML::Parser
共23条数据 1 3 尾页
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐