CPAN 初始设置
在安装Koha的时候,需要提前安装perl的相关模块,这里用到了CPAN,刚开始不知道是什么东东,现把Google来的东西整理在此,以作备份。
CPAN简介
CPAN是Comprehensive Perl Archive Network的缩写,它是一个巨大的Perl软件收藏库,收集了大量有用的Perl模块(modules)及其相关的文件。
CPAN的初始化
当第一次使用CPAN时,需要进行初始化,初始化命令如下:
sudo /etc/perl/CPAN/Config.pm initialized
初始化的过程除了几个选项外,一般是一路回车默认至结束。
若想再次初始化,可以执行如下命令
sudo cpan
cpan> o conf init
初始化信息如下:
CPAN is the world-wide archive of perl resources. It consists of about
100 sites that all replicate the same contents all 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, you have to configure it properly.
If you do not want to enter a dialog now, you can answer ‘no’ to this
question and I’ll try to autoconfigure. (Note: you can revisit this
dialog anytime later by typing ‘o conf init’ at the cpan prompt.)
Are you ready for manual configuration? [yes]
The following questions are intended to help you with the
configuration. The CPAN module needs a directory of its own to cache
important index files and maybe keep a temporary mirror of CPAN files.
This may be a site-wide directory or a personal directory.
First of all, I’d like to create this directory. Where?
CPAN build and cache directory? [/root/.cpan]
If you want, I can keep the source files after a build in the cpan
home directory. If you choose so then future builds will take the
files from there. If you don’t want to keep them, answer 0 to the
next question.
How big should the disk cache be for keeping the build directories
with all the intermediate files?
Cache size for build directory (in MB)? [10]
By default, each time the CPAN module is started, cache scanning
is performed to keep the cache size in sync. To prevent from this,
disable the cache scanning with ‘never’.
Perform cache scanning (atstart or never)? [atstart]
To considerably speed up the initial CPAN shell startup, it is
possible to use Storable to create a cache of metadata. If Storable
is not available, the normal index mechanism will be used.
Cache metadata (yes/no)? [yes]
The next option deals with the charset your terminal supports. In
general CPAN is English speaking territory, thus the charset does not
matter much, but some of the aliens out there who upload their
software to CPAN bear names that are outside the ASCII range. If your
terminal supports UTF-8, you say no to the next question, if it
supports ISO-8859-1 (also known as LATIN1) then you say yes, and if it
supports neither nor, your answer does not matter, you will not be
able to read the names of some authors anyway. If you answer no, names
will be output in UTF-8.
Your terminal expects ISO-8859-1 (yes/no)? [yes] no
If you have one of the readline packages (Term::ReadLine::Perl,
Term::ReadLine::Gnu, possibly others) installed, the interactive CPAN
shell will have history support. The next two questions deal with the
filename of the history file and with its size. If you do not want to
set this variable, please hit SPACE RETURN to the following question.
File to save your history? [/root/.cpan/histfile]
Number of lines to save? [100]
The CPAN module can detect when a module that which you are trying to
build depends on prerequisites. If this happens, it can build the
prerequisites for you automatically (’follow’), ask you for
confirmation (’ask’), or just ignore them (’ignore’). Please set your
policy to one of the three values.
Policy on building prerequisites (follow, ask or ignore)? [ask]
The CPAN module will need a few external programs to work properly.
Please correct me, if I guess the wrong path for a program. Don’t
panic if you do not have some of them, just press ENTER for those. To
disable the use of a download program, you can type a space followed
by ENTER.
Where is your gzip program? [/bin/gzip]
Where is your tar program? [/bin/tar]
Where is your unzip program? [/usr/bin/unzip]
Where is your make program? [/usr/bin/make]
Warning: lynx not found in PATH
Where is your lynx program? [] /usr/bin
Where is your wget program? [/usr/bin/wget]
Warning: ncftpget not found in PATH
Where is your ncftpget program? []
Warning: ncftp not found in PATH
Where is your ncftp program? []
Where is your ftp program? [/usr/bin/ftp]
Where is your gpg program? [/usr/bin/gpg]
What is your favorite pager program? [/usr/bin/less]
What is your favorite shell? [/bin/bash]
Every Makefile.PL is run by perl in a separate process. Likewise we
run ‘make’ and ‘make install’ in processes. If you have any
parameters (e.g. PREFIX, LIB, UNINST or the like) you want to pass
to the calls, please specify them here.
If you don’t understand this question, just press ENTER.
Parameters for the ‘perl Makefile.PL’ command?
Typical frequently used settings:
PREFIX=~/perl non-root users (please see manual for more hints)
Your choice: [INSTALLDIRS=site]
Parameters for the ‘make’ command?
Typical frequently used setting:
-j3 dual processor system
Your choice: [] -j3 #双核才需要填写
Parameters for the ‘make install’ command?
Typical frequently used setting:
UNINST=1 to always uninstall potentially conflicting files
Your choice: []
Sometimes you may wish to leave the processes run by CPAN alone
without caring about them. As sometimes the Makefile.PL contains
question you’re expected to answer, you can set a timer that will
kill a ‘perl Makefile.PL’ process after the specified time in seconds.
If you set this value to 0, these processes will wait forever. This is
the default and recommended setting.
Timeout for inactivity during Makefile.PL? [0]
If you’re accessing the net via proxies, you can specify them in the
CPAN configuration or via environment variables. The variable in
the $CPAN::Config takes precedence.
Your ftp_proxy?
Your http_proxy?
Your no_proxy?
You have no /root/.cpan/sources/MIRRORED.BY
I’m trying to fetch one
CPAN: LWP::UserAgent loaded ok
Fetching with LWP:
ftp://ftp.perl.org/pub/CPAN/MIRRORED.BY
Now we need to know where your favorite CPAN sites are located. Push
a few sites onto the array (just in case the first on the array won’t
work). If you are mirroring CPAN to your local workstation, specify a
file: URL.
First, pick a nearby continent and country (you can pick several of
each, separated by spaces, or none if you just want to keep your
existing selections). Then, you will be presented with a list of URLs
of CPAN mirrors in the countries you selected, along with previously
selected URLs. Select some of those URLs, or just keep the old list.
Finally, you will be prompted for any extra URLs — file:, ftp:, or
http: — that host a CPAN mirror.
(1) Africa
(2) Asia
(3) Central America
(4) Europe
(5) North America
(6) Oceania
(7) South America
Select your continent (or several nearby continents) [] 2
Sorry! since you don’t have any existing picks, you must make a
geographic selection.
(1) China
(2) Hong Kong
(3) Indonesia
(4) Israel
(5) Japan
(6) Korea
(7) Pakistan
(8) Philippines
(9) Republic of Korea
(10) Saudi Arabia
(11) Singapore
(12) Taiwan
(13) Thailand
(14) Turkey
Select your country (or several nearby countries) [] 1 2 5 12
(1) ftp://ftp.cuhk.edu.hk/pub/packages/perl/CPAN/ (Hong Kong)
(2) http://mirrors.geoexpat.com/cpan/ (Hong Kong)
(3) ftp://ftp.dti.ad.jp/pub/lang/CPAN/ (Japan)
(4) ftp://ftp.jaist.ac.jp/pub/CPAN/ (Japan)
(5) ftp://ftp.kddilabs.jp/CPAN/ (Japan)
(6) ftp://ftp.nara.wide.ad.jp/pub/CPAN/ (Japan)
(7) ftp://ftp.riken.jp/lang/CPAN/ (Japan)
(8) ftp://ftp.ring.gr.jp/pub/lang/perl/CPAN/ (Japan)
(9) ftp://ftp.u-aizu.ac.jp/pub/CPAN (Japan)
(10) ftp://ftp.yz.yamagata-u.ac.jp/pub/lang/cpan/ (Japan)
(11) ftp://cpan.cdpa.nsysu.edu.tw/Unix/Lang/CPAN/ (Taiwan)
(12) ftp://cpan.cs.pu.edu.tw/pub/CPAN (Taiwan)
(13) ftp://cpan.nctu.edu.tw/ (Taiwan)
(14) ftp://ftp.isu.edu.tw/pub/CPAN (Taiwan)
(15) ftp://ftp.ncu.edu.tw/CPAN/ (Taiwan)
(16) ftp://ftp.stu.edu.tw/CPAN (Taiwan)
2 more items, hit SPACE RETURN to show them
Select as many URLs as you like (by number),
put them on one line, separated by blanks, e.g. ‘1 4 5′
(or just hit RETURN to keep your previous picks) [18] 1 2 3 11 12 13 14 15 16
Enter another URL or RETURN to quit: []
New set of picks:
ftp://ftp.cuhk.edu.hk/pub/packages/perl/CPAN/
http://mirrors.geoexpat.com/cpan/
ftp://ftp.dti.ad.jp/pub/lang/CPAN/
ftp://cpan.cdpa.nsysu.edu.tw/Unix/Lang/CPAN/
ftp://cpan.cs.pu.edu.tw/pub/CPAN
ftp://cpan.nctu.edu.tw/
ftp://ftp.isu.edu.tw/pub/CPAN
ftp://ftp.ncu.edu.tw/CPAN/
ftp://ftp.stu.edu.tw/CPAN
commit: wrote /etc/perl/CPAN/Config.pm
cpan> quit
Terminal does not support GetHistory.
Lockfile removed.
root@ubuntu:
CPAN的使用方法
一、安装模块
例如需要安装CGI::Session模块,可以有如下两种方法:
1、直接法
sudo cpan CGI::Session
2、间接法
sudo cpan
cpan> install CGI::Session
cpan> quit
二、在CPAN中查询模块
sudo cpan
cpan> d /CGI::Session/
cpan> quit
下面是摘引自Fed Chu’s Blog的“用CPAN安装perl module”,供参考。
1. 首先配置CPAN Module,方法是在bash下面运行
$ perl -MCPAN -eshell
配置过程会询问一些问题,其中CPAN的镜像可以选择http://cpan.linuxforum.net/。
2. 接下来要更新CPAN Module,而不是直接装LWP。否则会遇到undefined subroutine &Digest::base::new之类的错误。方法是运行
cpan> install Bundle::CPAN
这一步是关键,切记切记。我开始不知道,还在网上搜索这个错误信息,发现有人说是Perl的问题,我就把整个Cygwin更新到1.5.19.4,结果啥用也没有,还把其它东西弄得一塌糊涂。
3. 装好新的CPAN Module,先退出,然后再运行1里面的命令进入CPAN的shell,这时就可以装LWP了
cpan> install Bundle::LWP
安装Bundle::LWP意味着不仅安装LWP,而且安装它需要的其它module。
下面转自程序人生的“Perl 下面用cpan安装相关的模块问题”
最近有玩一下Perl,想用一下cpan中的一些不错的模块,但安装的过程中老是提示make…. not ok,我的服务器环境是freebsd6.2 (升级过ports) 现在的perl 版本是perl 5.8.8
针对上面的错误我的做法是重装,经过反复的重装,最后终于OK,下面分享一下我的重装过程。
如我要安装HTML::TreeBuilder
第一步:检查一下HTML::TreeBuilder模块是否存在于系统中,运行下面的两个指令,
官方给出的方法:
#perl -MHTML::TreeBuilder -e 1
如果运行上面的命令未有警告的话说明该模块已经安装了,需要看相关的使用说明可以使用下面的命令
#perldoc HTML::TreeBuilder
第二种方法其它已经在上面有提到过,即用查看帮助的方法
#perldoc HTML::TreeBuilder
如果有帮助信息的,则说明已安装,否则未安装
第二步:删除CPAN的配置
#cd /usr/local/lib/perl5/5.8.8/CPAN
#rm -f Config.pm
第三步:重新安装 CPAN
#perl -MCPAN -e shell
运行上面的命令后系统会提示这是首次运行cpan,要做一些设置,一般不知道是什么意思时只需要一直按“回车”即可!
下面贴出我的CPAN配置文件
Config.pm:
[code]
# 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
# ~/.cpan/CPAN/MyConfig.pm.
$CPAN::Config = {
‘build_cache’ => q[10],
‘build_dir’ => q[/root/.cpan/build],
‘cache_metadata’ => q[1],
‘cpan_home’ => q[/root/.cpan],
‘dontload_hash’ => { },
‘ftp’ => q[/usr/bin/ftp],
‘ftp_proxy’ => q[],
‘getcwd’ => q[cwd],
‘gpg’ => q[],
‘gzip’ => q[/usr/bin/gzip],
‘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],
‘lynx’ => q[],
‘make’ => q[/usr/bin/make],
‘make_arg’ => q[],
‘make_install_arg’ => q[],
‘makepl_arg’ => q[],
‘ncftp’ => q[],
‘ncftpget’ => q[],
‘no_proxy’ => q[],
‘pager’ => q[more],
‘prerequisites_policy’ => q[ask],
’scan_cache’ => q[atstart],
’shell’ => q[/bin/csh],
‘tar’ => q[/usr/bin/tar],
‘term_is_latin’ => q[1],
‘unzip’ => q[/usr/local/bin/unzip],
‘urllist’ => [q[ftp://cpan.hexten.net/], q[ftp://cpan.hostrack.net/pub/CPAN], q[ftp://cpan.pair.com/pub/CPAN/]],
‘wget’ => q[/usr/bin/wget],
};
[/code]
使用CPAN安装Perl模块
Perl到了第五版增加了模块的概念,用来提供面向对象编程的能力。这是Perl语言发展史上
的一个里程碑。此后,广大自由软件爱好者开发了大量功能强大、构思精巧的Perl模块,极大地
扩展了Perl语言的功能。CPAN(Comprehensive Perl Archive Network)是internet上Perl模块
最大的集散地,包含了现今公布的几乎所有的perl模块。
几个主要的CPAN站点有:
国内:ftp://freesoft.cgi.gov.cn/pub/languages/perl/CPAN
http://cpan.qz.fj.cn/
国外:http://www.cpan.org/
http://www.perl.com/CPAN-local/
我在这里介绍一下各种平台下perl模块的安装方法。以安装DBI模块为例。
1、Linux/Unix下的安装方法:
Linux/Unix下安装Perl模块有两种方法:手工安装和自动安装。第一种方法是从CPAN上下载
您需要的模块,手工编译、安装。第二种方法是联上internet,使用一个叫做CPAN的模块自动完
成下载、编译、安装的全过程。
a、手工安装的步骤:
从CPAN下载了DBI模块1.13版的压缩文件DBI-1.13.tar.gz,假设放在/usr/local/src/下。
cd /usr/local/src
解压缩这个文件:
tar xvzf DBI-1.13.tar.gz
这时会新建一个DBI-1.13的目录。
cd DBI-1.13
生成makefile:
perl Makefile.PL
建立模块
make
测试模块
make test
如果测试结果报告“all test ok”,您就可以放心地安装编译好的模块了。安装模块前,先要
确保您对perl5安装目录有可写权限(通常以su命令获得),执行:
make install
现在,写个程序试试吧。
#!/usr/bin/perl -w
use strict;
use DBI;
..
上述步骤适合于Linux/Unix下绝大多数的Perl模块。可能还有少数模块的安装方法略有差别,
所以最好先看看安装目录里的README或INSTALL。另外,上述过程是针对动态链接的Perl编译
器(所有Linux下预安装的Perl都是动态链接的),如果您在使用一个静态链接的Perl,您需要将
新的模块静态链接到perl编译器中,可能还需要重启机器。
b、使用CPAN模块自动安装:
安装前需要先联上线,并且您需要取得root权限。
perl -MCPAN -e shell
初次运行CPAN时需要做一些设置,如果您的机器是直接与internet相联(拨号上网、专线,etc.),
那么一路回车就行了,只需要在最后选一个离您最近的CPAN镜像站点。例如我选的是位于国内的
中国自由软件库ftp://freesoft.cgi.gov.cn/pub/languages/perl/CPAN 。否则,如果您的机器
位于防火墙之后,还需要设置ftp代理或http代理。
获得帮助
cpan>h
列出CPAN上所有模块的列表
cpan>m
安装模块
cpan>install DBI
自动完成DBI模块从下载到安装的全过程。
退出
cpan>q
2、Win32下的安装方法:
在Win32下,建议使用ActiveState的Perl for Win32,即ActivePerl。ActivePerl的主页在:
http://www.activestate.com/ 。在Win32下,最好也使用专门为ActivePerl定制的Perl模块。从
CPAN下载的Perl模块不能很好地在ActivePerl下使用。类似于CPAN模块,ActiveState也开发
了一个自动安装工具叫做PPM(Perl Package Manager)。
最通常的安装方法是:
首先联上线
在dos命令行下启动ppm
ppm
获得帮助
PPM>h
列出ActiveState站点上所有为Perl模块的清单。
PPM>search
安装模块
PPM>install DBI
自动完成DBI模块从下载到安装的全过程。
退出
PPM>q
如果您的机器位于防火墙之后,通过http代理上网,那么可以使用下面的方法。
对于老的基于perl 5.005的ActivePerl版本(ActivePerl 522以下版本,不包括ActivePerl 522),从
http://www.ActiveState.com/ppmpackages/5.005/zips/下载您需要的Perl模块,例如DBI.zip。
将其解压缩在C:\TEMP\DBI下
cd \TEMP\DBI
ppm install DBI.PPD
最新的基于perl 5.6的ActivePerl版本(ActivePerl 613及以上版本)的安装方法略有不同。安
装ActivePerl 613前需要先安装Microsoft的Windows Installer。
Windows Installer从这里下载:
http://activestate.com/download/contrib/Microsoft/9x/InstMsi.exe
ActivePerl 613从这里下载:
http://activestate.com/download/ … ePerl-5.6.0.613.msi
对于基于perl 5.6的ActivePerl版本,从
http://www.activestate.com/PPMPackages/5.6/
下载您需要的Perl模块的安装描述文件,例如DBI.PPD
安装模块前需要先联上线
ppm install DBI.PPD。
If you are already familiar with installing CPAN modules, go-perl is no different from any other. If you aren’t, you may wish to experiment now.
Try typing the following:
perl -MCPAN -e shell
install GO::Parser
The following may also work:
cpan GO::Parser
If this is the first time using the CPAN installer, you will be asked a barrage of questions. You are best to answer with the defaults – you can always change this later.
If you do NOT have access to the system-wide perl directories on your system (these will typically be in /Library or /usr/local), then you should either get some help setting up CPAN for use with your system, OR you should follow an alternate protocol below. (You may wish to modify the value of PREFIX to ~ in the CPAN setup, as detailed in protocol III)
If you are on OS X you may need to do this:
sudo cpan GO::Parser
Providing you do have write-access to these directories, the above commands should hopefully go smoothly. When installing go-perl, you may be asked if you wish to also install Data::Stag and IO::String – you should answer yes
After this, you should be ready to use go-perl! The scripts should be in your path and the libraries should be in the standard place. You may wish to start by trying “map2slim” or “go2obo_xml”
There are certain applications that require additional third-party modules. All these are available from CPAN, and can be installed in the above manner. For example, if you try and use the go-filter-subset.pl script to generate a PNG image of an ontology subgraph, the system will complain you do not have the module “GraphViz” installed. To install this, simply type:
perl -MCPAN -e shell
install GraphViz
Depending on what you use go-perl for, you may not ever need to install other CPAN modules
