User Installed Software - Perl/CPAN

Perl/CPAN

Installing Perl/CPAN software in your user account

CPAN is the place and tool to install Perl modules. The problem is that CPAN likes to install stuff where normal users don't have permissions to write, so we have to configure CPAN to use other directories.

Installing

First we decide where to have the CPAN modules installed. Let's assume that we want to install them under ~/Public/perl. Any place can do, but it is best if you have it under ~/Public if you want to use them from batch jobs.

Then add these lines to your ~/.bashrc:

export PERL5LIB=$HOME/Public/lib/perl5
export PATH="$HOME/Public/bin:$PATH"

If you choose to install under ~/Public directly, you can skip setting the PATH. If you have already set PERL5LIB you will have to modify the line appropriately.

Be aware that cpan will overwrite anything under bin, lib, and man under your install directory.

Run and configure

Next we have to run and configure cpan. To run cpan, you use the command cpan (or you could use perl -MCPAN -e shell).

If this is the first time you run cpan, cpan will ask if you want it to configure things automatically. Just let it do it. If you have already run it, and wants a fresh start, you can either remove ~/.cpan/CPAN/MyConfig.pm or (from within cpan) run 'o conf init'.

Assuming the initial run has been done, we need to set some configuration variables. The first two controls where things get installed and the third one makes it ask less questions for dependencies. The last one is not an option, it just saves your configuration.

o conf makepl_arg INSTALL_BASE=~/Public/perl
o conf mbuildpl_arg "--install_base ~/Public/perl"
o conf prerequisites_policy follow
o conf commit

(Note: the o is part of the command and not a bullet point.)

You can now quit cpan.

From now on the actual installation of a CPAN module will be quite easy, just use:

cpan -i module

There might be some questions asked but you can usually just press return on all of them.

Updated: 2024-10-10, 12:39