Install perl module via CPAN (locally)

Installation of perl module using cpan is very handy. Previously there was a rpm for RH ‘cpam2rpm’, unfortunately, the development for this package ceased. have to go back to native cpan.

1 install cpan and its dependencies

  • on ubuntu sudo  apt-get install build-essential
  • on fedora sudo yum install perl-CPAN

2. Configuration and installation  Perl Modules as an ordinary user.

The root user had already used and Perl wanted to use root’s config until I did the following. First create the .cpan directories

 # These directories didn't exist on my computer
 mkdir $HOME/.cpan/
 mkdir $HOME/.cpan/CPAN/

Then create a new in $HOME/.cpan/CPAN/

 # This is so it ignores the global CPAN config that has root's
 # info in it
 echo "\$CPAN::Config->{cpan_home}='$HOME/.cpan';" > $HOME/.cpan/CPAN/

Then Execute a CPAN shell

 perl -MCPAN -e shell

Then when in the shell type:

 o conf init

to reconfigure CPAN, making sure that all of the variables point to /home/$user/.cpan/somefile instead of /home/root/.cpan/somefile

Then edit /home/$user/.cpan/CPAN/ and change the makepl_arg so that it has your PREFIX line as well:

 'makepl_arg' => q[INSTALLDIRS=site PREFIX=$HOME/perl/],

Finally the env variable PERL5LIB needs to point to the new module installation paths:

 export PERL5LIB="$HOME/perl/share/perl/5.8.4/:$HOME/perl/lib/perl/5.8.4/";

and then you should be able to use CPAN to install modules.

I then modified the Oddmuse script so that the new module install directory was in @INC so that Oddmuse could pick up the modules. Put the following line somewhere near the top

 push @INC,qw(/home/$user/perl/share/perl/5.8.4/ /home/$user/perl/lib/perl/5.8.4/);

3 Proxy for internet access

if you use proxy to access web, you need configure it too in file ~/.wgetrc

# The proxy server – proxy server:port number
# The account details for yum connections

4. example

invoke the cpan command as a normal user


But once you hit on enter for “cpan” to execute, you
be asked of some few questions. To make it simple for
yourself, answer “no” for the first question so that
the latter ones will be done for you automatically.

At the cpan prompt. now enter the commands below

make install

install Bundle::CPAN

examples of what installed below

cpan prompt>  install  IO::File
cpan prompt>  install  Net::SMTP_auth
cpan prompt>  Email::MIME::Attachment::Stripper
cpan prompt>  Mail::POP3Client

2 responses to “Install perl module via CPAN (locally)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s