Perl的CPAN和CPANPLUS安装模块介绍
说明: 蓝色字体是终端上输出的文字; 红色字体是我们输入的指令; 先把步骤写上,免得看我下面叙述感到啰嗦: 一 CPAN $cpan cpan>install Tkx ???感觉安装很慢,那就配置下 capn>o conf urllist push?http://mirrors.163.com/cpan/ 上面的那个镜像是国内的,国内还有其他镜像,参考http://www.voidcn.com/article/p-fjzpbiuc-bgk.html cpan>o conf commit 得到:commit: wrote '/Users/xxxxxx/.cpan/CPAN/MyConfig.pm' 请看你自己的MyConfig.pm的路径 然后打开.pm文件,找到最后有个urllist=[...]的, 然后可以把那些网址删除,再把国内网站的添加上,保存退出,再次安装模块,再也不需要等待。。。。。 有参考:http://bbs.chinaunix.net/thread-3610007-1-1.html 二 CPANPLUS 使用CPANPLUS的话,就能自动给依赖的模块也装好 cpan>install CPANPLUS $cpanp CPAN Terminal>s reconfigure
7> Select mirrors Section to configure: [1]:7 1> Mirror Please choose an option [1]:1 2> Asia Pick a continent [2]:2 ?1> ftp://ftp.cuhk.edu.hk ? 2> ftp://mirrors.ustc.edu.cn ? 3> ftp://mirrors.xmu.edu.cn ? 4> http://cpan.communilink.net ? 5> http://ftp.cuhk.edu.hk ? 6> http://mirrors.163.com ? 7> http://mirrors.devlib.org ? 8> http://mirrors.hust.edu.cn ? 9> http://mirrors.neusoft.edu.cn ?10> http://mirrors.sohu.com ?11> http://mirrors.ustc.edu.cn ?12> http://mirrors.xmu.edu.cn ?13> rsync://mirrors.ustc.edu.cn ?14> rsync://mirrors.xmu.edu.cn ?15> Custom ?16> View ?17> Up ?18> Quit Please pick a site:? :6 10 8 11 18> Quit Please pick a site:? :18 ?9> Save & exit Section to configure: [1]:9? 安装模块 CPAN Terminal>i CSS 你没看错就是i+模块名完成~~~~~详情参看:http://www.php-oa.com/2010/02/04/cpanplus-per.html 如安装完成,就没必要再看下面的啰嗦: 1.CPAN Mac os下通过CPAN安装第三方模块很方便,只需要: xxxxxx:~ xxxxx$cpan Terminal does not support AddHistory. cpan shell -- CPAN exploration and modules installation (v2.00) Enter 'h' for help. cpan[1]>install [module_name] 。。。。。。。。 但这时你通常感觉安装会很慢甚至卡住一样,最后可能告诉你timeout什么的结束,反正是安装特别不爽。 当我注意到CPAN安装时资源是从国外的镜像上抓取的,参看下面的浅蓝位置:
Fetching with LWP: http://mirrors.163.com/cpan/authors/id/R/RU/RUBYKAT/SQLite-Work-0.16.tar.gz 这里是 http://mirrors.163.com/cpan/, 是因为我设置过,通常默认的是国外网站,你可对比下这时我想起CPAN在中国有很多的镜像网站在上面下载资源很快,那有没有方法直接从中国的镜像下下载呢,然后我就搜了下,参考了: http://bbs.chinaunix.net/thread-3610007-1-1.html 里面的回答,然后自己设置下: xxxxx:~ xxxx$cpan Terminal does not support AddHistory. cpan shell -- CPAN exploration and modules installation (v2.00) Enter 'h' for help. cpan[1]>o conf help Known options: ? commit? ? commit session changes to disk ? defaults? reload default config values from disk ? help? ? ? this help ? init? ? ? enter a dialog to set all or a set of parameters Edit key values as in the following (the "o" is a literal letter o): ? o conf build_cache 15 ? o conf build_dir "/foo/bar" ? o conf urllist shift ? o conf urllist unshift ftp://ftp.foo.bar/ ? o conf inhibit_startup_message 1 cpan[2]>o conf urllist push http://mirrors.163.com/cpan/ Please use 'o conf commit' to make the config permanent! cpan[3]>o conf commit commit: wrote '/Users/xxxxxx/.cpan/CPAN/MyConfig.pm' 也看到提示了保存到了我的个人文件夹的config中 再次进入cpan,当你欣喜万千再次安装模块时,可发现还是从原来那个镜像抓取,注意到Myconfig.pm这个文件,然后通过上面提供的路径打开Myconfig.pm,找到最后几行,有个 'urllist' =>......的,会看到刚才加入的163的镜像在最后,而它是默认从第一个镜像使用的,除非前面一个镜像查不到这个模块才会轮到下一个,而这种情况又是极少见的,所以把163的网址,放到第一个就ok了,保存退出,再次安装你会看到安装信息满屏滚动你会心潮澎湃的,哈哈~~~ 2.CPANPLUS 因为我曾配置过,所以显示步骤有可能有差异,请自己斟酌 xxxx:~ xxxx$cpanp CPANPLUS::Shell::Default -- CPAN exploration and module installation (v0.9154) *** Please report bugs to <bug-cpanplus@rt.cpan.org>. *** Using CPANPLUS::Backend v0.9154. ? *** ReadLine support available (try 'i Term::ReadLine::Perl'). *** Type 'p' now to show start up log Did you know... ? ? You can run an interactive setup using 's reconfigure' CPAN Terminal>s reconfigure =================>? ? ? MAIN MENU ? ? ? <================= Welcome to the CPANPLUS configuration. Please select which parts you wish to configure Defaults are taken from your current configuration. If you would save now,your settings would be written to: ? ? CPANPLUS::Config::User ?? ? ? ? ? 1> Select Configuration file ? 2> Setup CLI Programs ? 3> Setup CPANPLUS Home directory ? 4> Setup FTP/Email settings ? 5> Setup basic preferences ? 6> Setup installer settings ? 7> Select mirrors ? 8> Edit configuration file ? 9> Save & exit ?10> Quit without saving Section to configure: [1]:7 You can select VIEW to see your current selection and QUIT when you are done. ? 1> Mirror ? 2> Custom ? 3> View ? 4> Quit Please choose an option [1]:1 Now,we are going to fetch the mirror list for first-time configurations. This may take a while... ? 1> Africa ? 2> Asia ? 3> Europe ? 4> North America ? 5> Oceania ? 6> South America ? 7> Custom ? 8> Up ? 9> Quit Pick a continent [2]:2 You can enter multiple sites by separating them by a space. For example: ? ? 1 4 2 5 ?? ? ? ? ? ? ? ? ? 1> ftp://ftp.cuhk.edu.hk ? 2> ftp://mirrors.ustc.edu.cn ? 3> ftp://mirrors.xmu.edu.cn ? 4> http://cpan.communilink.net ? 5> http://ftp.cuhk.edu.hk ? 6> http://mirrors.163.com ? 7> http://mirrors.devlib.org ? 8> http://mirrors.hust.edu.cn ? 9> http://mirrors.neusoft.edu.cn ?10> http://mirrors.sohu.com ?11> http://mirrors.ustc.edu.cn ?12> http://mirrors.xmu.edu.cn ?13> rsync://mirrors.ustc.edu.cn ?14> rsync://mirrors.xmu.edu.cn ?15> Custom ?16> View ?17> Up ?18> Quit Please pick a site:? :6 10 8 11 Selected http://mirrors.163.com? ? ? ? ? ? ? 0 hosts selected thus far. Selected http://mirrors.sohu.com ? ? ? ? ? ? 0 hosts selected thus far. Selected http://mirrors.hust.edu.cn? ? ? ? ? 0 hosts selected thus far. Selected http://mirrors.ustc.edu.cn? ? ? ? ? 0 hosts selected thus far. You can enter multiple sites by separating them by a space. For example: ? ? 1 4 2 5 ?? ? ? ? ? ? ? ? ? 1> ftp://ftp.cuhk.edu.hk ? 2> ftp://mirrors.ustc.edu.cn ? 3> ftp://mirrors.xmu.edu.cn ? 4> http://cpan.communilink.net ? 5> http://ftp.cuhk.edu.hk ? 6> http://mirrors.163.com ? 7> http://mirrors.devlib.org ? 8> http://mirrors.hust.edu.cn ? 9> http://mirrors.neusoft.edu.cn ?10> http://mirrors.sohu.com ?11> http://mirrors.ustc.edu.cn ?12> http://mirrors.xmu.edu.cn ?13> rsync://mirrors.ustc.edu.cn ?14> rsync://mirrors.xmu.edu.cn ?15> Custom ?16> View ?17> Up ?18> Quit Please pick a site:? :18 Your host configuration has been saved =================>? ? ? MAIN MENU ? ? ? <================= Welcome to the CPANPLUS configuration. Please select which parts you wish to configure Defaults are taken from your current configuration. If you would save now,your settings would be written to: ? ? CPANPLUS::Config::User ?? ? ? ? ? 1> Select Configuration file ? 2> Setup CLI Programs ? 3> Setup CPANPLUS Home directory ? 4> Setup FTP/Email settings ? 5> Setup basic preferences ? 6> Setup installer settings ? 7> Select mirrors ? 8> Edit configuration file ? 9> Save & exit ?10> Quit without saving Section to configure: [1]:9? Quitting setup,changes are saved to 'CPANPLUS::Config::User' CPANPLUS 使用1. CPANPLUS 中安装模块,按i:
?2. CPANPLUS 中删除模块,按u:
3. CPANPLUS 中查找模块,按m:
4. CPANPLUS 中查找作者的模块,按a:
?5. CPANPLUS 中更新所有有新版本的模块,按下o:
6. 没事也可以更新 CPANPLUS 自己:
?还有很多小功能,以后可能会用这个换掉CPANPLUS本身 可以按e来加入目录到@INC,可以按x来更新index. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |