Difference between revisions of "CPAN"

From CsWiki
Jump to: navigation, search
m
 
Line 35: Line 35:
  
 
To uninstall (if you want to free space) simply delete the ~/.cpan and ~/cpan directories (or other directories if you changed the installation path).
 
To uninstall (if you want to free space) simply delete the ~/.cpan and ~/cpan directories (or other directories if you changed the installation path).
 +
[[category:software]]

Latest revision as of 21:46, 22 March 2017

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.

Install

First step is to create the proper directory tree:

mkdir -p ~/.cpan/CPAN

Next, copy the /cs/share/skel/MyConfig.pm 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/MyConfig.pm > ~/.cpan/CPAN/MyConfig.pm

If you previously opened cpan, this will override the old configuration, you might need to delete the previous MyConfig.pm 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 MyConfig.pm file.

Specifically, each parameter in the line starting with makepl_arg need 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/MyConfig.pm

(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 MyConfig.pm file.

Uninstalling

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