Installation of mod_perl-enabled Apache Without Superuser Privileges Page 4

Note that if you have a PERL5LIB setting, you don't need to alter the @INC value in your scripts. But if for example someone else (who doesn't have this setting in the shell) tries to execute your scripts, Perl will fail to find your locally installed modules. The best example is a crontab script that might use a different SHELL environment and therefore the PERL5LIB setting won't be available to it.

So the best approach is to have both the PERL5LIB environment variable and the explicit @INC extension code at the beginning of the scripts as described above.

The CPAN.pm Shell and Locally Installed Modules

The CPAN.pm shell saves a great deal of time when you have to deal with Perl modules installation and keeping them up to date. It does the job for us, even detecting the missing modules listed in prerequisites, fetching and installing them. So you might wonder whether you can use CPAN.pm to maintain your local repository as well.

When you start the CPAN interactive shell, it searches first for the user's private configuration file and then for the system wide one. When I'm logged as user stas the two files on my setup are:


If there is no CPAN shell configured on your system, when you start the shell for the first time it will ask you a dozen configuration questions and then create the Config.pm file for you.

If you've got it already system-wide configured, you should have a /usr/lib/perl5/5.00503/CPAN/Config.pm. If you have a different Perl version, alter the path to use your Perl's version number, when looking up the file. Create the directory (mkdir -p creates the whole path at once) where the local configuration file will go:

  % mkdir -p /home/stas/.cpan/CPAN

Now copy the system wide configuration file to your local one:

  % cp /usr/lib/perl5/5.00503/CPAN/Config.pm   /home/stas/.cpan/CPAN/MyConfig.pm

The only thing left is to change the base directory of .cpan in your local file to the one under your home directory. On my machine I replace /usr/src/.cpan (that's where my system's .cpan directory resides) with /home/stas. I use Perl of course!

  % perl -pi -e 's|/usr/src|/home/stas|'   /home/stas/.cpan/CPAN/MyConfig.pm

Now you have the local configuration file ready, you have to tell it what special parameters you need to pass when executing the perl Makefile.PL stage.

Open the file in your favorite editor and replace line:

  'makepl_arg' => q[],


  'makepl_arg' => q[PREFIX=/home/stas],

Now you've finished the configuration. Assuming that you are logged in as the same user you have prepared the local installation for (stas in our example), start it like this:

  % perl -MCPAN -e shell

From now on any module you try to install will be installed locally. If you need to install some system modules, just become the superuser and install them in the same way. When you are logged in as the superuser, the system-wide configuration file will be used instead of your local one.

If you have used more than just the PREFIX variable, modify MyConfig.pm to use them. For example if you have used these variables:

This article was originally published on Jul 14, 2000

Thanks for your registration, follow us on our social networks to keep up-to-date