Installing Local Perl And Libraries On Mac Book Snow Leopard
I recently installed Perl 5.14 on a new Mac Book running Snow Leopard so I thought I'd share my findings and experiences to save the next person doing this some time.
I started off by doing a search on Google for "install perl mac".
Hit number 1: Download Perl - www.perl.org http://www.perl.org/get.html
That suggests you have a perl already installed, which is currently perl 5.10, or you can use App::Perlbrew.
It wasn't quite that easy so I've documented below exactly what I did. I've given feedback to Leo Laporte who looks after http://xrl.us/installperlosx and who should be updating the instructions on the perl.org page. At that point something like "curl -L http://xrl.us/installperlosx | bash" will work.
If you use a package manager directly, you'll find today (June 8th 2011) that macports offers you perl 5.12 and homebrew assumes you want to use your system perl, i.e. perl 5.10. The trouble with macports (or homebrew) is that they will fight over using /usr/local to store your local perl and you are better off installing it below your home directory using perlbrew.
Assuming you want perl 5.14, read on...
A. Install local perl and libraries
1. Install Mac C compiler by installing XCode 4
You can either install it from your install disks or buy it from the Mac online App Store.
There is a problem with XCode 4 that will stop PathTools building when installing perlbrew, see the problem described at
$ echo 'export ARCHFLAGS="-arch i386"' >> ~/.bash_login
$ export ARCHFLAGS="-arch i386"
2. Bootstrap local::lib for Perl local library support
download local::lib from http://search.cpan.org/CPAN/authors/id/A/AP/APEIRON/local-lib-1.008004.tar.gz
$ tar xfz local-lib-1.008004.tar.gz
$ cd local-lib-1.008004
$ perl Makefile.PL --bootstrap=~/perl_local1
$ make test
$ make install
$ echo 'eval $(perl -I$HOME/perl_local1/lib/perl5 -Mlocal::lib=$HOME/perl_local1' >> ~/.bash_login
set up environment for local build
$ . ~/.bash_login
That has you configured to install all your CPAN modules below ~/perl_local1.
Later if you want to have a different local::lib for different perl versions or different apps you can easily enough change your setup like above.
3. Install App::cpanminus for easier CPAN module installation
$ cpan App::cpanminus
4. Install App::perlbrew for easier local Perl version binary building
$ cpanm App::perlbrew
$ perlbrew init
$ echo 'source ~/perl5/perlbrew/etc/bashrc' >> ~/.bash_login
$ source ~/perl5/perlbrew/etc/bashrc
$ perlbrew available
5. Install a local perl 5.14 and start using it
$ perlbrew install perl-5.14.0
(wait 30 minutes)
$ perlbrew use perl-5.14.0
$ perl -v
(should report that you are running perl 5.14)
B. Install "homebrew" package manager
1. Install XCode 4 (already done above)
2. Install Java developer update
3. Install homebrew
$ ruby -e "$(curl -fsSLk https://gist.github.com/raw/323731/install_homebrew.rb)"
$ brew install git
$ brew update
Now you can install or build packages using the "brew" command.
An alternative is macports http://www.macports.org