NetGate Internet Products and Services 1-877-715-4927
Hosting Access Support About Us Contact Us
Sign Me Up!

Support Home
Phone Support
System Status
Search Our Site
How to Install Your Own Perl Modules

Because we typically have just the standard Perl 5 modules installed there may be times when you need the functionality of a module we don't have installed. Keeping various modules updated for everyone without breaking everyone's scripts would be difficult. Below you'll find some information that should make using these modules easier my allowing you to install the module into your own directory space.

Installing Perl 5 Modules Locally

Installing Perl 5 modules yourself can be a tricky exercise. Utilities for installing Perl 5 modules generally assume that the installation is being done in the root area of the file system of the host machine. As a user you do not have access to the root area of the host machine. So, you must install Perl 5 modules locally, within your directory space.

Normally, the Perl 5 module installation procedure includes commands something like these:

% perl Makefile.PL
% make
% make test
% make install

The first command, "perl Makefile.PL", directs Perl to create a Makefile for the new module you are installing. When installing a Perl module locally you must designate on the command line the directory of your local Perl module directory. That information is used by Perl 5 to create the Makefile. Substitute the following command for "perl Makefile.PL":

% perl5 Makefile.PL PREFIX=<homedir>/perl

The value <homedir> above should be replaced with the output from the following UNIX command:

% echo $HOME

So the complete installation process is:

% perl Makefile.PL PREFIX=<homedir>/perl
% make
% make test
% make install

For older modules it may be necessary to designate several other variables on the command line during the module installation:

% perl Makefile.PL PREFIX=<homedir>/perl \
INSTALLPRIVLIB=<homedir>/perl/lib/perl5 \
INSTALLSCRIPT=<homedir>/perl/bin \ INSTALLSITELIB=<homedir>/perl/lib/perl5/site_perl \
INSTALLBIN=<homedir>/perl/bin \
INSTALLMAN1DIR=<homedir>/perl/perl5/man \

To save yourself some typing you can create a file and put these variable assignments above in a file (perlmodvars) something like this:

INSTALLPRIVLIB=<homedir>/perl/lib/perl5 \
INSTALLSCRIPT=<homedir>/perl/bin \
INSTALLSITELIB=<homedir>/perl/lib/perl5/site_perl \
INSTALLBIN=<homedir>/perl/bin \
INSTALLMAN1DIR=<homedir>/perl/lib/perl5/man \

Then, each time you install a Perl module you can use the following syntax:

% perl Makefile.PL `cat perlmodvars`
% make
% make test
% make install

You also can have a few different local modules installation procedures, for example one for production Perl and another for development:

% perl Makefile.PL `cat <filename>.production`
% perl5 Makefile.PL `cat <filename>.development`

Making Scripts Find the Modules You Have Installed

All pre-installed modules are installed into these 4 directories (depending on the version of Perl):


These 4 directories are already preset in the Perl 5 @INC array. That array contains the paths that perl searches in order to find modules. If you install perl modules locally as described above, you will need to append these two directories, which are local to your directory space, to the @INC array:

<homedir>/perl/lib/perl5 <homedir>/perl/lib/perl5/site_perl

The architecture specific directories are being searched by Perl automatically Each time you want to use modules in that path you should add the following line to your scripts:

use lib qw(<homedir>/perl/lib/perl5/ <homedir>/perl/lib/perl5/site_perl);

You don't have to put it into a BEGIN block; the module takes care of that for you. It also adds the architecture specific directories. You also can use a BEGIN block to include your installed modules:

unshift @INC, qw(<homedir>/perl/lib/perl5/ \

However, the use lib construct seems to be cleaner and the unshift @INC construct doesn't automatically add the architecture specific directories to the @INC array.

Installing New Modules that Require Locally Installed Modules

Imagine that you have installed module A in <homedir>/perl/lib/perl5. Now you want to install a module B that demands module A to be already installed. You know that you have installed the A module, but amazingly B can't locate it. Why? Because when you try to install the module B it doesn't know that you have module A installed locally. Perl 5 searches the basic 4 directories as defined by default in the @INC array. But your local directories aren't listed there.

The solution is simple. The PERL5LIB environment variable does the same job in the shell as use lib does in your script. So if you use csh/tcsh type the following at the command line:

% setenv PERL5LIB <homedir>/perl/lib/perl5:<homedir>/perl/lib/perl5/site_perl

Check the man page of your favorite shell how to set the environment variables if you use a shell different from csh/tcsh. Put this setenv statement into .login or another file that is being sourced each time you login into your account and you will not have to worry to remember setting it each time you login.

Module Installation Using

An alternative to manually installing Perl modules is the module (see which automates module download and installation. When you initially run the

% perl -MCPAN -e shell

command, it will ask you a few questions. You can use all the defaults, except for this one

Parameters for the 'perl Makefile.PL' command? []

and this one:

Parameters for the 'make install' command? []

When it asks for your favorite CPAN site, try this:

After configuration of the module is complete, you will see a > prompt.
Then you can try installing modules. To install the CGI module, do this:

> install CGI

It will fetch the latest version of the CGI module, unpack it, make it, test it and install it into your local area, or the directory you specified as the PREFIX directory. The command:

> i /CGI/

will return the list of modules that match that pattern. The module has more functionality, like checking for the latest modules, for example. Just run

% perldoc CPAN

to read the man page.

An Actual Example Install

In this example we needed the HTTP-Lite Perl module to do some data acquisition from within a Perl script.

Login to our account

telnet <virtualhost name>

Create our local Perl directory

mkdir perl
chmod 700 perl

Create the directory to store the module source

mkdir src
chmod 700 src
cd src

Create our "perlmodvars" file (using vi or your favorite editor)

vi perlmodvars

PREFIX=/u1/vhome/kb/perl \
INSTALLPRIVLIB=/u1/vhome/kb/perl/lib/perl5 \
INSTALLSCRIPT=/u1/vhome/kb/perl/bin \
INSTALLSITELIB=/u1/vhome/kb/perl/lib/perl5/site_perl \
INSTALLBIN=/u1/vhome/kb/perl/bin \
INSTALLMAN1DIR=/u1/vhome/kb/perl/perl5/man \

Download the module using lynx, gunzip, and untar the file

get the module
gunzip HTTP-Lite-0.2.5.tar.gz
tar xvf HTTP-Lite-0.2.5.tar
cd HTTP-Lite-0.2.5

Make the new module

perl Makefile.PL `cat ../perlmodvars`
make install

View the man page for the new module

man -M ../../perl/lib/perl5/man perl/lib/perl5/man HTTP::Lite
(You can add the path to your modules to your MANPATH env to make the automatic)
setenv MANPATH /u1/vhome/kb/perl/lib/perl5/man
man HTTP::Lite

Modify the @INC array in the perl script in which we want to use the module

use lib qw(/u1/vhome/kb/perl/lib/perl5/ \

Run the new script: