25 Sep 2007, 00:00

Install a Perl Module on a Shared Host
  1. Setup cpan:

    $ mkdir ~/perl
    $ mkdir -p ~/.cpan/CPAN  
    $ touch ~/.cpan/CPAN/MyConfig.pm  
    $ cpan
    cpan> o conf init

    Set the following settings:

    'cpan_home' => q[/home/username/.cpan],  
    'build_dir' => q[/home/username/.cpan/build]  
    'keep_source_where' => q[/home/username/.cpan/sources],  
    'mbuildpl_arg' => q[--install_base /home/username/perl]
  2. Get and Install the Module

    $ cpan force install Module::Name           
  3. Make sure Perl can find your modules

    Add this line in each of your Perl scripts (change perl version accordingly):

    use lib '/home/your_username/perl/lib/perl5/site_perl/5.8.7';

    OR rather than editing all your Perl scripts, in your cgi-bin/.htaccess file:

    SetEnvIf Request\_URI "^/cgi-bin/" PERL5LIB=/home/your_username/perl/lib/perl5/site_perl/5.8.7:/home/your_username/perl/lib/perl5/site_perl/5.8.7/site\_perl

    OR in your .bash_profile:

    export PERL5LIB=/home/your_username/perl/lib/perl5/site_perl/5.8.7:/home/your_username/perl/lib:/home/your_username/perl/lib/perl5:/home/your_username/perl/lib/perl5/site_perl

It won’t be effective until you log back in, if you want to make it effective in your current session, just type the EXPORT line in your command prompt.