| The installation of Perl modules varies by Perl distribution. If you're using an ActiveState Perl distribution, the installation is very easy. If you're using another distribution of Perl, such as a version that was delivered with your operating system or a Perl binary that you compiled from source, there may be an additional step or two in the process, but it is still fairly straightforward. Let's take a look at these two cases and discuss how to install a Perl module. Standard Perl Module InstallationStandard module installation can be performed in two ways: either with a manual install or by using the CPAN.pm module. Let's take a look at the manual installation first. Manual Perl Module InstallationThe standard module installation process requires you to use the same compiler that was used to compile the Perl binary for your operating system. In addition to the compiler, you must also have the make utility available. Note The make utility name may vary between operating systems. Microsoft Visual C++, for example, comes with the nmake utility, and Borland C++ comes with dmake . Be sure to use the utility that corresponds to the compiler that was used to build the Perl binary. Provided that your compiler is properly installed, the first step in the process is to download the module. Most Perl modules are available at CPAN (http://www.cpan.org). Some specialized Perl modules not available on CPAN may be offered at different sites. Perl modules are usually downloaded in a compressed format. The following assumes that the module is compressed using either tar or gzip . Note The tar and gzi p utilities are freely available at http://www.gnu.org. Although initially developed for Unix-like platforms, they have now been ported to other operating systems, including Windows. You can get the Microsoft Windows version of both utilities from www.cygwin.com. Microsoft Windows compression utilities may also extract tar and gzip files. Let's assume that we just downloaded the XML::SAX module to the current directory. The following are the commands we need to execute to compile and install the modules. We'll first need to decompress the package, cd , to the top-level directory where the unzipped files reside and execute the following commands:
Note the capital letters ( Makefile.PL ) in the first step. These are very important on a Unix system. These steps decompress, compile, and install the module. If a prerequisite is not met (for example, the module you're trying to install is expecting that another module was already installed), the installation will fail. For more accurate installation instructions, be sure to read the README file that is distributed with every Perl module. Usually, any platform-specific instructions are included in the README file. Installing Perl Modules Using CPAN.pmAnother method of installing Perl modules is to use the CPAN.pm module. To use the CPAN.pm module, you must first install the CPAN.pm Perl module using the manual installation procedure previously discussed (if it isn't already included with your Perl distribution). Using the CPAN.pm Perl module to install other modules is very easy and straightforward. Modules are retrieved from any number of CPAN mirror sites. An added benefit is that the CPAN.pm Perl module also takes care of the prerequisites for you. Therefore, when you install a module, the CPAN.pm Perl module will compile and install all its prerequisites first, as well as their requisites, before proceeding. Here is how you would install XML::SAX using CPAN.pm in the shell mode: >perl -MCPAN -e shell CPAN>install XML::SAX The first line starts the CPAN shell prompt. Typing install XML::SAX retrieves and installs all the required Perl modules ( assuming you have a network connection to the Internet). After you're finished with the installation, type exit to leave the CPAN shell. Note The CPAN.pm module has a large number of commands and options. Unfortunately I can't discuss all of them here. For additional information on the CPAN.pm Perl module, please see perldoc CPAN.pm. ActiveState Module InstallationThe ActiveState distribution of Perl provides the Perl Package Manager (PPM) tool. PPM provides an easy-to-use interface that enables you to locate, install, upgrade, and remove Perl modules. The first thing you'll need to do is type ppm to enter the PPM shell. Note that you can call ppm from any directory on your machine ”the installed modules will be installed in the proper location. During the ActiveState Perl installation, modifications are made to your PATH statement, so that the ppm utility is accessible from anywhere on your machine. Now that we've started the PPM shell, the first thing we need to do is identify PPM repositories (PPM equivalents of File Transfer Protocol (FTP) sites). These repositories are mirror sites used to distribute Perl modules. Let's add a few of our favorite repositories. At the prompt, type the following:
What we've done is create links to Perl module repositories that can now be referred to by the location name (for example, XMLPROJ , JENDA , and THEORY5 ). The set save statement is important ”it saves the repositories that you've just added, so that they're available next time you run ppm . Now, our PPM executable knows which repositories to use when looking for Perl modules. To install a module, type install module_name That's it. PPM will now look at the repositories that have been defined and install the requested module. Note For additional information on the Perl Package Manager, please look at perldoc ppm or visit the ActiveState PPM page at http://aspn.activestate.com/ASPN/Downloads/ActivePerl/PPM/. |