perlmodinstall.html

来自「perl教程」· HTML 代码 · 共 413 行 · 第 1/2 页

HTML
413
字号
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../displayToc.js"></script>
<script language="JavaScript" src="../../tocParas.js"></script>
<script language="JavaScript" src="../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../scineplex.css">
<title>perlmodinstall - Installing CPAN Modules</title>
<link rel="stylesheet" href="../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>

<body>

<script>writelinks('__top__',2);</script>
<h1><a>perlmodinstall - Installing CPAN Modules</a></h1>
<p><a name="__index__"></a></p>

<!-- INDEX BEGIN -->

<ul>

	<li><a href="#name">NAME</a></li>
	<li><a href="#description">DESCRIPTION</a></li>
	<ul>

		<li><a href="#preamble">PREAMBLE</a></li>
	</ul>

	<li><a href="#portability">PORTABILITY</a></li>
	<li><a href="#hey">HEY</a></li>
	<li><a href="#author">AUTHOR</a></li>
	<li><a href="#copyright">COPYRIGHT</a></li>
</ul>
<!-- INDEX END -->

<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>perlmodinstall - Installing CPAN Modules</p>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>You can think of a module as the fundamental unit of reusable Perl
code; see <a href="../../lib/Pod/perlmod.html">the perlmod manpage</a> for details.  Whenever anyone creates a chunk of
Perl code that they think will be useful to the world, they register
as a Perl developer at <a href="http://www.cpan.org/modules/04pause.html">http://www.cpan.org/modules/04pause.html</a>
so that they can then upload their code to the CPAN.  The CPAN is the
Comprehensive Perl Archive Network and can be accessed at
<a href="http://www.cpan.org/">http://www.cpan.org/</a> , and searched at <a href="http://search.cpan.org/">http://search.cpan.org/</a> .</p>
<p>This documentation is for people who want to download CPAN modules
and install them on their own computer.</p>
<p>
</p>
<h2><a name="preamble">PREAMBLE</a></h2>
<p>First, are you sure that the module isn't already on your system?  Try
<code>perl -MFoo -e 1</code>.  (Replace &quot;Foo&quot; with the name of the module; for
instance, <code>perl -MCGI::Carp -e 1</code>.</p>
<p>If you don't see an error message, you have the module.  (If you do
see an error message, it's still possible you have the module, but
that it's not in your path, which you can display with <code>perl -e
&quot;print qq(@INC)&quot;</code>.)  For the remainder of this document, we'll assume
that you really honestly truly lack an installed module, but have
found it on the CPAN.</p>
<p>So now you have a file ending in .tar.gz (or, less often, .zip).  You
know there's a tasty module inside.  There are four steps you must now
take:</p>
<dl>
<dt><strong><a name="item_decompress_the_file"><strong>DECOMPRESS</strong> the file</a></strong>

<dt><strong><a name="item_unpack_the_file_into_a_directory"><strong>UNPACK</strong> the file into a directory</a></strong>

<dt><strong><a name="item_module"><strong>BUILD</strong> the module (sometimes unnecessary)</a></strong>

<dt><strong><a name="item_install_the_module_2e"><strong>INSTALL</strong> the module.</a></strong>

