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 -

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 and who should be updating the instructions on the page. At that point something like "curl -L | 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

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
$ 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"
$ brew install git
$ brew update

Now you can install or build packages using the "brew" command.

An alternative is macports


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

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

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.