On Carbonate at IU, how do I install and manage Perl modules in my home directory?

On Carbonate at Indiana University, use the local::lib module and CPAN to install and manage your own library of Perl modules:

  1. Make a personal configuration for use with the CPAN module; on the command line, enter:
      perl -MCPAN -e 'mkmyconfig'
  2. When prompted, press Enter or Return to allow automatic configuration.
  3. For "What approach do you want?", press Enter or Return to select the default option ( local::lib).
  4. Press Enter or Return to let the application automatically choose CPAN mirror sites.
  5. Press Enter or Return to add the necessary environment variables to your shell configuration file.
  6. If prompted to run automatic configuration again, press Enter or Return to select [yes].

    You'll see output indicating autoconfiguration is complete, with MyConfig.pm written to the following directory (where username is your IU Network ID username, and cluster_name is Carbonate:

  7. When returned to the shell prompt, run the CPAN module; enter:
      perl -MCPAN -e shell
  8. Configure the CPAN module to install new modules in your home directory; at the first CPAN prompt (cpan[1]>), enter:
      o conf makepl_arg INSTALL_BASE=~/perl5

    You'll see the following output:

          makepl_arg         [INSTALL_BASE=~/perl5]
      Please use 'o conf commit' to make the config permanent!
  9. At the next CPAN prompt, enter:
      o conf commit

    You'll see the following output (where username is your IU username, and cluster_name is Carbonate:

      commit: wrote '/N/u/username/cluster_name/.cpan/CPAN/MyConfig.pm'
  10. At the next CPAN prompt, enter:
  11. Modify your environment to use the new library of modules:
    • If you're using the bash shell, add the following lines to your ~/.bashrc file (replace username with your IU username, and cluster_name with Carbonate):
        export PERL_MM_OPT="INSTALL_BASE=/N/u/username/cluster_name/perl5" 
        export PERL5LIB="/N/u/username/cluster_name/perl5/lib/perl5:$PERL5LIB" 
        export PATH="/N/u/username/cluster_name/perl5/bin:$PATH"
        eval $(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib) 
    • If you're using a variant of the C shell, you'll need to set the environment variables manually in your shell configuration file.
  12. Use the CPAN module (or the cpan command) to install modules locally:
      $ perl -MCPAN -Mlocal::lib -e 'CPAN::install(Math::Matrix)'

    This will produce a lot of output.

  13. In your Perl script, use the local::lib module to have your local library searched when modules are loaded:
      use strict;
      use local::lib;
      use Math::Matrix;

If you have a question about installing and managing Perl modules, or need help, email the UITS Scientific Applications and Performance Tuning (SciAPT) team.

This is document baiu in the Knowledge Base.
Last modified on 2017-11-20 15:36:45.

Contact us

For help or to comment, email the UITS Support Center.