</dl>
<p>Here's how to perform each step for each operating system.  This is
&lt;not&gt; a substitute for reading the README and INSTALL files that
might have come with your module!</p>
<p>Also note that these instructions are tailored for installing the
module into your system's repository of Perl modules -- but you can
install modules into any directory you wish.  For instance, where I
say <code>perl Makefile.PL</code>, you can substitute <code>perl Makefile.PL
PREFIX=/my/perl_directory</code> to install the modules into
<code>/my/perl_directory</code>.  Then you can use the modules from your Perl
programs with <code>use lib &quot;/my/perl_directory/lib/site_perl&quot;;</code> or
sometimes just <code>use &quot;/my/perl_directory&quot;;</code>.  If you're on a system
that requires superuser/root access to install modules into the
directories you see when you type <code>perl -e &quot;print qq(@INC)&quot;</code>, you'll
want to install them into a local directory (such as your home
directory) and use this approach.</p>
<ul>
<li>
<p><strong>If you're on a Unix or Unix-like system,</strong></p>
<p>You can use Andreas Koenig's CPAN module
( <a href="http://www.cpan.org/modules/by-module/CPAN">http://www.cpan.org/modules/by-module/CPAN</a> )
to automate the following steps, from DECOMPRESS through INSTALL.</p>
<p>A. DECOMPRESS</p>
<p>Decompress the file with <code>gzip -d yourmodule.tar.gz</code></p>
<p>You can get gzip from <a href="ftp://prep.ai.mit.edu/pub/gnu/">ftp://prep.ai.mit.edu/pub/gnu/</a></p>
<p>Or, you can combine this step with the next to save disk space:</p>
<pre>
     gzip -dc yourmodule.tar.gz | tar -xof -</pre>
<p>B. UNPACK</p>
<p>Unpack the result with <code>tar -xof yourmodule.tar</code></p>
<p>C. BUILD</p>
<p>Go into the newly-created directory and type:</p>
<pre>
      perl Makefile.PL
      make test</pre>
<p>or</p>
<pre>
      perl Makefile.PL PREFIX=/my/perl_directory</pre>
<p>to install it locally.  (Remember that if you do this, you'll have to
put <code>use lib &quot;/my/perl_directory&quot;;</code> near the top of the program that
is to use this module.</p>
<p>D. INSTALL</p>
<p>While still in that directory, type:</p>
<pre>
      make install</pre>
<p>Make sure you have the appropriate permissions to install the module
in your Perl 5 library directory.  Often, you'll need to be root.</p>
<p>That's all you need to do on Unix systems with dynamic linking.
Most Unix systems have dynamic linking -- if yours doesn't, or if for
another reason you have a statically-linked perl, <strong>and</strong> the
module requires compilation, you'll need to build a new Perl binary
that includes the module.  Again, you'll probably need to be root.</p>
</li>
<li>
<p><strong>If you're running ActivePerl (Win95/98/2K/NT/XP, Linux, Solaris)</strong></p>
<p>First, type <code>ppm</code> from a shell and see whether ActiveState's PPM
repository has your module.  If so, you can install it with <code>ppm</code> and
you won't have to bother with any of the other steps here.  You might
be able to use the CPAN instructions from the &quot;Unix or Linux&quot; section
above as well; give it a try.  Otherwise, you'll have to follow the
steps below.</p>
<pre>
   A. DECOMPRESS</pre>
<p>You can use the shareware Winzip ( <a href="http://www.winzip.com">http://www.winzip.com</a> ) to
decompress and unpack modules.</p>
<pre>
   B. UNPACK</pre>
<p>If you used WinZip, this was already done for you.</p>
<pre>
   C. BUILD</pre>
<p>You'll need the <code>nmake</code> utility, available at
<a href="http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/nmake15.exe">http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/nmake15.exe</a>
or dmake, available on CPAN.
<a href="http://search.cpan.org/dist/dmake/">http://search.cpan.org/dist/dmake/</a></p>
<p>Does the module require compilation (i.e. does it have files that end
in .xs, .c, .h, .y, .cc, .cxx, or .C)?  If it does, life is now
officially tough for you, because you have to compile the module
yourself -- no easy feat on Windows.  You'll need a compiler such as
Visual C++.  Alternatively, you can download a pre-built PPM package
from ActiveState.
<a href="http://aspn.activestate.com/ASPN/Downloads/ActivePerl/PPM/">http://aspn.activestate.com/ASPN/Downloads/ActivePerl/PPM/</a></p>
<p>Go into the newly-created directory and type:</p>
<pre>
      perl Makefile.PL
      nmake test</pre>
<pre>
   D. INSTALL</pre>
<p>While still in that directory, type:</p>
<pre>
      nmake install</pre>
</li>
<li>
<p><strong>If you're using a Macintosh with &quot;Classic&quot; MacOS and MacPerl,</strong></p>
<p>A. DECOMPRESS</p>
<p>First, make sure you have the latest <strong>cpan-mac</strong> distribution (
<a href="http://www.cpan.org/authors/id/CNANDOR/">http://www.cpan.org/authors/id/CNANDOR/</a> ), which has utilities for
doing all of the steps.  Read the cpan-mac directions carefully and
install it.  If you choose not to use cpan-mac for some reason, there
are alternatives listed here.</p>
<p>After installing cpan-mac, drop the module archive on the
<strong>untarzipme</strong> droplet, which will decompress and unpack for you.</p>
<p><strong>Or</strong>, you can either use the shareware <strong>StuffIt Expander</strong> program
( <a href="http://www.aladdinsys.com/expander/">http://www.aladdinsys.com/expander/</a> )
in combination with <strong>DropStuff with Expander Enhancer</strong>
( <a href="http://www.aladdinsys.com/dropstuff/">http://www.aladdinsys.com/dropstuff/</a> )
or the freeware <strong>MacGzip</strong> program (
<a href="http://persephone.cps.unizar.es/general/gente/spd/gzip/gzip.html">http://persephone.cps.unizar.es/general/gente/spd/gzip/gzip.html</a> ).</p>
<p>B. UNPACK</p>
<p>If you're using untarzipme or StuffIt, the archive should be extracted
now.  <strong>Or</strong>, you can use the freeware <strong>suntar</strong> or <em>Tar</em> (
<a href="http://hyperarchive.lcs.mit.edu/HyperArchive/Archive/cmp/">http://hyperarchive.lcs.mit.edu/HyperArchive/Archive/cmp/</a> ).</p>
<p>C. BUILD</p>
<p>Check the contents of the distribution.
Read the module's documentation, looking for
reasons why you might have trouble using it with MacPerl.  Look for
<em>.xs</em> and <em>.c</em> files, which normally denote that the distribution
must be compiled, and you cannot install it &quot;out of the box.&quot;
(See <a href="#portability">PORTABILITY</a>.)</p>
<p>If a module does not work on MacPerl but should, or needs to be
compiled, see if the module exists already as a port on the
MacPerl Module Porters site ( <a href="http://pudge.net/mmp/">http://pudge.net/mmp/</a> ).
For more information on doing XS with MacPerl yourself, see
Arved Sandstrom's XS tutorial ( <a href="http://macperl.com/depts/Tutorials/">http://macperl.com/depts/Tutorials/</a> ),
and then consider uploading your binary to the CPAN and
registering it on the MMP site.</p>
<p>D. INSTALL</p>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?