GNU/Linux >> Linux の 問題 >  >> Linux

CPAN コマンドを使用して Perl モジュールを手動でインストールする方法

さまざまなオープン ソース ソフトウェアに必要な Perl モジュールのインストールは、システム管理者にとって日常的なタスクです。 Perl モジュールの手動インストール すべての依存関係を解決するのは、退屈で煩わしいプロセスです。

CPAN を使用した Perl モジュールのインストール すべての依存関係を自動的に解決するため、より優れたソリューションです。この記事では、手動と CPAN の両方の方法を使用して Linux に Perl モジュールをインストールする方法を確認します。


Perl モジュールがインストールされていない場合、アプリケーションは次のエラー メッセージを表示します。この例では、XML::Parser Perl モジュールが欠落しています。

Can't locate XML/parser.pm in @INC (@INC contains:
/usr/lib/perl5/5.10.0/i386-linux-thread-multi
/usr/lib/perl5/5.10.0
/usr/local/lib/perl5/site_perl/5.10.0/i386-linux-thread-multi
/usr/local/lib/perl5/site_perl/5.10.0
/usr/lib/perl5/vendor_perl/5.10.0/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.10.0 /usr/lib/perl5/vendor_perl
/usr/lib/perl5/site_perl/5.10.0 .)

Perl モジュールを手動でインストールする

Perl モジュールをダウンロード

CPAN 検索 Web サイトにアクセスし、ダウンロードするモジュールを検索します。この例では、XML::Parser Perl モジュールを検索、ダウンロード、およびインストールします。 XML-Parser-2.36.tar.gz を /home/download にダウンロードしました

# cd /home/download
# gzip -d XML-Parser-2.36.tar.gz
# tar xvf XML-Parser-2.36.tar
# cd XML-Parser-2.36

perl モジュールをビルドする

# perl Makefile.PL
Checking if your kit is complete...
Looks good
Writing Makefile for XML::Parser::Expat
Writing Makefile for XML::Parser
# make
# make test

perl モジュールをインストールします

# make install

これは、依存関係のない 1 つのモジュールにとって非常に簡単です。通常、Perl モジュールは他のいくつかのモジュールに依存します。これらすべての依存関係を 1 つずつ追跡することは、非常に苦痛で面倒な作業になる可能性があります。以下に示すように、CPAN によるインストール方法をお勧めします。サーバーがインターネットに接続されていない場合にのみ、手動の方法を使用してください。

CPAN を使用して Perl モジュールを自動的にインストールする

CPAN が既にインストールされているかどうかを確認する

CPAN を使用して Perl モジュールをインストールするには、cpan コマンドが機能していることを確認してください。 CPAN を使用して他の Perl モジュールをインストールする前に、CPAN perl モジュールをインストールする必要があります。この例では、CPAN モジュールはインストールされていません。

# cpan
-bash: cpan: command not found

# perl -MCPAN -e shell
Can't locate CPAN.pm in @INC (@INC contains:
/usr/lib/perl5/5.10.0/i386-linux-thread-multi
/usr/lib/perl5/5.10.0
/usr/local/lib/perl5/site_perl/5.10.0/i386-linux-thread-multi
/usr/local/lib/perl5/site_perl/5.10.0
/usr/lib/perl5/vendor_perl/5.10.0/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.10.0
/usr/lib/perl5/vendor_perl /usr/lib/perl5/site_perl/5.10.0 .).
BEGIN failed--compilation aborted.

yum を使用して CPAN モジュールをインストールする

# yum install perl-CPAN

yum install perl-CPAN コマンドの出力:

Loaded plugins: refresh-packagekit
updates-newkey                       | 2.3 kB     00:00
primary.sqlite.bz2                   | 2.4 MB     00:00
Setting up Install Process
Parsing package install arguments

Resolving Dependencies
Transaction Summary
=============================================================================
Install      5 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 1.0 M
Is this ok [y/N]: y
Downloading Packages:
(1/5): perl-ExtUtils-ParseXS-2.18-31.fc9.i386.rpm     |  30 kB     00:00
(2/5): perl-Test-Harness-2.64-31.fc9.i386.rpm         |  70 kB     00:00
(3/5): perl-CPAN-1.9205-31.fc9.i386.rpm               | 217 kB     00:00
(4/5): perl-ExtUtils-MakeMaker-6.36-31.fc9.i386.rpm   | 284 kB     00:00
(5/5): perl-devel-5.10.0-31.fc9.i386.rpm              | 408 kB     00:00

Installing     : perl-ExtUtils-ParseXS                             [1/5]
Installing     : perl-devel                                        [2/5]
Installing     : perl-Test-Harness                                 [3/5]
Installing     : perl-ExtUtils-MakeMaker                           [4/5]
Installing     : perl-CPAN                                         [5/5]


Installed: perl-CPAN.i386 0:1.9205-31.fc9
Dependency Installed:
  perl-ExtUtils-MakeMaker.i386 0:6.36-31.fc9
  perl-ExtUtils-ParseXS.i386 1:2.18-31.fc9
  perl-Test-Harness.i386 0:2.64-31.fc9
  perl-devel.i386 4:5.10.0-31.fc9
Complete!

初めて cpan を構成する

初めて cpan を実行するときは、以下に示すようにいくつかの構成パラメーターを設定する必要があります。以下に、重要な設定パラメータのみを示しました。 Enter キーを押してすべてのデフォルト値を受け入れます。

注:o conf commit」を必ず実行してください 」を設定後に cpan プロンプトで入力して、設定を保存します。

# cpan

