From CsWiki
Jump to: navigation, search

When you need a perl module and the system can't or won't install it for you, the best option is usually to install it manually through CPAN (Comprehensive Perl Archive Network).

This page gives instructions for configuring cpan to install perl modules in your home directory (or any other place you have permission to write in the school's filesystems). For general information and usage of cpan please refer to the cpan inline help, the cpan man page or google.


First step is to create the proper directory tree:

mkdir -p ~/.cpan/CPAN

Next, copy the /cs/share/skel/ template and replace __USER__ and __HOME__ appropriately. This can be done in a single command:

sed -e 's,__USER__,'$USER',g' -e 's,__HOME__,'$HOME',g' /cs/share/skel/ > ~/.cpan/CPAN/

If you previously opened cpan, this will override the old configuration, you might need to delete the previous file.

Final step is to let perl (and cpan) locate the packages installed by cpan. This can be done by setting the PERL5LIB environment variable. For those who use the (t)csh shell (our default) add the following line to ~/.cshrc:

setenv PERL5LIB ~/cpan/perl5

For those who use an sh compatible shell (sh, bash, zsh), use:

export PERL5LIB=~/cpan/perl5

Note that each module you install, will be installed in your home directory by default (see Setting Different Paths for more details). Depending on the module(s), this can be heavy on your disk quota. To minimize the quota usage, the build and sources directories are set to /tmp. This will free some space, but will cause a longer load time for the cpan itself.

After this, open a new shell (or execute the setenv manually), and you can start using cpan

Setting Different Paths

If you have access to another filesystem where you want to install cpan modules (for example, lab specific disk, jailbird, .+, etc.), you need to manually update the file.

Specifically, each parameter in the line starting with makepl_arg needs to be changed to the new location. For example, if the new location is /a/new/path/cpan, you can execute the command:

sed -i -e 's,~/cpan,/a/new/path/cpan,g' ~/.cpan/CPAN/

(This command will only work when changing for the first time)

Don't forget to also update PERL5LIB appropriately.

If you want to keep the sources and build directory, you need to change the keep_source_where and build_dir lines appropriately in the file.


To uninstall (if you want to free space) simply delete the ~/.cpan and ~/cpan directories (or other directories if you changed the installation path).