Perl学习11之perl模块详解(二)
"pythonic生物人"的第17篇分享
摘要
详细介绍cpan在非root权限下安装perl包
目录
2、cpan下载模块
3、cpan常用参数介绍和配置
4、cpan下载源
常用国内下载源
cpan下载源配置
正文开始啦
1、配置个人cpan
wget -O- http://cpanmin.us | perl - -l ~/perl5 App::cpanminus local::lib
eval `perl -I ~/perl5/lib/perl5 -Mlocal::lib`
echo 'eval `perl -I ~/perl5/lib/perl5 -Mlocal::lib`' >> ~/.bashrc
echo 'export MANPATH=$HOME/perl5/man:$MANPATH' >> ~/.bashrc
source ~/.bashrc
详细介绍每行的意义
wget -O- http://cpanmin.us | perl - -l ~/perl5 App::cpanminus local::lib
wget -O- http://cpanmin.us fetches the latest version of cpanm and prints it to STDOUT which is then piped to perl - -l ~/perl5 App::cpanminus local::lib. The first - tells perl to expect the program to come in on STDIN, this makes perl run the version of cpanm we just downloaded.perl passes the rest of the arguments to cpanm. The -l ~/perl5 argument tells cpanm where to install Perl modules, and the other two arguments are two modules to install. [App::cpanmins]1 is the package that installs cpanm. local::lib is a helper module that manages the environment variables needed to run modules in local directory.
eval `perl -I ~/perl5/lib/perl5 -Mlocal::lib`
echo 'eval `perl -I ~/perl5/lib/perl5 -Mlocal::lib`' >> ~/.bashrc
.bashrc会随着linux系统不同而不同,如.profile .bash_profile
to ensure we will be able to use them the next time we log in.(环境变量配置)
echo 'export MANPATH=$HOME/perl5/man:$MANPATH' >> ~/.bashrc
will hopefully cause man to find the man pages for your local modules.
source ~/.bashrc
立马生效
2、cpan下载模块
经过第一步配置,可以像root账户一样自由下载模块了,以安装Module::Runtime模块为例。
cpan Module::Runtime
3、cpan常用参数介绍和配置
h,? 获得帮助;
o conf 查看当前 CPAN 的配置信息,如下(部分内容)
o conf 第1列关键字 修改信息 即可以修改对应第2列的配置信息,例如
#常用配置1,修改cpan下载源:添加阿里云源和清华源,不加push会直接覆盖默认内容
o conf urllist push https://mirrors.aliyun.com/CPAN/ https://mirrors.tuna.tsinghua.edu.cn/CPAN/
#常用配置2,修改CPAN 模块安装位置
#Makefile.PL 需要make的模块
o conf makepl_arg INSTALL_BASE=/home/perl15
#Build.PL 需要build的模块
o conf mbuild_arg INSTALL_BASE=/home/perl15
#常用配置3,配置自动提交,修改后以后再修改不用使用o conf commit
o conf auto_commit 1
##以上配置结束后,执行以下命令才能生效,类似linux中source
o conf commit
q 退出cpan终端
4、cpan下载源
常用国内下载源
cpan上公示常用的国内源见http://mirrors.163.com/cpan/SITES.html
China
http://mirrors.163.com/cpan/
AnHui
ftp://mirrors.ustc.edu.cn/CPAN/
http://mirrors.ustc.edu.cn/CPAN/
rsync://mirrors.ustc.edu.cn/CPAN/
Gansu
http://mirror.lzu.edu.cn/CPAN/
Hong Kong SAR
ftp://ftp.cuhk.edu.hk/pub/packages/perl/CPAN/
http://cpan.metacpan.org/
http://ftp.cuhk.edu.hk/pub/packages/perl/CPAN/
http://mirror-hk.koddos.net/CPAN/
rsync://mirror-hk.koddos.net/CPAN/
Liaoning
http://mirrors.neusoft.edu.cn/cpan/
其它一些源
不单只有Perl源还有Python源
阿里云源:https://mirrors.aliyun.com/CPAN/
清华源:https://mirrors.tuna.tsinghua.edu.cn/CPAN/
cpan下载源配置
方法一:cpan端同时添加多个源。
#push指定阿里云源和清华源,不加push会直接覆盖默认内容
o conf urllist push https://mirrors.aliyun.com/CPAN/ https://mirrors.tuna.tsinghua.edu.cn/CPAN/
#提交,写入到磁盘配置文件
o conf commit
方法二:直接修改cpan参数配置文件CPAN/MyConfig.pm。
该文件位置可以通过如下获得
cpan[6]> o conf
$CPAN::Config options from /home/.local/share/.cpan/CPAN/MyConfig.pm:
https://stackoverflow.com/questions/2980297/how-can-i-use-cpan-as-a-non-root-user