LoginSignup
2
2

More than 3 years have passed since last update.

[RHEL7/CentOS7] yumコマンドでPerlをインストールした環境でLWP実行エラー

Last updated at Posted at 2020-02-21

エラーが発生

動作確認済みの Web アクセスを行う Perl プログラムをある環境で動かすと実行エラーが発生。

HTTP で Web アクセスした場合のエラー

$ perl test.pl
501 Attempt to reload IO/Socket.pm aborted.
Compilation failed in require

HTTPS で Web アクセスした場合のエラー

$ perl test.pl
LWP will support https URLs if the LWP::Protocol::https module
is installed.

該当Perlスクリプト

test.pl
#!/usr/bin/perl
use LWP::UserAgent;

my $url = "https://www.example.com";
my $request = HTTP::Request->new(GET => $url);
my $useragent = LWP::UserAgent->new;
my $response = $useragent->request($request);
my $result = $response->content;
print $result;

事前に構築していたPerl環境

Perl はこれまで実績のあるやり方で yumコマンドにてインストールを行っており、必要なライブラリも同様にインストール済み。なのに実行エラーが発生する。

$ sudo yum install perl
$ sudo yum install perl-Net-SSLeay
$ sudo yum install perl-Crypt-SSLeay
$ sudo yum install perl-IO-Socket-SSL
$ sudo yum install perl-IO-stringy
$ sudo yum install perl-URI
$ sudo yum install perl-LWP-Protocol-https

※LWP は Library for WWW in Perl の略で、Perl から Web アクセスを実現するライブラリです。

原因と対策

正常動作する環境と見比べると Perl のパッケージで perl-Socket がインストールされていないことがわかりました。
このパッケージを yum コマンドでインストールするとあっさり解決!

$ sudo yum install perl-Socket

※実際には他にも多くの Perl パッケージで差異があったため、一つ一つ順番に追加インストールして動作確認を行い、このパッケージにたどり着きました。

通常は依存関係でインストールされるパッケージであり、これだけ個別にインストールしたこと無いのですが、利用していた環境が某クラウドにインストールされた RHEL7 でパッケージ管理に問題を抱えていたのかもしれません。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2