最近接到一个需求,给Perl安装Spreadsheet::WriteExcel模块。原以为挺简单的事,没想到找不到资源,网上大都说需要下载插件源码包,然后编译安装,但是找了一圈都没找到源码包下载地址,好不容易找到源码包,下载了安装又提示缺少依赖:

Warning: prerequisite OLE::Storage_Lite 0.19 not found.
Warning: prerequisite Parse::RecDescent 0 not found. 
Writing Makefile for Spreadsheet::WriteExcel

忽然间看到一个教程,可以通过cpanm安装Perl模块,自动安装缺乏的依赖,看操作比较傻瓜,咱啥也不懂,怎么简单怎么来嘛!说干就干。

安装cpanm

其实就是下载cpanm文件,放到/usr/bin/目录,然后给执行权限即可。
# wget https://raw.githubusercontent.com/miyagawa/cpanminus/master/cpanm -O /usr/bin/cpanm; chmod +x /usr/bin/cpanm

检查cpanm

# cpanm -h
Usage: cpanm [options] Module [...]

Options:
  -v,--verbose              Turns on chatty output
  -q,--quiet                Turns off the most output
  --interactive             Turns on interactive configure (required for Task:: modules)
  -f,--force                force install
  -n,--notest               Do not run unit tests
  --test-only               Run tests only, do not install
  -S,--sudo                 sudo to run install commands
  --installdeps             Only install dependencies
  --showdeps                Only display direct dependencies
  --reinstall               Reinstall the distribution even if you already have the latest version installed
  --mirror                  Specify the base URL for the mirror (e.g. http://cpan.cpantesters.org/)
  --mirror-only             Use the mirror's index file instead of the CPAN Meta DB
  -M,--from                 Use only this mirror base URL and its index file
  --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

Commands:
  --self-upgrade            upgrades itself
  --info                    Displays distribution info on CPAN
  --look                    Opens the distribution with your SHELL
  -U,--uninstall            Uninstalls the modules (EXPERIMENTAL)
  -V,--version              Displays software version

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
  cpanm -M https://cpan.metacpan.org App::perlbrew          # use only this secure mirror and its index

You can also specify the default options in PERL_CPANM_OPT environment variable in the shell rc:

  export PERL_CPANM_OPT="--prompt --reinstall -l ~/perl --mirror http://cpan.cpantesters.org"

Type `man cpanm` or `perldoc cpanm` for the more detailed explanation of the options.

安装模块

# cpanm Spreadsheet::WriteExcel

完事,跑路!

最后修改:2022 年 11 月 05 日
如果觉得我的文章对你有用,请随意赞赏