From now on, any time you want to install perl modules locally you simply
execute:
% perl Makefile.PL 'cat ~/.perl_dirs' % make % make test % make install
Using this method you can easily maintain several Perl module repositories.
For example, you could have one for production Perl and another for
development:
% perl Makefile.PL 'cat ~/.perl_dirs.production'
or:
% perl Makefile.PL 'cat ~/.perl_dirs.develop'
Perl modules are generally placed in four main directories. To find these
directories, execute:
% perl -VThe output contains important information about your Perl installation. At
the end you will see:Characteristics of this binary (from libperl): Built under linux Compiled at Apr 6 1999 23:34:07 @INC: /usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_perl/5.005/i386-linux /usr/lib/perl5/site_perl/5.005 .It shows us the content of the Perl special variable
@INC,
which is used by Perl to look for its modules. It is equivalent to the
PATHenvironment variable in Unix shells which is used to find
executable programs.Notice that Perl looks for modules in the
.directory, too,
which stands for the current directory. It's the last entry in the above
output.Of course this example is from version 5.00503 of Perl installed on my x86
architecture PC running Linux. That's why you see i386-linux and
5.00503. If your system runs a different version of Perl, operating
system, processor or chipset architecture, then some of the directories will
have different names.I also have a perl-5.6.0 installed under
/usr/local/lib/so
when I do:% /usr/local/bin/perl5.6.0 -VI see:
@INC: /usr/local/lib/perl5/5.6.0/i586-linux /usr/local/lib/perl5/5.6.0 /usr/local/lib/site_perl/5.6.0/i586-linux /usr/local/lib/site_perlNote that it's still Linux, but the newer Perl version uses the
version of my Pentium processor (thus the i586 and not i386).
This makes use of compiler optimizations for Pentium processors when the binary
Perl extensions are created.All the platform specific files, such as compiled C files glued to Perl
withXSorSWIG, are supposed to go into the
i386-linux-like directories.Important: As we have installed the Perl modules into
non-standard directories, we have to let Perl know where to look for the four
directories. There are two ways to accomplish this. You can either set the
PERL5LIBenvironment variable, or you can modify the
@INCvariable in your scripts.Assuming that we use perl-5.00503, in our example the directories are:
/home/sbekman/lib/perl5/5.00503/i386-linux /home/sbekman/lib/perl5/5.00503 /home/sbekman/lib/perl5/site_perl/5.005/i386-linux /home/sbekman/lib/perl5/site_perl/5.005As mentioned before, you find the exact directories by executing
perland replacing the global Perl installation's base directory with your
-V
home directory.Modifying
@INCis quite easy. The best approach is to use the
libmodule (pragma), by adding the following snippet at the top of
any of your scripts that require the locally installed modules:use lib qw(/home/stas/lib/perl5/5.00503/ /home/stas/lib/perl5/site_perl/5.005);
Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved
Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.