Configuring CPAN


Introduction

I've been working with perl since 1994 and it's easily my favorite language, despite all its actual and perceived faults. One of my favorite aspects of perl and Perl Culture is the scope and depth of contributed code and the ease of installing and updating it. The primary tool used to maintain a local perl distribution is the CPAN module, used to access the Comprehensive Perl Archive Network aka CPAN.

For all its power and utility, the CPAN module has suffered from some significant flaws. Additionally, some vendors (named below) persist in shipping versions of perl that cannot make use of most of CPAN's power. This document is intended to help unix administrators (especially Solaris administrators) configure their systems to use CPAN.

Read All This Before Starting

This article is short. Read it first before doing anything. Then back up everything you care about and read about the tools you don't understand (h2ph, for example.)

Manually Upgrade CPAN.pm

Before installing anything (else), manually upgrade CPAN.pm to the most recent version. Download the tarball from cpan.org, unpack, and install as any other perl module (perl Makefile.PL; make; make test; make install).

Do not use CPAN to install CPAN.pm. CPAN.pm versions 1.48 and earlier do not ask permission before upgrading core perl when installing modules that are now maintained as part of core perl (Data::Dumper, File::Spec, etc.) For this reason, it's important to install a recent version of CPAN.pm and configure it to ask permission before installing prerequisites, e.g.:

# perl -MCPAN -e shell
cpan> o conf prerequisites_policy ask
cpan> o conf commit
cpan> quit

You can also do this when you initialize CPAN for the first time.

Set CPAN to Uninstall Old Modules

Set CPAN to uninstall old modules when conflicts occur with

# perl -MCPAN -e shell
cpan> o conf make_install_arg   UNINST=1
cpan> o conf commit
cpan> quit

You can also do this when you initialize CPAN for the first time:

# perl -MCPAN -e shell
cpan> o conf init
<<a whole lotta questions later...>>
cpan> quit

Source Tarballs of CPAN Modules Are Hidden Nearby

CPAN stores downloaded modules under $HOME/.cpan/sources/authors/id/Z/ZZ/ZZZ... so if you have trouble installing modules automatically, you can find fresh sources here.

Solaris Users Have Even More Fun

Solaris 8 users: I feel your pain. You have two choices with regards to CPAN:

  1. Scrape out the heinously borked version of perl 5.005_03 that Sun supplies you and install a new (5.6.1 or later) clean copy from source so that all the files go in the right places (Hint: /usr/perl5/bin is where vital utilities like h2xs, h2ph, perldoc, and find2perl live. Paraphrasing Dave Barry, "Who installed this code? Vandals?") Also, make sure the C compiler you build perl with is available after installation (see below.) The simple low-budget solution: install gcc.
  2. Presuming you don't have Sun's C compiler (and who does?), install gcc. Save a backup copy of /usr/perl5/5.00503/sun4-solaris/Config.pm and in the original, replace references to cc with gcc, being careful to change the values of 'optimize' and 'cccdlflags' to reflect the appropriate gcc options ('-KPIC' -> '-fPIC', '-xO3 -xdepend' -> '-O3').

/usr/perl5/5.00503/sun4-solaris/Config.pm 'remembers' how perl was built and is used by CPAN (via MakeMaker) to build makefiles to install modules. You can change some of the options in CPAN to convince it to use gcc instead of Sun's hypothetical compiler but it's often much cleaner to erase cc from Config.pm or just install a recent version of perl from scratch. I don't have many comments about the Solaris packages of perl on sunfreeware.com or sunsite/ibiblio; I've had good results with packages from both archives but I simply don't trust anyone's package of perl, especially when Sun is involved.

Perl 5.6.0 Has Issues - Upgrade.

Perl 5.6.0 is a troubled version. If feasible, upgrade to 5.6.1 or later.

Don't Force-Install Packages Unless You Know What You're Doing (And Even Then...)

Rarely do I have to force-install a package. Tests generally fail for a reason and really, you should investigate the failed tests before forcing an installation, just to ensure the test results can be safely neglected. Some tests fail if they're run as root. Common problems are missing library paths (requiring LD_LIBRARY_PATH and LD_RUN_PATH to be specified) and missing or outdated .ph files (perl-massaged include files for system libraries.) Update the .ph files with:

cd /usr/include; h2ph -r -l .

You should only need to do this once, or whenever you update the contents of /usr/include. See the h2ph manpage for details (Solaris users should use

'/usr/perl5/bin/perldoc /usr/perl5/bin/h2ph'

instead...)

Finally...

Smile. Have fun. Use this an opportunity to learn. Write some code or documentation and share it with the rest of us.


$Id$