阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

修改CPAN mirror的默认源

234次阅读
没有评论

共计 2437 个字符,预计需要花费 7 分钟才能阅读完成。

详细介绍对 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

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计2437字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中