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).
-
Create the required directory in your desired location (e.g., home or project space).
mkdir -p /depot/gcore/localperlcd /depot/gcore/localperlYou can substitute this path to any location you want (
~
or even$SCRATCH
) . -
Set up the environment to install Perl modules locally:
nano /depot/gcore/localperl/env.shPaste the following into
env.sh
:env.sh export PERL_LOCAL_LIB_ROOT=/depot/gcore/localperlexport PERL_MB_OPT="--install_base /depot/gcore/localperl"export PERL_MM_OPT="INSTALL_BASE=/depot/gcore/localperl"export PERL5LIB=/depot/gcore/localperl/lib/perl5:$PERL5LIBexport PATH=/depot/gcore/localperl/bin:$PATHThen activate it:
source /depot/gcore/localperl/env.sh -
Install
cpanm
(Perl module installer) into the custom location:curl -L https://cpanmin.us | perl - --local-lib=/depot/gcore/localperl App::cpanminusConfirm that it worked:
which cpanm# should return: /depot/gcore/localperl/bin/cpanm -
Install the required Perl modules:
cpanm DateTime namespace::autoclean Sub::Name \JSON Getopt::Long Pod::Usage JSON::XS MojoliciousYou can add more modules as needed.
-
(Optional) Automatically load your environment in future sessions:
echo 'source /depot/gcore/localperl/env.sh' >> ~/.bashrcIf you prefer not to modify your
~/.bashrc
, you can manually source the environment script each time you start a new session.
Testing the installation
Section titled “Testing the installation”To verify that the installation was successful, you can run a simple Perl script that uses one of the installed modules:
#!/usr/bin/perluse 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'