Skip to content

Installing Local Perl Modules with CPAN

CPAN is a convenient way to build and install perl modules, but many people have difficulty knowing how to do this if they lack "root" permissions.  This tutorial will demonstrate how to install Perl modules to a local user space using CPAN.

Procedure

First start the CPAN shell:

1
2
3
4
5
6
7
8
9
$ cpan

Terminal does not support AddHistory.

cpan shell -- CPAN exploration and modules installation (v1.9402)

Enter 'h' for help.

cpan[1]>

Next determine where you want to install your local Perl modules. Let's assume we are going to place them in: /mnt/home/myUid/perlmods

Now from within the CPAN shell, enter the following three (3) commands:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
cpan[1]> o conf mbuildpl_arg "--install_base /mnt/home/myUid/perlmods"

     mbuildpl_arg       [--install_base /mnt/home/myUid/perlmods]

   Please use 'o conf commit' to make the config permanent!


cpan[2]> o conf makepl_arg "PREFIX=/mnt/home/myUid/perlmods"

    makepl_arg         [PREFIX=/mnt/home/myUid/perlmods]

  Please use 'o conf commit' to make the config permanent!


cpan[3]> o conf prefs_dir "/mnt/home/myUid/.cpan/prefs"

    prefs_dir          [/mnt/home/myUid/.cpan/prefs]

  Please use 'o conf commit' to make the config permanent!

If you want to make the settings above permanent, enter "o conf commit".  Otherwise, bear in-mind you will need to reset this value every time you restart CPAN. If you do make the setting permanent, you can always change it later and re-commit as shown above.

Now to install a module (lets assume we want to build "Math::GMP") simply enter:

1
cpan[4]> install Math::GMP

Respond to any prompts for information that might be requested. When you are finished, enter:

1
cpan[5]> quit

Setting the PERL5LIB Path

Now that you've successfully installed a local Perl module, you will need to tell Perl where to find them.  This can be easily accomplished by setting the environmental path variable "PERL5LIB". For example:

1
$ export PERL5LIB=/mnt/home/myUid/perlmods:$PERL5LIB

You can add this export to your .bashrc file if you'd like to ensure it is always loaded upon login. In addition, for any scripts that you write that utilize these local Perl modules that you run on the HPCC cluster, you should add this export statement to your job script, or create a custom user module that does that for you, and which can be loaded from within your job script.