Pages

Thursday, October 25, 2012

Fix Perl CPAN on OS X Mountain Lion

I regularly develop automation tools with the VMware SDK for Perl on my Macbook Pro.  However, with the latest versions of OS X, including Mountain Lion, I've found the default install of CPAN is unable to download modules after automatically generating a list of mirror sites.

The issue is the result of a bad list of mirror sites generated by CPAN's automatic configuration.

Note:  If you haven't already done so, you'll need the Xcode Command Line Tools so CPAN can build Perl modules with make.  Xcode is free via the AppStore.  Once installed, be sure to run Xcode, open Preferences, select Downloads and install the Command Line Tools.

Install XCode Command Line Tools

When invoking the CPAN shell for the first time, it will prompt to do an automatic configuration of your mirror list by default.  After automatic configuration is complete, try to install a module.  Typically the first one I attempt to install is Crypt::SSLeay.  Every mirror site will error out with Not Connected and Bad luck... Still failed!.

sudo perl -MCPAN -e shell
cpan[1]> install Crypt::SSLeay

Bad Luck... Still failed!

The solution is to update the URL mirror list for the CPAN configuration, then update the CPAN bundle.  In this example, I use unshift to insert http://www.cpan.org into the first position of the URL list for the CPAN configuration, update CPAN, and generate a new (and working) list of CPAN mirror sites.

sudo perl -MCPAN -e shell
cpan[1]> o conf urllist unshift http://www.cpan.org
cpan[2]> o conf commit
cpan[3]> install Bundle::CPAN
# CPAN install may take a while...
cpan[4]> reload cpan
cpan[5]> o conf init urllist
cpan[6]> o conf commit
cpan[7]> install Crypt::SSLeay

Now that CPAN is working properly, just be sure to use sudo when calling the CPAN shell so new modules can be placed in the System Perl library path.

6 comments:

  1. I really like using cpanm
    Install it with
    #cpan App::cpanminus

    Now install any module you can find.
    cpanm Module::Name

    ReplyDelete
  2. Just tried cpanm, pretty nice. Have to add that to my toolbox!

    ReplyDelete
  3. Thanks for this page. I don't know why Apple just doesn't keep a configured Perl working in there. Invariably, I'll need to write a quick and dirty Perl script to do something to an .ICS file or CSV file or somewhat, and I hate reinventing the wheel.

    Thanks again!

    ReplyDelete
  4. Thanks for this useful tip - question though: with previous versions of OS X, it was generally a bad idea to mess with the system's perl installation. Is this no longer an issue with 10.8 Mountain Lion?

    ReplyDelete
  5. Honestly don't know. Never ran into any issues in my experience.

    ReplyDelete
  6. Thank you for the excellent content I did experienced studying it, I will be sure to save your website and definitely will come returning from again. I want to motivate that you proceed your excellent job, have a excellent day. striped bass fishing tips

    ReplyDelete