你好,游客 登录 注册 搜索
背景:
阅读新闻

修改CPAN mirror的默认源

[日期:2017-10-27] 来源:Linux社区  作者:Linux [字体: ]

详细介绍对Perl的CPAN镜像使用管理的文章,安装perl下的很多模块文件时,比较快捷的方法是使用cpan工具。默认cpan shell 使用的是cpan.org的源,在国内使用的话速度会非常的慢。如果更换为国内的如阿里或网易等公司的源的话,速度会明显提高。修改方法如下:

1、执行cpan命令确认存在该命令

如果cpan执行后提示找到该命令,可以通过yum -y install perl-CPAN 或手动安装该模块。
[root@localhost CPAN]# cpan
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
………… 省略
commit: wrote '/usr/share/perl5/CPAN/Config.pm'
Terminal does not support AddHistory.
cpan shell -- CPAN exploration and modules installation (v1.9402)
Enter 'h' for help.

首次执行会出现yes/no的界面,输入yes会自动配置,输入no会让手动的配置一些参数。这里我选择了yes,配置好后的配置文件存放在/usr/share/perl5/CPAN/Config.pm。

2、查看当前源配置
cpan[1]> o conf
$CPAN::Config options from '/usr/share/perl5/CPAN/Config.pm':
    commit            [Commit changes to disk]
    defaults          [Reload defaults from disk]
    help              [Short help about 'o conf' usage]
    init              [Interactive setting of all options]
    applypatch        []
    auto_commit        [0]
    build_cache        [100]
    build_dir          [/root/.cpan/build]
    build_dir_reuse    [0]
    build_requires_install_policy [ask/yes]
    bzip2              [/usr/bin/bzip2]
    cache_metadata    [1]
    check_sigs        [0]
cpan[2]> o conf urllist
    urllist
Type 'o conf' to view all configuration items

默认没有配置源,也即使用的官方源,所以这里查不到源信息。

3、增加源或移出源并提交
cpan[3]> o conf urllist push http://mirrors.aliyun.com/CPAN/
Please use 'o conf commit' to make the config permanent!
cpan[4]> o conf commit
commit: wrote '/usr/share/perl5/CPAN/Config.pm'

也可以一次增加多个源:
cpan[4]> o conf urllist ftp://mirrors.sohu.com/CPAN/ http://mirrors.163.com/cpan/

移出一个源可以使用pop函数,如下:
cpan[3]> o conf urllist pop http://mirrors.163.com/cpan/ ftp://mirrors.sohu.com/CPAN/

再次查看当前源信息
 cpan[5]> o conf urllist
    urllist
        0 [http://mirrors.aliyun.com/CPAN/]
Type 'o conf' to view all configuration items

也可以为本地用户自定义一个配置文件,可以配置为root的环境变量文件(原理类似于profile 与 ~/.bash_profile)
# mkdir -p /root/.cpan/CPAN/
# cp /usr/share/perl5/CPAN/Config.pm /root/.cpan/CPAN/MyConfig.pm

4、重新初始化配置

如果对当前的当前所有的cpan shell 的配置不满意,也可以通过命令重新初始化该文件,如下:
cpan> o conf init

本文永久更新链接地址http://www.linuxidc.com/Linux/2017-10/148010.htm

linux
相关资讯       CPAN  修改CPAN mirror默认源 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款