cpan安装及其使用
Perl是一种相当灵活的程序编程语言,现有的许有程序都是使用它进行编程的。它的优点之一就是无需自己编写编码,你就能利用许多增加的模块,创建新的功能。
虽然许多Linux零售商创建了各种Perl模块的RPM软件包,但他们并不为每一个现存的模块创建数据包,除了那些是供应商所要求的。这就是Comprehensive Perl Archive Network (CPAN)的产生的原因。
使用CPAN模块,你就能使用Perl本身安装其它模块。这样做,你就需要你所要安装的模块的名字。比如,你要安装的是Time::HiRes或是DBI模块。具有特色的是,如果你为一个特定的Perl程序查看README文件,它将会列举任何所要求的模块的名字。
第一: 安装:
使用CPAN,成为根用户,执行以下操作:
# perl -MCPAN -e shell
首次这样做的话,你就必须配置CPAN模块。花一些时间按照提示回答它所问的问题;网上通常有这样的例子,通常情况下,问题按住【Enter】就可。这里是说通常情况下,最好自己设置一下!
*************************************************************************************************************
第二:重新设置:
如果在初始安装完成以后,您再想修改某些设置,可以通过以下两种方法进行设置:
方法1:shell下输入cpan,然后回车,cpan[1]> o conf init,会出现一下内容:
CPAN is the world-wide archive of perl resources. It consists of about
300 sites that all replicate the same contents around the globe. Many
countries have at least one CPAN site already. The resources found on
CPAN are easily accessible with the CPAN.pm module. If you want to use
CPAN.pm, lots of things have to be configured. Fortunately, most of
them can be determined automatically. If you prefer the automatic
configuration, answer 'yes' below.
If you prefer to enter a dialog instead, you can answer 'no' to this
question and I'll let you configure in small steps one thing after the
other. (Note: you can revisit this dialog anytime later by typing 'o
conf init' at the cpan prompt.)
Would you like me to configure as much as possible automatically? [yes]
默认的[yes],系统自动的进行编译修改。当然,您可以输入no,回车,然后一项一项的修改。
方法2:修改cpan里面的Config.pm文件
寻找文件:
[root@localhost ]# find / -name Config.pm
/home/.Trash/perl_moduals/perl-5.10.0/ext/Encode/lib/Encode/Config.pm
/home/soft/perl_moduals/perl-5.10.0/ext/Encode/lib/Encode/Config.pm
/usr/lib/perl5/5.8.8/Net/Config.pm
/usr/lib/perl5/5.8.8/ExtUtils/MakeMaker/Config.pm
/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/Config.pm
/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/Encode/Config.pm
/usr/share/automake-1.9/Automake/Config.pm
/usr/local/perl/lib/5.10.0/Net/Config.pm
/usr/local/perl/lib/5.10.0/x86_64-linux/Config.pm
/usr/local/perl/lib/5.10.0/x86_64-linux/Encode/Config.pm
/usr/local/perl/lib/5.10.0/Log/Message/Config.pm
/usr/local/perl/lib/5.10.0/ExtUtils/MakeMaker/Config.pm
/usr/local/perl/lib/5.10.0/Module/Build/Config.pm
/usr/local/perl/lib/5.10.0/CPANPLUS/Config.pm
/usr/local/perl/lib/5.10.0/CPAN/Config.pm
/usr/local/perl/lib/site_perl/5.10.0/HTTP/Config.pm
然后 vi /usr/local/perl/lib/5.10.0/CPAN/Config.pm
# This is CPAN.pm's systemwide configuration file. This file provides
# defaults for users, and the values can be changed in a per-user
# configuration file. The user-config file is being looked for as
# /root/.cpan/CPAN/MyConfig.pm.
$CPAN::Config = {
'applypatch' => q[],
'auto_commit' => q[0],
'build_cache' => q[100],
'build_dir' => q[/root/.cpan/build],
'build_dir_reuse' => q[1],
'build_requires_install_policy' => q[ask/yes],
'bzip2' => q[/usr/bin/bzip2],
'cache_metadata' => q[1],
'check_sigs' => q[0],
'colorize_output' => q[0],
'commandnumber_in_prompt' => q[1],
'connect_to_internet_ok' => q[1],
'cpan_home' => q[/root/.cpan],
'curl' => q[/usr/bin/curl],
'ftp' => q[/usr/kerberos/bin/ftp],
'ftp_passive' => q[1],
'ftp_proxy' => q[],
'getcwd' => q[cwd],
'gpg' => q[/usr/bin/gpg],
'gzip' => q[/usr/bin/gzip],
'halt_on_failure' => q[0],
'histfile' => q[/root/.cpan/histfile],
'histsize' => q[100],
'http_proxy' => q[],
'inactivity_timeout' => q[0],
'index_expire' => q[1],
'inhibit_startup_message' => q[0],
'keep_source_where' => q[/root/.cpan/sources],
'load_module_verbosity' => q[v],
'lynx' => q[],
'make' => q[/usr/bin/make],
'make_arg' => q[],
'make_install_arg' => q[],
"/usr/local/perl/lib/5.10.0/CPAN/Config.pm" 75L, 2216C
然后修改,保存,退出!
********************************************************************************************************************
第三:使用cpan查询和安装模块(一定在根目录下)
查询:cpan[1]> d /模块名字或者部分名字/
查询结果中会给出所有含有模块名字或者部分名字的模块,选择您所需要的模块进行下载
下载安装:cpan[1]> install 模块名字
所有的模块都可以按照上面的例子,类似的进行安装!