CPAN

From DreamHost

Jump to: navigation, search
The instructions provided in this article or section are considered advanced.

You are expected to be knowledgeable in the UNIX shell.
Support for these instructions is not available from DreamHost tech support.


CPAN is the Comprehensive Perl Archive Network and allows you to use the HUGE library of premade modules available at http://search.cpan.org

You need root access normally, but this article will show you how to setup CPAN as a non root user.

To install modules in your home directory you first need to setup a target directory for them:

$ mkdir ~/perlmods

Perl needs to know where the new modules are going to be installed:

$ PERL5LIB=~/perlmods/lib/perl/5.8:~/perlmods/lib/perl/5.8.4
$ PERL5LIB=$PERL5LIB:~/perlmods/share/perl/5.8:~/perlmods/share/perl/5.8.4
$ export PERL5LIB

where 5.8 and 5.8.4 refer to the current version of Perl installed on the Dreamhost servers. (You an find the version with perl -v.)

You should add the above to your .profile as well. Any CGI or Fast CGI scripts will need to have the following at their top before you use any modules.

use lib qw( /home/username/perlmods/lib/perl/5.8 /home/username/perlmods/lib/perl/5.8.4 
            /home/username/perlmods/share/perl/5.8 /home/username/perlmods/share/perl/5.8.4 );

Then setup CPAN to install the modules there. Most of the answers are the defaults, however be sure to note the exceptions listed:

$ cpan
Are you ready for manual configuration? yes

Policy on building prerequisites (follow, ask or ignore)? follow

Parameters for the 'perl Makefile.PL' command? Typical frequently used settings:

PREFIX=~/perl non-root users (please see manual for more hints)

Your choice: PREFIX=~/perlmods
Select your continent (or several nearby continents) [] 5
Select your country (or several nearby countries) [] 6

put them on one line, separated by blanks, e.g. '1 4 5' [] 14 7 1 2 3 (whatever you like)


The important options are that you want to do a manual configuration, and the PREFIX= line. The prerequisite line is optional but easier overall. After that you are done! You will be dumped into a cpan> command prompt:

>install XRAY::Vision

Just type "install Some::Module", where Some::Module is the name of the module you are trying to install. See the example above. This will install if for you in the perlmods directory.

After you are finished you type:

>bye

to exit the CPAN shell. How do you know if a Module is installed? You can tell if you need to add it or not by typing this at a shell login:

$ perl -MXRAY::Vision -e 1

If the module is installed in the root perl install, you won't get any errors, it will just return silently. If the module is not already installed in the root perl install, you will get something like this:

$ perl -MXRAY::Vision -e 1
Can't locate XRAY/Vision.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.8.4 .... etc

Now that you have the module installed, you have to make sure your script knows where to find it, in your script you type:

use lib '/home/username/perlmods/share/perl/5.8.4/';

where username is your shell name, and perlmods is what you chose above as the local CPAN install directory.

What if you get an error

If the above cpan command generates an error like the following:

Your configuration suggests that CPAN.pm should use a working
directory of
    /root/.cpan
Unfortunately we could not create the lock file
    /root/.cpan/.lock
due to permission problems.

Please make sure that the configuration variable
    $CPAN::Config->{cpan_home}
points to a directory where you can write a .lock file. You can set
this variable in either
    /etc/perl/CPAN/Config.pm
or
    /home/username/.cpan/CPAN/MyConfig.pm

Could not open >/root/.cpan/.lock: Permission denied

then you'll have to manually create your ~/.cpan/CPAN/MyConfig.pm file before going on (this is because root already configured cpan in your host.

You can do this by typing the following:

mkdir -pv ${HOME}/.cpan/CPAN
cat > ${HOME}/.cpan/CPAN/MyConfig.pm <<eof

\$CPAN::Config = {
  'auto_commit' => q[0],
  'build_cache' => q[10],
  'build_dir' => q[\$ENV{HOME}/.cpan/build],
  'cache_metadata' => q[1],
  'commandnumber_in_prompt' => q[1],
  'cpan_home' => q[\$ENV{HOME}/.cpan],
  'dontload_hash' => {  },
  'ftp' => q[/usr/bin/ftp],
  'ftp_passive' => q[1],
  'ftp_proxy' => q[],
  'getcwd' => q[cwd],
  'gpg' => q[/usr/bin/gpg],
  'gzip' => q[/bin/gzip],
  'histfile' => q[\$ENV{HOME}/.cpan/histfile],
  'histsize' => q[100],
  'http_proxy' => q[],
  'inactivity_timeout' => q[0],
  'index_expire' => q[1],
  'inhibit_startup_message' => q[0],
  'keep_source_where' => q[\$ENV{HOME}/.cpan/sources],
  'lynx' => q[/usr/bin/lynx],
  'make' => q[/usr/bin/make],
  'make_arg' => q[],
  'make_install_arg' => q[],
  'make_install_make_command' => q[/usr/bin/make],
  'makepl_arg' => q[PREFIX=\$ENV{HOME}/perlmods],
  'mbuild_arg' => q[],
  'mbuild_install_arg' => q[],
  'mbuild_install_build_command' => q[./Build],
  'mbuildpl_arg' => q[],
  'ncftpget' => q[/usr/bin/ncftpget],
  'no_proxy' => q[],
  'pager' => q[less],
  'prerequisites_policy' => q[follow],
  'scan_cache' => q[atstart],
  'shell' => q[/bin/bash],
  'tar' => q[/bin/tar],
  'term_is_latin' => q[0],
  'term_ornaments' => q[1],
  'unzip' => q[/usr/bin/unzip],
  'urllist' => [q[ftp://cpan.cse.msu.edu/], q[ftp://cpan-du.viaverio.com/pub/CPAN/], q[ftp://cpan.mirrors.redwire.net/pub/CPAN/], q[ftp://cpan.hostrack.net/pub/CPAN]],
  'use_sqlite' => q[0],
  'wget' => q[/usr/bin/wget],
};
1;
__END__
eof


Installing Module::Build and many other modules

If you're installing Module::Build or others which use Module::Build in their installation, it might help to add the above PERL5LIB lines follwing to your .profile (or .bash_profile) otherwise, anything you build won't know how to get to the Module::Build Build script.

Configuring CPAN

If you need to manually configure settings, you may access your configuration in the file:

~/.cpan/CPAN/MyConfig.pm

If specifying PREFIX as above use the full path to your perlmods directory:

PREFIX=/home/username/perlmods

Use perldoc to get a listing of CPAN settings that you may edit:

perldoc CPAN
Personal tools