Sorry, we have to rerun the configuration dialog for CPAN.pm due
to some missing parameters...

CPAN build and cache directory? [/root/.cpan]
Download target directory? [/root/.cpan/sources]
Directory where the build process takes place? [/root/.cpan/build]

Always commit changes to config variables to disk? [no]
Cache size for build directory (in MB)? [100]
Let the index expire after how many days? [1]

Perform cache scanning (atstart or never)? [atstart]
Cache metadata (yes/no)? [yes]
Policy on building prerequisites (follow, ask or ignore)? [ask]

Parameters for the 'perl Makefile.PL' command? []
Parameters for the 'perl Build.PL' command? []

Your ftp_proxy? []
Your http_proxy? []
Your no_proxy? []
Is it OK to try to connect to the Internet? [yes]

First, pick a nearby continent and country by typing in the number(s)
(1) Africa
(2) Asia
(3) Central America
(4) Europe
(5) North America
(6) Oceania
(7) South America
Select your continent (or several nearby continents) [] 5

(1) Bahamas
(2) Canada
(3) Mexico
(4) United States
Select your country (or several nearby countries) [] 4

(2) ftp://carroll.cac.psu.edu/pub/CPAN/
(3) ftp://cpan-du.viaverio.com/pub/CPAN/
(4) ftp://cpan-sj.viaverio.com/pub/CPAN/
(5) ftp://cpan.calvin.edu/pub/CPAN
(6) ftp://cpan.cs.utah.edu/pub/CPAN/
e.g. '1 4 5' or '7 1-4 8' [] 2-16

cpan[1]> o conf commit
commit: wrote '/usr/lib/perl5/5.10.0/CPAN/Config.pm'

cpan[2]> quit
No history written (no histfile specified).
Lockfile removed.

CPAN を使用して Perl モジュールをインストールする

cpan を使用して Perl モジュールをインストールするには、次のいずれかの方法を使用できます。

# /usr/bin/perl -MCPAN -e 'install Email::Reply'

(or)

# cpan
cpan shell -- CPAN exploration and modules installation (v1.9205)
ReadLine support available (maybe install Bundle::CPAN or Bundle::CPANxxl?)

cpan[1]> install "Email::Reply";

上記の perl インストール コマンドの出力:

CPAN: Storable loaded ok (v2.18)
Going to read /root/.cpan/Metadata
Database was generated on Mon, 15 Sep 2008 11:02:52 GMT

Running install for module 'Email::Reply'
Running make for R/RJ/RJBS/Email-Reply-1.202.tar.gz
CPAN: LWP::UserAgent loaded ok (v2.036)
CPAN: Time::HiRes loaded ok (v1.9711)
Fetching with LWP:
ftp://carroll.cac.psu.edu/pub/CPAN/authors/id/R/RJ/RJBS/Email-Reply-1.202.tar.gz

CPAN: checksum security checks disabled because Digest::SHA not installed.
Please consider installing the Digest::SHA module.

CPAN: Compress::Zlib loaded ok (v2.008)
Email-Reply-1.202/
Email-Reply-1.202/Changes
CPAN: File::Temp loaded ok (v0.18)
Warning: prerequisite Email::Abstract 2.01 not found.
Warning: prerequisite Email::MIME::Creator 1.41 not found.
Writing Makefile for Email::Reply
---- Unsatisfied dependencies detected during ----
----       RJBS/Email-Reply-1.202.tar.gz      ----
Email::Abstract [requires]
Email::MIME::Creator [requires]
Shall I follow them and prepend them to the queue

of modules we are processing right now? [yes]
[Note: CPAN automatically detects that Email::Abstract
       and Email::MIME::Creator is required]

Fetching with LWP:
ftp://server/pub/CPAN/authors/id/R/RJ/RJBS/Email-Abstract-2.134.tar.gz
make -- OK
make install  -- OK

Fetching with LWP:
ftp://server/pub/CPAN/authors/id/R/RJ/RJBS/Email-MIME-Creator-1.454.tar.gz
make -- OK
make install  -- OK

Warning: prerequisite Email::Simple::Creator 1.4 not found.
Writing Makefile for Email::MIME::Creator
Email::Simple::Creator [requires]
Shall I follow them and prepend them to the queue
of modules we are processing right now? [yes]
[Note: CPAN automatically detects that Simple::Creator is required]

Fetching with LWP:
ftp://carroll.cac.psu.edu/pub/CPAN/authors/id/R/RJ/RJBS/Simple-Creator.tar.gz
make -- OK
make install  -- OK

Fetching with LWP:
CPAN.pm: Going to build R/RJ/RJBS/Email-Reply-1.202.tar.gz

make -- OK
make install  -- OK

上記の例では、Email::Reply は他のいくつかのモジュールに依存しています。 CPAN は依存関係を自動的に解決します Email::Reply とそれに依存するすべての Perl モジュールをインストールします。

この記事が気に入ったら、del.icio.us でブックマークしてください そしてつまずく .


Linux
  1. Raspberry Piファイアウォール:UFWを使用してインストールおよび管理する方法

  2. LinuxにPerlモジュールをインストールする方法

  3. Linux コマンドを使用して OS とバージョンを確認する方法

  1. cPanelを使用してWordPressを手動でインストールする方法

  2. CentOS7および8にdigをインストールする方法

  3. LinuxでPingコマンドをインストールして使用する方法

  1. 共有サーバーにPerlモジュールをインストールする方法

  2. LinuxにSSHFSをインストールして使用する方法

  3. Linuxでlocateコマンドをインストールして使用する方法