How to Install Perl Modules on Mac OS X in 4 Easy Steps
Today at work, I learned how to install Perl modules using CPAN. It’s a lot easier than I thought.
You see, for the past couple of years, I’ve been a bit frustrated because OS X does not come with a whole lot of Perl modules pre-installed, and for all I googled, I couldn’t find an “idiot’s” guide for moderately-savvy-but-not-expert users like myself to install modules and dependencies on demand.
The only instructions I could find point to Fink, which basically installs modules in a path that isn’t included in the Perl @INC variable, meaning you have to manually specify the full path to the modules in every script — which is not a lot of fun if you’re developing on OS X and deploying on Red Hat, for instance.
Moreover, Fink doesn’t seem to make every module available, and it’s not very easy to determine which Fink package you need to install if you need a particular module.
So, with a script that called on several apparently unavailable modules, and a deadline looming, I finally decided to suck it up and figure out how to use CPAN to install them:
If you don’t have this stuff installed, your installation will fail with errors about unavailable commands.
Older versions of XCode installed the command line tools (which are required to properly install CPAN modules) by default, but apparently newer ones do not. To check whether you have the command line tools already installed, run the following from the Terminal:
This command checks the system for the “
This will prompt you for some settings. You can accept the defaults for almost everything (just hit “return”). The two things you must fill in are the path to
If you skip Step 2, you may get errors about
Don’t forget the
This will spend a long time downloading, testing, and compiling various files and dependencies. Bear with it. It will prompt you a few times about dependencies. You probably want to enter “yes”. I agreed to everything it asked me, and everything turned out fine. YMMV of course. If everything installs properly, it’ll give you an “OK” at the end.
or
This will install the module and its dependencies. Nice, eh? Again, don’t forget the
The first time you run this after upgrading CPAN, it may prompt you to configure again (see Step 2). If you accept its offer to try to configure itself automatically, it may just run through everything without a problem.
There are a couple of potential pitfalls with specific modules (such as the
And that’s it!
Did you find this useful? Is there anything I missed?
You see, for the past couple of years, I’ve been a bit frustrated because OS X does not come with a whole lot of Perl modules pre-installed, and for all I googled, I couldn’t find an “idiot’s” guide for moderately-savvy-but-not-expert users like myself to install modules and dependencies on demand.
The only instructions I could find point to Fink, which basically installs modules in a path that isn’t included in the Perl @INC variable, meaning you have to manually specify the full path to the modules in every script — which is not a lot of fun if you’re developing on OS X and deploying on Red Hat, for instance.
Moreover, Fink doesn’t seem to make every module available, and it’s not very easy to determine which Fink package you need to install if you need a particular module.
So, with a script that called on several apparently unavailable modules, and a deadline looming, I finally decided to suck it up and figure out how to use CPAN to install them:
1) Make sure you have the Apple Developer Tools (XCode) installed.
These are on one of your install discs, or available as a huge but free download from the Apple Developer Connection [free registration required] or the Mac App Store. I thought I had them, but apparently when we upgraded that computer to Tiger, they went missing.If you don’t have this stuff installed, your installation will fail with errors about unavailable commands.
1.5) Install Command Line Tools (Recent XCode versions only)
(Thank you to Tom Marchioro for informing me about this step.)Older versions of XCode installed the command line tools (which are required to properly install CPAN modules) by default, but apparently newer ones do not. To check whether you have the command line tools already installed, run the following from the Terminal:
$ which make
This command checks the system for the “
make
” tool. If it spits out something like /usr/bin/make
you’re golden and can skip ahead to Step 2. If you just get a new prompt and no output, you’ll need to install the tools:- Launch XCode and bring up the Preferences panel.
- Click on the Downloads tab
- Click to install the Command Line Tools
which make
again to confirm that everything’s installed correctly.2) Configure CPAN.
$ sudo perl -MCPAN -e shell
perl> o conf init
This will prompt you for some settings. You can accept the defaults for almost everything (just hit “return”). The two things you must fill in are the path to
make
(which should be /usr/bin/make
or the value returned when you run which make
from the command line) and your choice of CPAN mirrors (which you
actually choose don’t really matter, but it won’t let you finish until
you select at least one). If you use a proxy or a very restrictive
firewall, you may have to configure those settings as well.If you skip Step 2, you may get errors about
make
being unavailable.3) Upgrade CPAN
$ sudo perl -MCPAN -e 'install Bundle::CPAN'
Don’t forget the
sudo
, or it’ll fail with permissions errors, probably when doing something relatively unimportant like installing man
files.This will spend a long time downloading, testing, and compiling various files and dependencies. Bear with it. It will prompt you a few times about dependencies. You probably want to enter “yes”. I agreed to everything it asked me, and everything turned out fine. YMMV of course. If everything installs properly, it’ll give you an “OK” at the end.
4) Install your modules. For each module….
$ sudo perl -MCPAN -e 'install Bundle::Name'
or
$ sudo perl -MCPAN -e 'install Module::Name'
This will install the module and its dependencies. Nice, eh? Again, don’t forget the
sudo
.The first time you run this after upgrading CPAN, it may prompt you to configure again (see Step 2). If you accept its offer to try to configure itself automatically, it may just run through everything without a problem.
There are a couple of potential pitfalls with specific modules (such as the
LWP::UserAgent
/ HEAD
issue), but most have workarounds, and I haven’t run into anything that wasn’t easily recoverable.And that’s it!
Did you find this useful? Is there anything I missed?
Post a Comment
Your email is never published nor shared. Required fields are marked *
Comments may be held for moderation to prevent spam: your comment may not appear immediately.
COMMENT: by Ken, January 15th, 2008
similarly, i bet it would be also helpful for some people to see how to install perl packages with FC8 using yum…say you want to install the Perl Frontier::Client package (and its dependencies)…
$ su root
# yum -y install perl-Frontier-RPC
…all you do is append a ‘perl-’ to the package name and substitute the ‘::’ for a ‘-’ and you should be all set…
COMMENT: by Alex, March 14th, 2008
COMMENT: by jpd, March 14th, 2008
Hope that helps
COMMENT: by Noemi Millman, March 16th, 2008
COMMENT: by Albert, March 18th, 2008
COMMENT: by Michele, July 7th, 2008
COMMENT: by Phoenix2Life, September 26th, 2008
COMMENT: by nobighair, January 14th, 2009
I had a list of modules to install. Plus there were a couple I needed to force install. So I found it easier to split it up:
> sudo perl -MCPAN -eshell
To get the CPAN shell. Then in the shell:
> install XML::Writer
or
> force install XML::Writer
Cheers
COMMENT: by Guizard Sébastien, May 5th, 2009
I had stop the process at the step 2 when you have to enter the adress of the miror cpan(for searching this adress).
Now, when I restart the command, it don’t ask me for the Cpan miror and the command make was not created. What can I do ? It’s my first macbook, I’ve bought it 3 day ago. I don’t know what can I do ! i’m thinking to re instal Mac OS X. I don’t it’s good idea ! if you can help me I will be very glad ! ! !
PS : I’m sory if my english is not very good, I’m learning right now in USA ^^
COMMENT: by Noemi Millman, May 6th, 2009
COMMENT: by Mac, June 20th, 2009
COMMENT: by Noemi Millman, June 23rd, 2009
COMMENT: by Nick, July 30th, 2009
COMMENT: by Simon, November 17th, 2009
COMMENT: by nod, January 4th, 2010
COMMENT: by Christian, June 8th, 2010
I followed these instructions and everything went well until I tried to install a module. Maybe I just misread the post, but instead of ‘install Module::Name’ I had to use ‘install Name’
COMMENT: by Noemi Millman, June 8th, 2010
COMMENT: by Christian, June 8th, 2010
COMMENT: by JM, August 31st, 2010
Like Christian though, I only had to use “sudo cpan ModuleName” at the Terminal prompt to install most of them. I think there was only one where I had to prefix the command with “Bundle::”.
This is on a 27″ iMac running Snow Leopard 10.6.4.
I also installed them on a ten-year-old G4 mini-tower running Tiger.
YMMV
Thanks again!
COMMENT: by Pierre, January 10th, 2011
COMMENT: by Dan, May 20th, 2011
COMMENT: by Richard Uschold, July 17th, 2011
I still get the error: “Can’t locate SOAP/Lite.pm in @INC (…)”
COMMENT: by Richard Uschold, July 17th, 2011
All is good, now!
COMMENT: by Noemi Millman, July 18th, 2011
COMMENT: by bert, November 4th, 2011
GAAS/libwww-perl-6.03.tar.gz
/usr/bin/make install — NOT OK
—-
You may have to su to root to install the package
(Or you may want to run something like
o conf make_install_make_command ‘sudo make’
to raise your permissions.Warning (usually harmless): ‘YAML’ not installed, will not store persistent state
COMMENT: by Noemi Millman, November 4th, 2011
COMMENT: by bert, November 6th, 2011
COMMENT: by Mandy, July 5th, 2012
COMMENT: by Cliff, July 9th, 2012
COMMENT: by John Wooten, Ph.D., July 10th, 2012
Has anyone installed PDL on OS X Lion 10.7.4? If so, how?
COMMENT: by Tom Marchioro, July 23rd, 2012
Really clear and useful instructions. You should be proud (and I’m an Eli of an age who doesn’t easily praise a Tiger
BUT, as John Wooten notes, the instructions need a slight updating for the current state of Appledom. I doubt this is Lion specififc, but the new XCode has turned into a standalone app that does NOT come with the standard command line tools by default, so your instructions should now be:
1. Make sure you have the Apple Developer Tools Installed.
2. Launch XCode and bring up the Preferences panel.
3. Click on the Downloads tab and then click to install the Command Line Tools (otherwise CPAN cannot access a working version of make).
After that I think Noemi’s instructions work perfectly (at least for DBI and LWP). thanks!
Hope this helps — tom
COMMENT: by Noemi Millman, July 23rd, 2012
COMMENT: by laura, July 30th, 2012
sudo perl -MCPAN -e ‘install Bundle::Name’
becomes this:
sudo env FTP_PASSIVE=1 perl -MCPAN -e ‘install Bundle::Name’
(tip found at http://hints.macworld.com/article.php?story=20090716132354455)
laura
COMMENT: by Noemi Millman, July 31st, 2012
COMMENT: by John, August 10th, 2012
COMMENT: by Anarcissiea, August 24th, 2012
COMMENT: by vogen, September 1st, 2012
Just installed Module Prima
Thanks heaps
COMMENT: by Avita, November 20th, 2012
COMMENT: by Bretfort, January 1st, 2013
COMMENT: by Ezmyrelda, March 5th, 2013
COMMENT: by Collin Dyer, May 13th, 2013
COMMENT: by Perl on Mac | BnafetS, May 27th, 2013
COMMENT: by Gaelle, June 26th, 2013
COMMENT: by Susanne, July 8th, 2013
COMMENT: by Ryan, July 21st, 2013
COMMENT: by Jack, November 8th, 2013
COMMENT: by Anonymous, December 17th, 2013
“t/lock.t …………… 1/4″
It’s been stuck on that for about 20 minutes now. Is this normal?
COMMENT: by Anonymous, December 17th, 2013
COMMENT: by Flo, June 18th, 2014