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
http://stackoverflow.com/questions/5256397/python-easy-install-fails-with-assembler-for-architecture-ppc-not-installed-on

To fix:
$ 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
perl-5.14.0
perl-5.12.3
perl-5.10.1
perl-5.8.9
perl-5.6.2
perl5.005_04
perl5.004_05
perl5.003_07

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

http://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wa/getSoftware?bundleID=20719

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

3 Comments

This seems to be a lot harder than just doing it the conventional way. Download, run Configure to give each perl their own installation directory, run install, and use the bundled cpan to install modules.

Hi Peter,

It's actually Leo Lapworth :)

curl -L http://xrl.us/installperlosx | bash

Should now do all of that (other than homebrew)...

https://github.com/ranguard/installing-perl/blob/master/scripts/install_perl_on_osx.sh

Is the actual code, there are some differences (like you don't need local::lib when using perlbrew as cpanm will then install into the right perlbrew/version directory), but it should end up with the same result.

Leave a comment

About Peter Edwards

user-pic Freelance Perl contractor.