cpanmのインストール方法

P1010154
毎回検索するのもつかれたのでcpanmのインストール方法をメモっておく。参考にしたのは下記の二つのサイト。感謝。

正直「perl -MCPAN -e shell」でいいじゃん?とそんなふうに考えていた時期が俺にも有りました。(AA略)

しかし、そうではなかった。参考サイトを診てもらうと分かるようにcpanmの利点として

  • 高速であること
  • 省メモリであること

が挙げられている。

実際どうかというと、それはもう爆速。cpan shellに比べて爆速も爆速。もうあの頃には戻れない。そして、速度だけであればまだしも、省メモリであることは重要。

私は少メモリのVPSを使っている。するとどういうことが起こるかというと、cpan shellでモジュールをインストールしようとすると長々とコンパイルした後、よくわからないエラーでインストールに失敗することが有る。モジュールの依存とは別に。

「ああ、だめなんだな」くらいに思っていた。

ところがそのモジュールをcpanmでインストールしてみるとすんなり出来たりする。

つまり、少メモリのVPSだとメモリ不足でモジュールのインストールに失敗していたと考えられるわけだ。それがわかってからはcpanmを使うことにした。

以下cpanmのインストール方法。

# cd /usr/bin/
#
curl -LOk http://xrl.us/cpanm
# chmod +x cpanm


local::libを入れておくと便利らしい。私ごときだと余り活用することはないかも知れないw。
第18回 local::lib:ふだんと違う環境でPerlを使う:モダンPerlの世界へようこそ|gihyo.jp … 技術評論社

# cpanm local::lib


cpanmのアップグレード方法。

# cpanm –self-upgrade


cpanmのヘルプ

基本的な使い方は、下のExamplesのところを見ると分かる。普通にモジュール名を指定したり、Tarボールを指定して直接インストール出来るみたい。すごい。

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
  –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
  –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
  -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

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.

未だにcpan shellを使ってる人には、早めにcpanmに移行することをお勧めする。

(Visited 144 times, 1 visits today)

タグ : , ,