Before you install a module, be sure that it isn't installed already:
perldoc perllocal
The recommended way to install Perl modules is to invoke the CPAN shell.
First time running the shell, you have to setup some parameters.
Read about all the details at http://search.cpan.org/perldoc?CPAN.
Normally it is sufficient to just type:
install Some::Module
and CPAN will take care of the rest (download, configure, install).
Sometimes, anyhow, you want to customize the installation.
You can find an example here, installing the DBD::mysql module.
If you still insist to install modules manually, here is how to do it:
Download your favorite module from CPAN and install it:
# gunzip -c Some-Module-X.X.tar.gz | tar -xf -
# cd Some-Module-X.X
# perl Makefile.PL
# make
# make test
# make install
Use the module from your Perl script:
#!/usr/bin/perl
usestrict;
useSome::Module;
Install it in your own path /home/redantig/perl (if you don't have root access, for example - note that this can be done from within the CPAN shell as well):
# gunzip -c Some-Module-X.X.tar.gz | tar -xf -
# cd Some-Module-X.X
# perl Makefile.PL LIB=/home/redantig/perl PREFIX=/home/redantig/perl
# make
# make test
# make install
If you need to use module dependencies already installed in the same path (i.e. /home/redantig/perl), you have to use the perl -I flag (to modify @INC).
(See other solutions in the Perl Cookbook, p. 413.)
Some times (depending on the Perl version) the -I flag doesn't work, so you have to set the PERL5LIB environment variable to install the modules correctly.
Heres a variant to be sure that Makefile.PL find your modules: