How To Install Perl Modules
When You Own or Control the Whole Server
(For other situations, see the Perl Modules main page.)
If you're trying to run a perl program and you get an error about a missing module (for example, "LWP/UserAgent.pm") then you just need to install that module. The slash becomes a double-colon, and the .pm is assumed, so in that example, you'd install "LWP::UserAgent". Here's how.
Mac OS X Users:
The following command should do it:
For example, to install the DBI.pm module:
The first time you use the cpan command, it'll ask you a bunch of configuration questions, but you can accept the default values for most of them.
ActivePerl comes with a program called ppm or ppm3 that you can run from the command-line. It will give you a "ppm>" prompt, at which you can type "search <module-name>" to find the exact name of the module you want, and then "install <module-name>" to install it. Or, in newer versions of ppm, it will launch a graphical interface where you can search for and install modules by point-and-click. Note: if you want a Perl module whose version in ppm is older than the current version, you can install the module from CPAN directly.
Run this command:
The first time you run it, you'll have to say y or n to a bunch of configuration questions, but eventually you'll get a cpan prompt, at which you can type:
Alternately, you can install a package non-interactively by just running:
And remember, in "module-name", use double-colons (::) in place of slashes (/), and don't type the .pm at the end.
Note that sometimes a module doesn't pass all of the tests that run during the build stage, but this is usually OK. However, it will then refuse to install the module, so you'll have to install it with cpan> force install <module-name> or at the shell prompt sudo perl -MCPAN -e 'force install <module-name>'.
Also note, if it doesn't seem to do anything when you try to install a module, and/or the connections just keep timing out or otherwise failing, type o conf urllist at the cpan prompt, which will show you which URLs it's using. You can add new URLs like this:
o conf urllist unshift ftp://ftp.crc.ca/pub/CPAN/
o conf urllist unshift ftp://cpan.mirror.smartworker.org/pub/CPAN
o conf urllist unshift ftp://cpan.chebucto.ns.ca/pub/CPAN/
Issues With Multiple Perl Versions
Some servers have multiple Perl installations, which can cause confusion when attempting to install/use Perl modules, because modules generally only install to one Perl installation at a time. So for example, if you have one Perl installation in /usr/bin and another in /opt/local/bin, and your module gets installed into one of those locations whereas your script is using the other one, then your script won't see the module. There are a few ways to solve this.
One solution would be to edit the first line of your Perl script, changing it from, say, #!/usr/bin/perl (the most common) to #!/opt/local/bin/perl, assuming of course that /opt/local is where your Perl module got installed. (On Mac and Linux systems, use the command "find / -name Foo.pm" to locate the Foo.pm module on your system.) This means your script will be executed using a different version of Perl, which shouldn't be a problem unless it's really outdated, or if this version is missing other Perl modules that are present in the version you were originally using, etc.
Another solution is to tell your Perl script to look in a particular location for the module. Using the find command in the previous paragraph, say you discover that your module is installed in the /opt/local/lib/perl5/site_perl/5.8.9 directory; then, you'd add this line near the top of your Perl script:
Depending on how close the version numbers are between your script's version of Perl and the module's version, this method may or may not work.
A third solution would be to simply install the Perl module into the Perl installation where your script is trying to find it. If you've got two different Perl installations, then you've got two different cpan commands, and the one you choose will determine which Perl installation receives the module. So instead of using the command "cpan Module::Name" to install the module, use the full path, e.g. "/usr/bin/cpan Module::Name" or "/opt/local/bin/cpan Module::Name", each of which will install the module into its respective Perl installation.
If That Doesn't Work...
Please contact us for more help.