今回の環境。

Mac OS X Yosemite 10.10.3


$ uname -mrsv
Darwin 14.3.0 Darwin Kernel Version 14.3.0: Mon Mar 23 11:59:05 PDT 2015; root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64

Mac OS X には最初から Perl が入っている。


$ perl -v

This is perl 5, version 18, subversion 2 (v5.18.2) built for darwin-thread-multi-2level
(with 2 registered patches, see perl -V for more detail)
(以下略)

Perlbrew のインストール

公式サイト Perlbrew に書いてある通りにインストール。


$ 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:02 --:--:--     0
100  1255  100  1255    0     0    316      0  0:00:03  0:00:03 --:--:--  1805

## 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 ~/.bash_profile 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

## Done.

~/.bash_profile に設定を追加

~/.bash_profile の最後に


source ~/perl5/perlbrew/etc/bashrc

という1行を追加して、


$ source ~/.bash_profile

を実行。

これで perlbrew へのパスが通って、使えるようになる。

Perlbrew のバージョンを確認。


$ perlbrew version
/Users/alice/perl5/perlbrew/bin/perlbrew  - App::perlbrew/0.73

Perlbrew のシンプルなヘルプを確認


$ perlbrew
Usage:
    perlbrew command syntax:

        perlbrew <command> [options] [arguments]

    Commands:

        init           Initialize perlbrew environment.
        info           Show useful information about the perlbrew installation

        install        Install perl
        uninstall      Uninstall the given installation
        available      List perls available to install
        lib            Manage local::lib directories.
        alias          Give perl installations a new name
        upgrade-perl   Upgrade the current perl

        list           List perl installations
        use            Use the specified perl in current shell
        off            Turn off perlbrew in current shell
        switch         Permanently use the specified perl as default
        switch-off     Permanently turn off perlbrew (revert to system perl)
        exec           exec programs with specified perl enviroments.

        self-install       Install perlbrew itself under PERLBREW_ROOT/bin
        self-upgrade       Upgrade perlbrew itself.

        install-patchperl  Install patchperl
        install-cpanm      Install cpanm, a friendly companion.
        install-multiple   Install multiple versions and flavors of perl

        download       Download the specified perl distribution tarball.
        mirror         Pick a preferred mirror site
        clean          Purge tarballs and build directories
        version        Display version
        help           Read more detailed instructions

    Generic command options:

        -q --quiet     Be quiet on informative output message.
        -v --verbose   Tell me more about it.

    See `perlbrew help` for the full documentation of perlbrew, or

    See `perlbrew help <command>` for detail description of the command.

インストール可能な Perl のバージョンを表示


$ perlbrew available
  perl-5.21.10
  perl-5.20.2
  perl-5.18.4
  perl-5.16.3
  perl-5.14.4
  perl-5.12.5
  perl-5.10.1
  perl-5.8.9
  perl-5.6.2
  perl5.005_04
  perl5.004_05
  perl5.003_07

バージョンを指定して Perl をインストール


$ perlbrew install perl-5.14.4

Perl のソースコードをダウンロードしてビルド&テストするのでけっこう時間がかかる。

ビルド&テストの状況を確認するにはログファイルをチェック。


$ tail -f ~/perl5/perlbrew/build.perl-5.14.4.log

テストに失敗 orz


Test Summary Report
-------------------
../ext/POSIX/t/posix.t                                          (Wstat: 0 Tests: 66 Failed: 0)
  TODO passed:   11
../lib/locale.t                                                 (Wstat: 0 Tests: 117 Failed: 1)
  Failed test:  99
Files=2090, Tests=455942, 686 wallclock secs (53.50 usr 10.93 sys + 378.96 cusr 53.32 csys = 496.71 CPU)
Result: FAIL
make: *** [test_harness] Error 1

テストに失敗しても、インストールは可能なので、インストールしてしまう。


$ cd /Users/alice/perl5/perlbrew/build/perl-5.14.4; make install

インストール済みの Perl のバージョン一覧を表示。


$ perlbrew list
  perl-5.14.4

バージョン 5.14.4 を使うように設定。


$ perlbrew switch 5.14.4

perl コマンドでバージョンを確認したら、ちゃんと 5.14.4 になってた。


$ perl -v

This is perl 5, version 14, subversion 4 (v5.14.4) built for darwin-2level
(with 1 registered patch, see perl -V for more detail)
(以下略)

hello, world で動作確認

サンプルコード。モジュールも使えるかどうかチェック。


$ cat ./hello.pl 
use Time::HiRes;
print "hello, world\n";
print "version + patchlevel / 1000: $]\n";
print "revision, version, subversion: $^V\n";
Time::HiRes::sleep(2.5);

実行結果。ちゃんと動いた。


$ perl ./hello.pl 
hello, world
version + patchlevel / 1000: 5.014004
revision, version, subversion: v5.14.4

参考資料

tags: perl

Posted by NI-Lab. (@nilab)