通过编辑 CPAN 配置文件,更新镜像源

通过编辑 CPAN 配置文件,更新镜像源

手动编辑 CPAN 配置文件

找到 CPAN 配置文件:

CPAN 的配置文件通常位于 ~/.cpan/CPAN/MyConfig.pm。如果该文件不存在,您可以通过 cpan 命令来生成。

cpan

然后输入 exit 退出。

编辑配置文件:

打开 ~/.cpan/CPAN/MyConfig.pm,找到 urllist 部分,并修改为清华镜像。

'urllist' => [
'http://mirrors.tuna.tsinghua.edu.cn/CPAN/',
],

保存并退出编辑器。

以下是一个完整的配置文件示例:

$CPAN::Config = {
'build_cache' => q[100],
'build_dir' => q[/home/username/.cpan/build],
'cache_metadata' => q[1],
'cpan_home' => q[/home/username/.cpan],
'dontload_hash' => {},
'ftp_passive' => q[1],
'ftp_proxy' => q[],
'getcwd' => q[cwd],
'gpg' => q[],
'gzip' => q[/bin/gzip],
'histfile' => q[/home/username/.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[/home/username/.cpan/sources],
'load_module_verbosity' => q[v],
'make' => q[/usr/bin/make],
'make_arg' => q[],
'make_install_arg' => q[],
'make_install_make_command' => q[/usr/bin/make],
'makepl_arg' => q[],
'mbuild_arg' => q[],
'mbuild_install_arg' => q[],
'mbuild_install_build_command' => q[./Build],
'mbuildpl_arg' => q[],
'ncftp' => q[],
'ncftpget' => q[],
'no_proxy' => q[],
'pager' => q[/usr/bin/less],
'perl5lib_verbosity' => q[v],
'prefer_installer' => q[EUMM],
'prefs_dir' => q[/home/username/.cpan/prefs],
'prerequisites_policy' => q[follow],
'scan_cache' => q[atstart],
'shell' => q[/bin/bash],
'show_unparsable_versions' => q[0],
'tar' => q[/bin/tar],
'term_is_latin' => q[1],
'unzip' => q[/usr/bin/unzip],
'urllist' => [q[http://mirrors.tuna.tsinghua.edu.cn/CPAN/]],
'use_sqlite' => q[0],
'wget' => q[/usr/bin/wget],
'yaml_load_code' => q[0],
'yaml_module' => q[YAML],
};
1;
__END__

将 ‘urllist’ 部分修改为清华镜像即可。

验证配置

您可以通过以下命令验证配置是否成功:

cpan

然后在 CPAN shell 中执行:

o conf urllist

如果配置成功,您应该会看到 http://mirrors.tuna.tsinghua.edu.cn/CPAN/ 在列表中。

通过以上步骤,您可以将 CPAN 的源设置为清华大学的镜像,加快模块下载速度。