Problems installing Perl modules

When a program requires a module that is not installed on the system, you may get an error similar to the following:

Can't locate XYZ.pm in @INC (you may need to install the XYZ module) (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5) at -e line 1.

or

Warining: XYZ module in Perl is missing

There are 2 methods of installing modules under Perl, using a Conda environment (preferred) or locally to your user.

Conda (Preferred)

To get the perl modules installed, a Conda environment can be created with Perl installed within it using the following steps.

srun -p epyc -t 12:00:00 -c 4 --mem=4G --pty bash -l  # Conda can be compute heavy, so run on a compute node
conda create -n perl_env -c conda-forge perl  # Create a conda environment called "perl_env"
conda activate perl_env

At this point, running which cpan should return a path ending similar to:
..../.conda/envs/perl_env/bin/cpan

It should not return /usr/bin/cpan. If it does then please review your steps for setting up the conda environment and make sure it is activated.

With the environment activated, you use cpan to install packages, for example to install “SVG”:

cpan install SVG

In your batch scripts, or when running future Perl commands, make sure that you include conda activate perl_env to properly load the environment.

Local

If for whatever reason you prefer to install the module(s) locally to your user, then the following steps will apply. Note that updates to our cluster install of Perl could cause locally-installed modules to break, which is why the Conda method above is preferred.

In this example, we will install the Math::Round module.

  1. To install Math::Round you can run cpan Math::Round.
  2. If this is your first time installing a Perl module, then you might be asked some questions -
  3. If/when asked if you would “like to configure as much as possible”, answer “yes”
  4. If/when asked “what approach do you want”, answer “local::lib”
  5. If/when asked if you “would like me to append that to /rhome/…/.bashrc”, answer “yes”.
  6. At this point the installation should complete without any more inputs.

Because your .bashrc file has been modified, you will need to log out and back in for the changes to apply. After logging back in, the installed module should be available within Perl.