This article explains how to install Perl modules from CPAN (Comprehensive Perl Archive Network) in your home directory on Pair Networks servers. This is useful if you need a module that isn’t already installed on your server or a specific version of an installed module.
Prerequisites
- Access to your Pair Networks hosting account via SSH
- Basic knowledge of the command line
- A directory in your home folder to store the installed modules
Installation Steps
1. Open the CPAN Shell
Connect to your account via SSH and then run:
/usr/local/bin/perl -MCPAN -e shell
You should see the CPAN shell prompt:
cpan shell -- CPAN exploration and modules installation (v1.7601)
ReadLine support enabled
cpan>
2. Configure CPAN to Use Your Home Directory
By default, CPAN installs modules in directories where you don't have write access. Configure CPAN to install to your home directory (where you do have write access) by running:
o conf makepl_arg LIB=DIRECTORY_PATH
Replace DIRECTORY_PATH with the file path to your chosen directory.
Example:
cpan> o conf makepl_arg LIB=/usr/home/MyUsername/MyFolder
makepl_arg LIB=/usr/home/MyUsername/MyFolder
cpan>
3. Install a Perl Module
To install a module, use the install command inside the CPAN shell. For example, if you wanted to install the Acme::Yoda module:
cpan> install Acme::Yoda
The installer will download and compile the module. You may see a lot of information, as well as warnings about man pages. This is normal and can be ignored. When the installation is successful, you will see:
/usr/bin/make install -- OK
4. Quit the CPAN Shell
When finished, enter the q command to exit:
cpan> q
This will exit the CPAN shell.
Post-Installation: Using Your Module
Any Perl script that uses the installed module must be told where to find it. You can add a line like this to your script, pointing to the same directory you used in step 2.
use lib '/usr/home/USERNAME/DIRECTORY_NAME';
use Acme::Yoda;
Replace USERNAME, DIRECTORY_Name, and Acme::Yoda with your username, directory name, and Perl module respectively.
Troubleshooting
Use the help command in CPAN shell for additional options:
cpan> help
You can also view the full documentation by running:
perldoc CPAN