edit · print · PDF

Please note that all the SIEpedia's articles address specific issues or questions raised by IAC users, so they do not attempt to be rigorous or exhaustive, and may or may not be useful or applicable in different or more general contexts.

Customizing Perl by adding your favourite modules.

If you use Perl at all, chances are that at some point you will like to add one of the hundreds of available modules for it. If you have a private installation, this is probably not an issue, but what about customizing the IAC-wide perl with your own favourite modules? In this HOWTO we show you how to easily do it by installing modules to your home directory.

Run and configure CPAN

  • You should start off by creating a directory where all modules will be installed, for example:
    [angelv@lubina ~]$ mkdir /home/angelv/perl-local
  • Then, we will run (and configure) the CPAN (Comprehensive Perl Archive Network) module, which will allow us to automatically install new Perl modules:
    [angelv@lubina ~]$ perl -MCPAN -e shell
  • Unless you know what you are doing, accept the defaults until you get to the question on ''parameters for the 'perl Makefile.PL' command". The question reads like this:
Every Makefile.PL is run by perl in a separate process. Likewise we 
run 'make' and 'make install' in processes. If you have any          
parameters (e.g. PREFIX, LIB, UNINST or the like) you want to pass  
to the calls, please specify them here. 

If you don't understand this question, just press ENTER.  

Parameters for the 'perl Makefile.PL' command?               

Typical frequently used settings:     

    PREFIX=~/perl       non-root users (please see manual for more hints)

Your choice:  [] PREFIX=/home/angelv/perl-local      

  • ... and you should specify the PREFIX attribute as stated above, obviously replacing /home/angelv/perl-local with the directory you have created to keep your modules.
  • Again, accept the defaults for the remaining questions, until you get to the question on selecting CPAN mirrors, which reads like this:
First, pick a nearby continent and country (you can pick several of     
each, separated by spaces, or none if you just want to keep your    
existing selections). Then, you will be presented with a list of URLs 
of CPAN mirrors in the countries you selected, along with previously 
selected URLs. Select some of those URLs, or just keep the old list.                  

Finally, you will be prompted for any extra URLs -- file:, ftp:, or
http: -- that host a CPAN mirror. 

  • ... follow the instructions and choose whaterver is closer to you. After this question, the configuration of CPAN will finish and you will end up in the CPAN prompt:
    cpan> quit
  • Issue the command quit in CPAN and back in your shell, define the variable PERL5LIB. Following the example, I would define it to be (make sure you adapt it to the directory you created):
    [angelv@lubina ~]$ setenv PERL5LIB /home/angelv/perl-local/lib/perl5/site_perl/5.8.5
  • If you want this change to stick for future sessions, make sure you put it in your .cshrc file or equivalent (if you are not sure how to do this, make sure you read our page on Environment Variables).
  • Now run CPAN again, and if you want to have an improved CPAN experience for the future, install the Bundle::CPAN bundle (this will take a while and you should accept the defaults when prompted):
    [angelv@lubina ~]$ perl -MCPAN -e shell
    cpan> install Bundle::CPAN

Installing PERL Module

  • So, now we are ready to actually install a module. Let's install, for example, the PGPLOT module, which allows subroutines in the PGPLOT graphics library to be called from Perl. To do it, we just issue the following commands:
    cpan> install PGPLOT
  • ... which at some point will complain with the error:
Can't locate ExtUtils/F77.pm in @INC (@INC contains: . 

  • Some modules will find and will ask you to automatically install all its dependencies, but not PGPLOT, so we have to do it manually. We can see that we need a module called something like "ExtUtils/F77.pm". In order to find the exact name of the module we can do (you can find other CPAN commands by issuing the command "help"):
    cpan> m /ExtUtils/
  • ... where one of the lines returned is:
Module          ExtUtils::F77   (K/KG/KGB/ExtUtils-F77-1.15.tar.gz)

  • ... so the exact name of the module is ExtUtils::F77, which we install:
    cpan> install ExtUtils::F77
  • If you now try to install PGPLOT again, it will complain, because the installation already started, but it couldn't finish properly, so it is convenient to perform first a clean, before retrying:
    cpan> clean PGPLOT
    cpan> install PGPLOT
    cpan> quit

Check installation

  • If all went well, the PGPLOT module is now installed in your home directory (after showing off a lot of its features), and you can check that your perl programs will load it without problems by doing:
    [angelv@guinda ~]$ perl -e 'use PGPLOT;'
  • If perl doesn't complain, then you have succesfully installed PGPLOT! Congratulations, you are now ready to customize perl as much as you want.

Angel de Vicente

Section: HOWTOs

edit · print · PDF
Page last modified on June 20, 2019, at 01:19 PM