cpanm安装及Perl模块安装教程

所属分类: 脚本专栏 / perl 阅读数: 831
收藏 0 赞 0 分享

cpanm是安装Perl模块的最方便的方法。自动下载安装依赖包。使用CPAN shell或下载源码包安装模块,遇到大量依赖关系,非常头痛。下面就是一例:

安装MongoDB模块

复制代码 代码如下:

# perl Makefile.PL
Warning: prerequisite Class::Method::Modifiers 0 not found.
Warning: prerequisite Data::Types 0 not found.
Warning: prerequisite DateTime 0 not found.
Warning: prerequisite DateTime::Tiny 0 not found.
Warning: prerequisite ExtUtils::MakeMaker 6.59 not found. We have 6.30.
Warning: prerequisite File::Slurp 0 not found.
Warning: prerequisite File::Temp 0.17 not found. We have 0.16.
Warning: prerequisite JSON 0 not found.
Warning: prerequisite Moose 0 not found.
Warning: prerequisite Test::Exception 0 not found.
Warning: prerequisite Test::Warn 0 not found.
Warning: prerequisite Tie::IxHash 0 not found.
Warning: prerequisite Try::Tiny 0 not found.
Warning: prerequisite boolean 0 not found.
Writing Makefile for MongoDB

1. 安装cpanm

cpanm其实是一个可执行文件而已。将它下载到bin目录,然后添加执行权限就可以了。

复制代码 代码如下:

# wget http:
//xrl.us/cpanm -O /usr/bin/cpanm; chmod +x /usr/bin/cpanm

2. 使用cpanm安装模块

复制代码 代码如下:

# cpanm -h
  -v,--verbose              Turns on chatty output
  -q,--quiet                Turns off the most output
  --interactive             开启交互配置(required for Task:: modules)
  -f,--force                强制安装
  -n,--notest               Do not run unit tests
  --test-only               只测试不安装
  -S,--sudo                 sudo to run install commands
  --installdeps             只安装依赖模块
  --showdeps                只显示依赖信息
  --reinstall               重新安装
  --mirror                  指定镜像url (e.g. http://cpan.cpantesters.org/)
  --mirror-only             只从镜像下载
  --prompt                  Prompt when configure/build/test fails
  -l,--local-lib            Specify the install base to install modules
  -L,--local-lib-contained  Specify the install base to install all non-core modules
  --self-contained          Install all non-core modules, even if they're already installed.
  --auto-cleanup            Number of days that cpanm's work directories expire in. Defaults to 7

  Examples:
  cpanm Test::More                                          # install Test::More
  cpanm MIYAGAWA/Plack-0.99_05.tar.gz                       # full distribution path
  cpanm http://example.org/LDS/CGI.pm-3.20.tar.gz           # install from URL
  cpanm ~/dists/MyCompany-Enterprise-1.00.tar.gz            # install from a local file
  cpanm --interactive Task::Kensho                          # Configure interactively
  cpanm .                                                   # install from local directory
  cpanm --installdeps .                                     # install all the deps for the current directory
  cpanm -L extlib Plack                                     # install Plack and all non-core deps into extlib
  cpanm --mirror http://cpan.cpantesters.org/ DBI           # use the fast-syncing mirror

参数名直接为模块名称

如,安装MongoDB模块

复制代码 代码如下:

# cpanm MongoDB
--> Working on MongoDB
Fetching http://www.cpan.org/authors/id/F/FR/FRIEDO/MongoDB-0.702.0.tar.gz ... OK
Configuring MongoDB-0.702.0 ... OK
==> Found dependencies: DateTime, Tie::IxHash, Data::Types, DateTime::Tiny, Class::Method::Modifiers, boolean, Moose, File::Slurp, Try::Tiny, Test::Exception, ExtUtils::MakeMaker, Test::Warn, File::Temp, JSON
--> Working on DateTime
......  //自动解决依赖模块

为了加快下载速度, 可以指定使用镜像,并只从镜像下载:

复制代码 代码如下:

# cpanm --mirror http:
//mirrors.163.com/cpan --mirror-only MongoDB

3. 删除模块

安装App::pmuninstall模块:

复制代码 代码如下:

# cpanm App::pmuninstall

4.删除模块

复制代码 代码如下:

# pm-uninstall MongoDB

MongoDB.so: undefined symbol: HeUTF8 问题解决方案参见:https://www.jb51.net/article/56285.htm

更多精彩内容其他人还在看

perl 指定长度并生成一个随机的DNA序列的脚本代码

perl 指定长度并生成一个随机的DNA序列的代码,有需要的朋友可以参考下
收藏 0 赞 0 分享

perl生成特定碱基比例的随机序列的代码

怎么用perl程序,随机生成一条序列,使ACGT四种碱基的含量分别为0.3,0.3,0.2,0.2!
收藏 0 赞 0 分享

学习perl的unless控制结构

在perl的if控制结构中,只有当条件表达式为真时才执行某块代码。如果想让程序块在条件为假时才执行,此时可以把if改成unless
收藏 0 赞 0 分享

有关perl正则表达式的一些杂项

有关perl正则表达式的一些杂项,有需要的朋友可以参考下
收藏 0 赞 0 分享

perl中heredoc使用说明

在成块打印文本的时候特别有用,需要的朋友可以参考下
收藏 0 赞 0 分享

Perl使用chdir的实例代码

Perl使用chdir的例子,供朋友们参考学习
收藏 0 赞 0 分享

perl特殊符号及默认的内部变量

perl特殊符号及默认的内部变量,有需要的朋友不妨参考下
收藏 0 赞 0 分享

perl中my与our的区别介绍

our 和 my 一样,都是对变量的声明,不过 our 声明的是包全局变量,而 my 声明的是词法变量
收藏 0 赞 0 分享

在vim中添加perl注释时无法对齐问题的解决方法

在使用vim编辑perl脚本时,每当输入#号时,#号都会跑到行首问题,需要的朋友可以参考下
收藏 0 赞 0 分享

perl 文件操作总结

perl 文件操作总结,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多