linux中修改CPAN mirror的預設源的教程

來源:互聯網
上載者:User

安裝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
寫在最後,如果沒有外網環境,或者想手動安裝模組的,也可以參看我之前的博文 CPAN模組的安裝 。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.