一歩前進

プログラミングに関する雑多なメモ

[Mac] perlbrewでERROR: Failed to retrieve patchperl executable.が出たときの対処

Mac上でのperlbrewで"ERROR: Failed to retrieve patchperl executable"というエラーが出たので回避策をメモします。 どうやら、MacPortsからインストールしたwgetに関連するエラーのようで、これを使わないようにすることでエラーを回避できました。

エラーのログ:

$ \curl -L http://install.perlbrew.pl | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0   315    0     0    0     0      0      0 --:--:--  0:00:03 --:--:--     0
100  1020  100  1020    0     0    175      0  0:00:05  0:00:05 --:--:--  3763

## Download the latest perlbrew

## Installing perlbrew
perlbrew is installed: ~/perl5/perlbrew/bin/perlbrew

perlbrew root (~/perl5/perlbrew) is initialized.

Append the following piece of code to the end of your ~/.zshenv and start a
new shell, perlbrew should be up and fully functional from there:

    source ~/perl5/perlbrew/etc/bashrc

Simply run `perlbrew` for usage details.

Happy brewing!

## Installing patchperl

ERROR: Failed to retrieve patchperl executable.

perlbrew本体のインストールは出来ているものの、その先のpatchperlのインストールで失敗しているようです。以下のやりとりをみると、どうやらMacPortsからインストールしたwgetがよろしくないようです。

"Installing perlbrew on OS X Mavericks (10.9.1) and macports"
http://stackoverflow.com/questions/20921886/installing-perlbrew-on-os-x-mavericks-10-9-1-and-macports

SSL証明書関連の問題かと思い、wget側でもcurlがみている証明書を参照するようにしたのですが、どうやら違う模様。

対処

方法その1

MacPortsのactivate, deactivateを使って、一時的にwgetを使わないようにする方法です。

(1) MacPortsdeactivateコマンドでwgetをオフにしておきます。

 $ sudo port deactivate wget
Password:
--->  Deactivating wget @1.14_5+ssl+universal
--->  Cleaning wget

(2) 次に、さきほどインストールしたperlbrewを一旦削除して、クリーンな状態に戻しておきます。

$ rm -rf ~/perl5/perlbrew

(3) ここでperlbrewをインストールします。今度はうまくいきました。

$ \curl -L http://install.perlbrew.pl | bash
... (中略)
Happy brewing!

## Installing patchperl

## Done.

(4) MacPortsを元に戻しておきます。

$ sudo port activate wget
--->  Computing dependencies for wget
--->  Activating wget @1.14_5+ssl+universal

To customize wget, you can copy /opt/local/etc/wgetrc.sample to /opt/local/etc/wgetrc     and then make changes.

--->  Cleaning wget

方法その2

方法1だと、perlbrewから何かインストールする度にwgetをdeactiveにする必要があります。スクリプトを作ってしまうのも手ですが、以下のエントリをみると、wgetとfetchの定義を削ればいいようです。wgetが無くても動くことは方法1で分かっているので、perlbrewを編集してみます。

「さくらのレンタルサーバに perlbrew」
http://www.naney.org/diki/d/2013-09-23-perlbrew.html

(1) perlbrewのバックアップを取る

cd ~/perl5/perlbrew/bin
cp perlbrew perlbrew.bak

(2) perlbrewを編集する

適当なエディタでperlbrewを開きます。8行目あたりにやたらと長い1行が出てくるため、表示がうまくいかない場合は折り返しをオフにするといいでしょう。(vimの場合は:set nowrap)

次のような箇所を探します。

my%commands=(curl=>{test=>'--version >/dev/null 2>&1',get=>'--silent --location --fail -o - {url}',download=>'--silent --location --fail -o {output} {url}' },wget=>{test=>'--version >/dev/null 2>&1',get=>'--quiet -O - {url}',download=>'--quiet -O {output} {url}',},fetch=>{test=>'--version >/dev/null 2>&1',get=>'-o - {url}',download=>'{url}' });sub http_user_agent_program {...

上記のwgetfetchの定義箇所を削除して保存します。 (※ただし、cpanmとpatchperlで試した限りでは、fetchの定義を削らなくてもエラーにはなりませんでした。どうやらwget固有の問題のようですが、念のためfetchも定義から除外しておきます。)

これでcpanmも無事インストールできました。

perlbrew install-cpanm

cpanm is installed to

    /Users/succzero/perl5/perlbrew/bin/cpanm

余談

wgetを無効にしない状態では、cpanmに関してはperl -dで実行するとうまくインストールされます。ただし、patchperlについては以下のissueのように-dの有無によらず失敗します。

"perlbrew fails to install patchperl"
https://github.com/gugod/App-perlbrew/issues/350

perl -dのログ:

$ perl -d ./perlbrew.bak install-cpanm

Loading DB routines from perl5db.pl version 1.39_10
Editor support available.

Enter h or 'h h' for help, or 'man perldebug' for more help.

main::(./perlbrew.bak:564): my $app = App::perlbrew->new(@ARGV);
  DB<1> r

/Users/succzero/perl5/perlbrew/bin/cpanm already exists, are you sure to override ? [y/N] [N] y

cpanm is installed to

    /Users/succzero/perl5/perlbrew/bin/cpanm

Debugged program terminated.  Use q to quit or R to restart,
use o inhibit_exit to avoid stopping after program termination,
h q, h R or h o to get additional info.