LoginSignup
0
0

More than 1 year has passed since last update.

最新の Perl を Mac にインストールする方法

Last updated at Posted at 2021-01-31

M2 MacBook Pro1 にプリインストールされている Perl のバージョンは、以下の通りで、

% perl -v

This is perl 5, version 30, subversion 3 (v5.30.3) built for darwin-thread-multi-2level
(with 2 registered patches, see perl -V for more detail)

Copyright 1987-2020, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

より最新の Perl を使いたいという人は、かなりの少数派かもしれませんが、

個人的には、これまで Ruby と Python について、以下のような記事を書いてきたということもあり、

一応、Perl についても、同様に最新のものを使えるようにしておきたいと思い、本記事もリライトしてみました。

次のコマンドを実行し、Homebrew で管理できるようにしておけば、

% brew install perl

以後、バージョンを上げる際には、次のようなコマンドを実行するだけで、簡単にアップグレードできます。

% brew upgrade perl

Homebrew のインストールについては、公式サイトを参照してください。

https://brew.sh/

今回、利用した Homebrew のバージョンは、以下の通りです。

% brew --version
Homebrew 4.0.16
Homebrew/homebrew-core (git revision 15bc37bb1ce; last commit 2023-02-17)
Homebrew/homebrew-cask (git revision b17568b22a; last commit 2023-02-17)

ちなみに、次のコマンドを実行すれば、Homebrew 自体をアップデートできます。

% brew update

Ruby をインストールした時と同じように、次のコマンドを実行するなどして、PATH を通すこともお忘れなく。

% echo 'export PATH="/opt/homebrew/opt/perl/bin:$PATH"' >> ~/.zshrc

これで、ターミナルを再起動するか、新しいウィンドウを開くか、あるいは、次のコマンドを実行するなどして、設定を更新すれば、

% source ~/.zshrc

新しいバージョンの Perl が、利用できるようになっているはずです。

% perl -v        

This is perl 5, version 36, subversion 0 (v5.36.0) built for darwin-thread-multi-2level

Copyright 1987-2022, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at https://www.perl.org/, the Perl Home Page.

インストール時の出力には、以下のような( モジュールのインストール先の )設定についても書かれていたので、念の為、ここにメモしておきます。

By default non-brewed cpan modules are installed to the Cellar. If you wish
for your modules to persist across updates we recommend using `local::lib`.

You can set that up like this:
  PERL_MM_OPT="INSTALL_BASE=$HOME/perl5" cpan local::lib
And add the following to your shell profile e.g. ~/.profile or ~/.zshrc
  eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib=$HOME/perl5)"
  1. MacBook Pro (14-inch, 2023)・macOS Ventura 13.3.1

0
0
3

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
0
0