欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

cpanm安装及Perl模块安装教程

程序员文章站 2022-04-29 19:15:14
cpanm是安装perl模块的最方便的方法。自动下载安装依赖包。使用cpan shell或下载源码包安装模块,遇到大量依赖关系,非常头痛。下面就是一例: 安装mongod...

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

相关标签: cpanm Perl