home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

Book HomePerl CookbookSearch this book

12.17. Building and Installing a CPAN Module


You want to install a module file that you downloaded from CPAN over the Net or obtained from a CD.


Type the following commands into your shell. It will build and install version 4.54 of the Some::Module package.

% gunzip Some-Module-4.54.tar.gz
% tar xf Some-Module-4.54
% cd Some-Module-4.54
% perl Makefile.PL
% make
% make test
% make install


Like most programs on the Net, Perl modules are available in source kits stored as tar archives in GNU zip format.[ 2 ] If tar warns of "Directory checksum errors" , then you downloaded the binary file in text format, mutilating it.

[2] This is not the same as the zip format common on Windows machines, but newer version of Windows winzip will read it. Prior to Perl 5.005, you'll need the standard port of Perl for Win32, not the ActiveState port, to build CPAN modules. Free versions of tar and gnutar are also available for Microsoft systems.

You'll probably have to become a privileged user with adequate permissions to install the module in the system directories. Standard modules are installed in a directory like /usr/lib/perl5 while third-party modules are installed in /usr/lib/perl5/site_ perl .

Here's a sample run, showing the installation of the MD5 module:

% gunzip MD5-1.7.tar.gz
% tar xf MD5-1.7.tar
% cd MD5-1.7
% perl Makefile.PL 

Checking if your kit is complete...

Looks good

Writing Makefile for MD5

% make

mkdir ./blib

mkdir ./blib/lib

cp MD5.pm ./blib/lib/MD5.pm

AutoSplitting MD5 (./blib/lib/auto/MD5)

/usr/bin/perl -I/usr/local/lib/perl5/i386 ...


cp MD5.bs ./blib/arch/auto/MD5/MD5.bs

chmod 644 ./blib/arch/auto/MD5/MD5.bsmkdir ./blib/man3

Manifying ./blib/man3/MD5.3

% make test

PERL_DL_NONLAZY=1 /usr/bin/perl -I./blib/arch -I./blib/lib

-I/usr/local/lib/perl5/i386-freebsd/5.00404 -I/usr/local/lib/perl5 test.pl


ok 1

ok 2


ok 13

ok 14

% sudo make install


Installing /usr/local/lib/perl5/site_perl/i386-freebsd/./auto/MD5/


Installing /usr/local/lib/perl5/site_perl/i386-freebsd/./auto/MD5/


Installing /usr/local/lib/perl5/site_perl/./auto/MD5/autosplit.ix

Installing /usr/local/lib/perl5/site_perl/./MD5.pm

Installing /usr/local/lib/perl5/man/man3/./MD5.3

Writing /usr/local/lib/perl5/site_perl/i386-freebsd/auto/MD5/.packlist

Appending installation info to /usr/local/lib/perl5/i386-freebsd/


If your system manager isn't around or can't be prevailed upon to run the installation, don't worry. When you use Perl to generate the Makefile from template Makefile.PL , you can specify alternate installation directories.

# if you just want the modules installed in your own directory
% perl Makefile.PL LIB=~/lib

# if you have your own a complete distribution
% perl Makefile.PL PREFIX=~/perl5-private

See Also

The documentation for the standard ExtUtils::MakeMaker module, also in Chapter 7 of Programming Perl ; the INSTALL file in the Perl source distribution for information on building a staticly linked perl binary.

Previous: 12.16. Documenting Your Module with Pod Perl Cookbook Next: 12.18. Example: Module Template
12.16. Documenting Your Module with Pod Book Index 12.18. Example: Module Template

Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.