CentOS8とcpanm(cpanminus)によるPerlモジュールの導入・環境構築

CentOS8とcpanm(cpanminus)によるPerlモジュールの導入・環境構築

2020-10-303 min read

目次

  1. 概要
  2. cpanmについて
  3. cpanmのインストール-dnfでインストール
  4. cpanmのインストール-shell経由でインストール
  5. cpanmのインストール-cpan経由
  6. cpanmでcpanモジュールをインストール
  7. 参考にしたサイト
  8. おまけ-cpanmのオプション

概要

cpanm(cpanminus)を利用してCentOS8上にPerl環境を構築した際の記録です。

cpanmについて

miyagawa/cpanminus - github

App::cpanminus - get, unpack, build and install modules from CPAN - metacpan.org

CPANからモジュールの取得とビルド・インストールを行うライブラリです。

CPAN::shellでもモジュールのインストールはできますが、設定しやすさやパーフォマンス・権限等の問題からcpanmの方が扱いやすいと思いました。

cpanmのインストール (DNFでインストール)

CentOS8の場合は標準でRPMパッケージが用意されているためDNFでインストールします。

$ dnf install perl-App-cpanminus
$ which cpanm
/usr/bin/cpanm

cpanmのインストール (shell経由でインストール)

root権限が利用できない場合は次のような手順で設定していきます。

まずはcpanmをインストールします。環境変数PERL_CPANM_OPTはCPANモジュールがインストールされるディレクトリを指定します。

$ export PERL_CPANM_OPT="--local-lib=~/perl5"
$ curl -L -O http://xrl.us/cpanm
$ perl cpanm App::cpanminus

PATHを通します。

$ export PATH=$HOME/perl5/bin:$PATH;
$ which cpanm
~/perl5/bin/cpanm

cpanmのインストール (cpan経由)

CPANが利用できる場合はCPANコマンドを利用してcpanmをインストールもできます。

$ cpan App::cpanminus

cpanmでCPANモジュールをインストール

試しにJSONモジュールをインストールします。

$ cpanm JSON
--> Working on JSON
Fetching http://www.cpan.org/authors/id/I/IS/ISHIGAKI/JSON-4.02.tar.gz ... OK
Configuring JSON-4.02 ... OK
Building and testing JSON-4.02 ... OK
Successfully installed JSON-4.02
2 distributions installed

ローカルに配置したファイルもインストールできます。

$ cpanm /home/foo/YAML-1.30.tar.gz

インストールするディレクトリを指定してインストールもできます。以下のコマンドの場合は~/testにインストールされます。

$ cpanm YAML -L ~/test

参考にしたサイト

cpanm - CPANからモジュールを取得、アンパック、インストールする

cpanmによるPerlのローカル環境構築

perlモジュールのinstallにcpanmを使う

おまけ cpanmのオプション

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.
Tags
javascript(109)
linux(54)
node.js(53)
amazon%20aws(47)
typescript(44)
%E3%82%A2%E3%83%AB%E3%82%B4%E3%83%AA%E3%82%BA%E3%83%A0(36)
%E7%94%BB%E5%83%8F%E5%87%A6%E7%90%86(30)
html5(29)
php(24)
centos(24)
python(22)
%E7%AB%B6%E6%8A%80%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0(21)
mac(21)
mysql(20)
canvas(19)
opencv(17)
%E9%9B%91%E8%AB%87(16)
docker(16)
wordpress(15)
atcoder(14)
apache(12)
%E6%A9%9F%E6%A2%B0%E5%AD%A6%E7%BF%92(12)
%E3%83%87%E3%83%BC%E3%82%BF%E3%83%99%E3%83%BC%E3%82%B9(12)
amazon%20s3(12)
red%20hat(12)
prisma(12)
ubuntu(11)
github(10)
git(10)
vue.js(10)
%E7%94%BB%E5%83%8F%E5%87%A6%E7%90%86100%E6%9C%AC%E3%83%8E%E3%83%83%E3%82%AF(10)
mariadb(10)
react(9)
aws%20cdk(9)
css3(8)
%E5%8F%AF%E8%A6%96%E5%8C%96(8)
%E5%B0%8F%E3%83%8D%E3%82%BF(8)
nestjs(8)
amazon%20lightsail(7)
next.js(7)
%E3%83%96%E3%83%AD%E3%82%B0(6)
cms(6)
oracle(6)
perl(6)
gitlab(6)
iam(5)
amazon%20ec2(5)
%E8%B3%87%E6%A0%BC%E8%A9%A6%E9%A8%93(5)
aws%20amplify(5)
curl(4)
Author
githubzennqiita
ただの備忘録です。

※外部送信に関する公表事項