Install CPAN modules under a different directory than the default

| 0 Comments | 0 TrackBacks

Are you frustrated with the permission denied message during the make install phase of your perl modules? Well, this is about installing CPAN Perl modules under a different directory than the default paths which are usually owned by root. If you don't have root access then this is the easiest way I've found for installing modules in your home directory.


You will obviously install your module under your own home directory. Let's assume that your directory is /home/farhad. Then create a subdirectory called CPAN.

 cd ~ && mkdir CPAN

That is where we'll install everything. First we'll wipe out the current CPAN configuration, if there is any.

 mkdir -p ~/CPAN/lib/perl5
 mkdir -p ~/.cpan/CPAN
 echo "\$CPAN::Config = {}"> ~/.cpan/CPAN/

And then we want to tell our shell, BASH in my case, the location of the new Perl Module path.

echo 'export PERL5LIB=${PERL5LIB}:~/CPAN/lib/perl5:~/CPAN//lib/perl5/lib:~/CPAN/lib/perl5/lib/i386-linux-thread-multi/' >> ~/.bashrc source ~/.bashrc

Now we'll configure our CPAN:

perl -MCPAN -e shell

Accept all the defaults until you reach this question:

Every Makefile.PL is run by perl in a separate process. Likewise we run 'make' and 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)

Give the following answer (it's one line):

PREFIX=~/CPAN/lib/perl5 LIB=~/CPAN/lib/perl5/lib INSTALLMAN1DIR=~/CPAN/lib/perl5/man1 INSTALLMAN3DIR=~/CPAN/lib/perl5/man3

Finish the CPAN configuration by accepting the rest of the defaults. When asked for which mirrors you want to use, you can choose these:, and

Finally, when presented with the "cpan>" prompt, type "o conf commit" to commit your configuration changes and then press Ctrl-D to exit.

Now you should be able to install CPAN modules by typing:

cpan install module_name

For example:

cpan install Locale::gettext 

No TrackBacks

TrackBack URL:

Leave a comment

About this Entry

This page contains a single entry by Farhad Saberi published on September 14, 2010 1:39 AM.

Perl File Find Breath Depth First Search Algorithms is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.