Skip navigation.
Home
Your source for Perl tips, howto's, faq and tutorials
( categories: | )

By default perl looks for modules in the standard library path and the current directory. Sometimes you need to use some modules that are installed in non standard locations; there are several ways to deal with this situation:

-- Install the module somewhere in the standard library path

If you have administrator privileges, then the best solution is to install the modules in any of the system defined library paths (you can get the paths executing perl -le 'print foreach @INC').

-- Set the environment variable PERL5LIB

Perl will look for modules in the directories specified in PERL5LIB environment variable before looking in the standard library and current directory, so you can set this variable to locate your modules.

The syntax is the same you use for the PATH environment variables, so you separate the directories with colons on unix and with a semicolon on Windows.

Example:

# unix, bourne shell
PERL5LIB=/home/path/lib:/usr/another/path/lib; export PERL5LIB

Be aware that scripts running with -T option (taint checks) don't use that variable, so in those cases this option won't work.

-- Use '-I' command line parameter

The syntax should be something like:

perl -I /home/path/lib -I /usr/another/lib script.pl

-- Add the library path in your script

The command for including the path in your script is: use lib "path".
Notice that this statement prepends "path" to the @INC array, so it's basically the same as unshift @INC, "path"

Example:

#!/usr/bin/perl
use lib "/home/path/lib";
use lib "/usr/another/lib";
 
use MyCustomModule;