[转]Installing Perl modules from CPAN

来源:百度文库 编辑:神马文学网 时间:2024/04/27 21:26:08
There are several ways to get Perl modules from CPAN installed on yourunix-based system. Keep in mind that there is always more than one wayto do it with Perl, and this is no different. Before embarking upon anyinstallation, it's a good idea to download the module, unzip it andcheck out the documentation. In general, though, most modules areinstalled in the same method.
The simplest way to get Perl modules installed is to use the CPAN moduleitself. If you are the system administrator and want to install themodule system-wide, you'll need to switch to your root user. To fire upthe CPAN module, just get to your command line and run this:
 perl -MCPAN -e shell 
If this is the first time you've run CPAN, it's going to ask you aseries of questions - in most cases the default answer is fine. Once youfind yourself staring at the cpan> command prompt, installing a module is as easy as install MODULE::NAME - for example, to install the HTML::Template module you'd type:
 cpan> install HTML::Template 
CPAN should take it from there and you'll wind up with the module installed into your Perl library.
Let's say you're on your system command line and you just want toinstall a module as quickly as possible - you can run the Perl CPANmodule via command line perl and get it installed in a single line:
 perl -MCPAN -e 'install HTML::Template' 
As I mentioned earlier, it's always advisable to download a moduleyourself, especially if you're having problems installing with CPAN. Ifyou're on the command line, you can use something like wget to grab the file. Next you'll want to unzip it with something like:
 tar -zxvf HTML-Template-2.8.tar.gz 
This will unzip the module into a directory, then you can move in andpoke around - look for the README or INSTALL files. In most cases,installing a module by hand is still pretty easy, though (although notas easy as CPAN). Once you've switched into the base directory for themodule, you should be able to get it installed by typing:
 perl Makefile.PL
make
make test
make install