Installing Perl applications and libraries¶
In this tutorial you will learn
- How to install cpanm
- How to install Perl modules with cpanm
Perl scripts and applications do not need installation. They can be simply
downloaded and run.
Roihu does not have a
perl module. A system Perl is available at
/usr/bin/perl, but it does not include cpanm or most common libraries.
Installing Perl modules¶
Sometimes applications may require additional modules to run.
- These "Perl modules" should not be confused with the software modules on CSC supercomputers.
You should check the installation instructions for each module. For
libraries in CPAN, the easiest method is to use
cpanm.
- You can check out the CPAN documentation here.
In this example, we'll add the Perl module JSON to our own environment¶
-
Check if JSON is already available:
- The error message indicates that it is not found, so you need to install it.
By default,
cpanmtries to install new modules to the Perl installation path, which will not work.- You need to set the location to a directory where you have write access.
It could be e.g. your project's
/projappldirectory. - This is accomplished by setting a few environment variables.
-
Set
PERL_BASEto the desired path and run the following:export PERL_BASE="/projappl/<project>/$USER/myperl" # replace <project> with your CSC project, e.g. project_2001234 export PERL_MM_OPT="INSTALL_BASE=$PERL_BASE" export PERL_MB_OPT="--install_base $PERL_BASE" export PERL5LIB="$PERL_BASE/lib/perl5" export PATH="$PERL_BASE/bin:$PATH" mkdir -p $PERL_BASE -
Install
cpanm(only needs to be done once): -
You can now install the module:
-
You can now try again:
- This time there's no error message, indicating that the JSON module is now available.
Additional info¶
The installation only needs to be done once, but you need to always ensure
Perl knows where to find the installed modules.
There are three main ways to do this (we used the second already).
Option 1¶
-
Pass the path using the command-line option
-I:
Option 2¶
-
Include the path in the
$PERL5LIBenvironment variable:
Option 3¶
-
Include the path in your Perl script with
use lib: