Skip to content

Install perl libraries

This guide explains how to install Perl modules in a non-system location (e.g., project or group directory) using cpanm and local::lib. This is ideal for environments where you cannot modify system Perl without root access, such as on RCAC clusters (Gautschi, Negishi, Bell).

  1. Create the required directory in your desired location (e.g., home or project space).

    mkdir -p /depot/gcore/localperl
    cd /depot/gcore/localperl

    You can substitute this path to any location you want (~ or even $SCRATCH) .

  2. Set up the environment to install Perl modules locally:

    nano /depot/gcore/localperl/env.sh

    Paste the following into env.sh:

    env.sh
    export PERL_LOCAL_LIB_ROOT=/depot/gcore/localperl
    export PERL_MB_OPT="--install_base /depot/gcore/localperl"
    export PERL_MM_OPT="INSTALL_BASE=/depot/gcore/localperl"
    export PERL5LIB=/depot/gcore/localperl/lib/perl5:$PERL5LIB
    export PATH=/depot/gcore/localperl/bin:$PATH

    Then activate it:

    source /depot/gcore/localperl/env.sh
  3. Install cpanm (Perl module installer) into the custom location:

    curl -L https://cpanmin.us | perl - --local-lib=/depot/gcore/localperl App::cpanminus

    Confirm that it worked:

    which cpanm
    # should return: /depot/gcore/localperl/bin/cpanm
  4. Install the required Perl modules:

    cpanm DateTime namespace::autoclean Sub::Name \
    JSON Getopt::Long Pod::Usage JSON::XS Mojolicious

    You can add more modules as needed.

  5. (Optional) Automatically load your environment in future sessions:

    echo 'source /depot/gcore/localperl/env.sh' >> ~/.bashrc

    If you prefer not to modify your ~/.bashrc, you can manually source the environment script each time you start a new session.

To verify that the installation was successful, you can run a simple Perl script that uses one of the installed modules:

test_perl_modules.pl
#!/usr/bin/perl
use strict;
use warnings;
use DateTime;
use JSON;
print "Local Perl modules are working!\n";

Run the script:

perl test_perl_modules.pl

If you see the message “Local Perl modules are working!”, your installation is successful.

1. How can I get a list of all installed perl modules? [click to see answer]

You can use the following command to list all installed Perl modules:

perldoc perllocal

or

find /depot/gcore/localperl/lib/perl5 -name '*.pm'