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.
Server changes may cause this to break. Be prepared to troubleshoot this yourself if this happens.
We seriously aren't kidding about this.

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.

Contents

Setting up CPAN

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. Add the following lines to the bottom of your ~/.profile file:

PERL5LIB=~/perlmods/lib/perl/5.x:~/perlmods/lib/perl/5.x.x
PERL5LIB=$PERL5LIB:~/perlmods/share/perl/5.x:~/perlmods/share/perl/5.x.x
PERL5LIB=$PERL5LIB:~/perlmods/local/share/perl/5.x.x:~/perlmods/local/lib/perl/5.x.x
export PERL5LIB

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

Now log out from DreamHost and then log in again.

Setup CPAN to install the modules in the new path. Run cpan. If this is the first time you run it it will go directly into configuration mode.

$ cpan

Note that you must use the cpan command, rather than perl -MCPAN - the latter command is not recognized as an installer, and will be subject to more stringent memory limits.

If the CPAN setup doesn't come up, at the cpan> prompt type "o conf init"

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:

cpan> 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:

cpan> 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

Making your FastCGI / CGI scripts work

Any CGI or Fast CGI scripts will need to have the following at their top if you want them to use the locally installed modules.

use lib qw( /home/username/perlmods/lib/perl/5.x /home/username/perlmods/lib/perl/5.x.x 
            /home/username/perlmods/share/perl/5.x /home/username/perlmods/share/perl/5.x.x
            /home/username/perlmods/local/share/perl/5.x.x 
            /home/username/perlmods/local/lib/perl/5.x.x );

where username is your shell name, perlmods is what you chose above as the local CPAN install directory, and 5.x and 5.x.x refer to the currently installed Perl version determined by perl -v.

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.

Other modules

Please note that some modules will not install correctly from CPAN as non-root and to a non-standard path. They will have to be built and installed manually (that is, using the build scripts provided with the modules). Two specifically are:

DateTime

DateTime (as of 0.68) requires the install step to be executed like so using the "--install_base" option:

 $ ./Build install --install_base ~/perlmods

IO:Compress

IO::Compress (as of 2.034) requires tweaking the Makefile because one of the target paths ignores the PREFIX environment variable. After generating the Makefile using

 $ perl Makefile.PL PREFIX=~/perlmods

Open up the Makefile and look for this line

 INSTALLARCHLIB = /usr/lib/perl/5.10

Change it to say

 INSTALLARCHLIB = $(SITEPREFIX)/lib/perl/5.10

Then proceed with your make/make test/make install.

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

Killed

There is a procwatch daemon running that may kill your perl installs - see Killed

Personal tools