2.3. Installing Perl
Most likely, your system administrator is responsible for installing and upgrading Perl. But if you are the system administrator, or you want to install Perl on your own system, sooner or later you will find yourself installing a new version of Perl.
TIP: If you run Perl and plan on upgrading to the latest distribution, be aware that pre-5.005 Perl extensions are not compatible with 5.6 and later. This means that you must rebuild and reinstall any dynamically loaded extensions you built under Perl distributions earlier than 5.005. If you're building under a Unix variant that's running Perl 5.005, choose the Configure option for 5.005 compatibility.
Specific installation instructions come in the README and INSTALL files of the Perl distribution kit. If you don't already have the Perl distribution, you can download it from CPAN—the latest Unix distribution is in stable.tar.gz. The information in this section is an overview of the installation process. The gory details are in the INSTALL file, which you should look at before starting, especially if you haven't done an installation before. Note that operating systems other than Unix may have special instructions; if so, follow those instructions instead of what's in this section or in INSTALL. Look for a file named README.xxx, in which xxx represents your operating-system type.
In addition to Perl itself, the standard distribution includes a set of core modules that are automatically installed with Perl. See Section 2.4, "Getting and Installing Modules" later in this chapter to learn how to install modules that are not bundled with Perl; Chapter 8, "Standard Modules" describes the standard modules in some detail.
2.3.1. Installing on Unix
Typically, the Perl kit will be packed as either a tar file or a set of shar (shell archive) scripts; in either case, the file will be in a compressed format. If you got your version of Perl directly from CPAN, it is probably in "tar-gzipped" format; tar and gzip are popular Unix data-archiving formats. In any case, once you've downloaded the distribution, you need to uncompress and unpack it. The filename indicates the kind of compression that was used. A .Z extension indicates you need to uncompress the file first, while a .gz extension indicates you need to gunzip the file. You then unpack the file as appropriate, read the README and INSTALL files, and run a massive shell script called Configure, which tries to figure out everything about your system and creates the file Config.pm to store the information. After this is done, you do a series of "makes" to find header file dependencies, to compile Perl (and a2p, which translates awk scripts to Perl), to run regression tests, and to install Perl in your system directories.
If you opt to build your own Perl under Win32, you will find that the Perl source kit is also shipped in zip format, which you can easily extract with pkunzip or Winzip (www.winzip.com).
If you're building Perl under Unix, it is likely that your architecture and development environment is supported by Configure. You shouldn't have any problems with the build process or running the test suite. One common problem is not making sure that Perl is linked against all the libraries it needs to build correctly. Also, you should say "yes" when Configure asks if you want dynamic loading, if your system supports it. Otherwise, you won't be able to install modules that use XS, which provides an interface between Perl and C.
If you are running Linux, and you've installed Perl from a tarball (or rpm package), you should make sure everything is there; one way to do that is to check the Config.pm file. If MakeMaker is not correctly installed, you might need to build Perl yourself.
It's possible you'll get a compiled (binary) copy of Perl, rather than the source. In that case, make sure you get suidperl, a2p, s2p, and the Perl library routines. Install these files in the directories that your version was compiled for. Note that binary distributions of Perl are made available because they're handy, not because you are restricted from getting the source and compiling it yourself. The people who give you the binary distribution ought to provide you with some form of access to the source, if only a pointer to where they got the source. See the Copying file in the distribution for more information.
126.96.36.199. Perl examples
The Perl source distribution comes with some sample scripts in the eg/ subdirectory. Feel free to browse among them and use them. They are not installed automatically, however, so you need to copy them to the appropriate directory and possibly fix the #! line to point to the right interpreter.
The files in the t/ and lib/ subdirectories, although arcane in spots, can also serve as examples.
Since Perl is constantly being honed and improved, patches are sometimes made available through CPAN. Your distribution is likely to have had most of the patches applied already—run perl -v to check the patch level of your distribution. Patches are sent out with complete instructions on how to apply them using patch, which is available from the GNU project.
2.3.2. Installing on Win32
You need to obtain and install a copy of Perl yourself, unless you have had the good fortune of having either a system administrator install Perl on your system or access to a set of development tools to compile the Perl distribution.
The official precompiled Perl distribution for Win32 is ActivePerl, which is developed by ActiveState Tool Corporation (www.activestate.com). You'll find that ActivePerl is quite complete, down to the availability of such modules as Win32 and mod_perl.
When Perl 5.005 was released, Perl developers could build their own Perl for Win32 from the same source kit that their Unix counterparts used. In addition, the Perl build mechanism for Win32 began to support more than just commercial development toolkits, such as Microsoft's Visual C++. A Perl developer who wanted to build the Perl source kit with a free development toolkit could build Perl with Cygwin (www.cygnus.com), a Unix layer on top of Win32, or Mingw32 (www.mingw.org) with dmake, a set of Win32 runtime libraries that provide a Unix emulation under native Win32.
TIP: Unless there's something specific that you gain by building your own Perl for Win32, then you should use the Activestate build, ActivePerl.
The canonical source for the ActivePerl distribution at the time of this writing is at http://aspn.activestate.com/ASPN/Downloads/ActivePerl/. Included in the distribution are:
The ActivePerl binary comes as a self-extracting executable that uses the standard Win32 InstallShield setup wizard to guide you through the installation process. By default, Perl is installed into the directory C:\Perl\version, in which version is the current version number (e.g., 5.005). (For information on customizing your installation, see the Win32 FAQ on the ActiveState web site.) The installation also associates the file extension .pl with Perl and adds the directory into which you installed Perl to your PATH environment variable.
If you want to install ActivePerl, you can do so by running the MSI archive that's shipped by ActiveState. If the MSI archive is not associated with the MSI application, you need to obtain InstMsi.exe from the downloads section at www.microsoft.com.
If you don't (or can't) install MSI on your system, ActiveState has made available a Perl installer that doesn't use MSI, but be aware that this installer doesn't have a corresponding de-installer.
188.8.131.52. Standard Perl distribution
The standard Perl distribution is available from CPAN, where you'll find binary and source distributions for the current version of Perl. The source distributions come as .tar.gz files, which you can extract using a utility that supports gzip files, tar files, and long filenames. Ports of both GNU gzip and tar are available for the various Win32 platforms, or you can use a graphical zip archive program such as WinZip. Make sure you preserve the directory structure when you unpack the distribution.
To install from the source, you need the Microsoft Visual C++ compiler, the Borland C++ compiler, or Mingw32 with EGCS gcc-2.95.X. If you're using Cygwin32, do not try to build Perl in the win32 subdirectory. Instead, you should run Configure in the src directory as you would when building under a Unix platform. You also need a make utility. Microsoft Visual C++ comes with nmake, or you can use dmake.
Once you have the distribution, start by reading the file README.win32. Next, edit the file Makefile in the win32 subdirectory of the distribution and make sure that you're happy with the values for the install drive and directory. Then execute the following commands from the win32 subdirectory of the distribution to build, test, and install the distribution. This example assumes that you have the proper environment variables (LIB, INCLUDE, etc.) set up for your compiler and that nmake is your make program.
C:\> nmake Build all of Perl C:\> nmake test Test your distribution C:\> nmake install Install to target directory, as specified in the Makefile
TIP: If you're running Mingw32, you'll use dmake, since nmake is part of commercial development suites—such as Microsoft Visual C++—and is not available separately.
Assuming everything is now built correctly, you just need to add the bin subdirectory of the installation target directory to your path or to your operating environment under Microsoft server platforms such as Windows NT. For example, if you installed the Perl distribution to C:\Perl, you'll want to add the directory containing perl.exe (e.g., C:\Perl\bin) to your path.
Finally, you should restart your machine so the environment changes take effect, and you're ready to go. This is of particular importance if you're running Perl under Windows 95, 98, or ME.
WARNING: Windows 95/98 users can expect significantly different functionality from their Perl distribution than Windows NT users. For various reasons, some of the Win32 modules don't work on Windows 95/98. The functionality required to implement them may be missing on Windows 95/98, or bugs in Windows 95 may prevent them from working correctly.
Copyright © 2002 O'Reilly & Associates. All rights reserved.