Setting up the Perl CPAN module installer

October 11th, 2007    2 Comments

perl -MCPAN -e 'install Collection::Module'

is the standard way of installing Perl modules.

The first time you run this you get asked lots of questions. For most of these you can just hit Enter to accept the default. However, you must tell it where to find the modules - i.e. the name of a CPAN mirror site. You can add several, one after the other, so that, if the first one fails, it just tries the next one in the urllist.

You can find a list of URLs at:

http://www.cpan.org/SITES.html

Now common sense might tell you that all you need to do is copy the URL for one of the FTP sites, paste it in and Bob's your uncle. Not so, in some cases, however, because if you're sitting behind a firewall that's fussy about what it allows to be passed via FTP, then you'll have to choose an HTTP URL rather than one of the FTP ones.

If you've already added URLs and got failure messages when you try to install modules, try adding an HTTP one as your first choice site. To do this, go to the CPAN command prompt:

perl -MCPAN -eshell

Once there enter:

o conf

to list your configuration settings. You'll see your urllist. Now enter:

o conf urllist unshift HTTP-URL

This sticks the URL at the top of the list. Depending on the age of your CPAN module and the way it's been set up, you may now have to do:

o conf commit

to make the change permanent, otherwise it will only last for the duration of the interactive session.

Now try installing the module again using:

install Collection::Module

To quit out of the CPAN shell enter:

quit

And if installing using the CPAN installer still fails, you can always just download the package from CPAN and install it manually using the instructions I described recently.

However, if you're somewhere where there's no access to the internet - or the server is locked down to prevent anything being installed from a remote source - you're going to have to use a copy of CPAN that you've downloaded previously onto a DVD or a thumb drive. For more on this have a listen to the Perlcast episode Making My Own CPAN by Brian D Foy.

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

Comments

  1. User Gravatar brian d foy said:

    August 25th, 2008 at 1:14 pm (#)

    It's easier just to use the cpan command that comes with Perl. Just tell it which modules you want to install:

    % cpan Foo::Bar Baz::Quux

    If you need to force install something, perhaps because a module fails its tests, use the -f switch:

    % cpan -f -i Foo::Bar Baz::Quux

  2. User Gravatar ac said:

    August 25th, 2008 at 9:46 pm (#)

    Thanks Brian, but that seems way too easy!
    :-)

    Alistair

Leave a comment