各种平台下Perl模块的安装方法

各种平台下Perl模块的安装方法,第1张

概述Perl到了第五版增加了模块的概念,用来提供面向对象编程的能力。这是Perl语言发展史上的一个里程碑。此后,广大自由软件爱好者开发了大量功能强大、构思精巧的Perl模块,极大地扩展了Perl语言的功能。CPAN(Comprehensive Perl Archive Network)是internet上Perl模块最大的集散地,包含了现今公布的几乎所有的perl模块。      几个主要的CPAN站

Perl到了第五版增加了模块的概念,用来提供面向对象编程的能力。这是Perl语言发展史上的一个里程碑。此后,广大自由软件爱好者开发了大量功能强大、构思精巧的Perl模块,极大地扩展了Perl语言的功能。CPAN(Comprehensive Perl Archive Network)是internet上Perl模块最大的集散地,包含了现今公布的几乎所有的perl模块。 

    几个主要的CPAN站点有: 

    国内:ftp://freesoft.cgi.gov.cn/pub/languages/perl/CPAN 

          http://cpan.qz.fj.cn/ 

    国外:http://www.cpan.org/ 

          http://www.perl.com/CPAN-local/ 

  我在这里介绍一下各种平台下perl模块的安装方法。以安装DBI模块为例。 

1、linux/Unix下的安装方法: 

  linux/Unix下安装Perl模块有两种方法:手工安装和自动安装。第一种方法是从CPAN上下载您需要的模块,手工编译、安装。第二种方法是联上internet,使用一个叫做CPAN的模块自动完成下载、编译、安装的全过程。 

a、手工安装的步骤: 

从CPAN下载了DBI模块1.13版的压缩文件DBI-1.13.tar.gz,假设放在/usr/local/src/下。 

cd /usr/local/src 

解压缩这个文件: 

tar xvzf DBI-1.13.tar.gz 

这时会新建一个DBI-1.13的目录。 

cd DBI-1.13 

生成makefile: 

perl Makefile.PL 

建立模块 

make 

测试模块 

make test 

如果测试结果报告“all test ok”,您就可以放心地安装编译好的模块了。安装模块前,先要确保您对perl5安装目录有可写权限(通常以su命令获得),执行: 

make install 

现在,写个程序试试吧。 

#!/usr/bin/perl -w 

use strict; 

use DBI; 

.. 

 

  上述步骤适合于linux/Unix下绝大多数的Perl模块。可能还有少数模块的安装方法略有差别,所以最好先看看安装目录里的README或INSTALL。另外,上述过程是针对动态链接的Perl编译器(所有linux下预安装的Perl都是动态链接的),如果您在使用一个静态链接的Perl,您需要将新的模块静态链接到perl编译器中,可能还需要重启机器。 

 

b、使用CPAN模块自动安装: 

安装前需要先联上线,并且您需要取得root权限。 

perl -MCPAN -e shell 

初次运行CPAN时需要做一些设置,如果您的机器是直接与internet相联(拨号上网、专线,etc.),那么一路回车就行了,只需要在最后选一个离您最近的CPAN镜像站点。例如我选的是位于国内的中国自由软件库ftp://freesoft.cgi.gov.cn/pub/languages/perl/CPAN 。否则,如果您的机器位于防火墙之后,还需要设置ftp代理或http代理。 

获得帮助 

cpan>h 

列出CPAN上所有模块的列表 

cpan>m 

安装模块 

cpan>install DBI 

自动完成DBI模块从下载到安装的全过程。 

退出 

cpan>q 

 

2、Win32下的安装方法: 

  在Win32下,建议使用ActiveState的Perl for Win32,即ActivePerl。ActivePerl的主页在: 

http://www.activestate.com/ 。在Win32下,最好也使用专门为ActivePerl定制的Perl模块。从CPAN下载的Perl模块不能很好地在ActivePerl下使用。类似于CPAN模块,ActiveState也开发了一个自动安装工具叫做PPM(Perl Package Manager)。 

最通常的安装方法是: 

首先联上线 

在dos命令行下启动ppm 

ppm 

获得帮助 

PPM>h 

列出ActiveState站点上所有为Perl模块的清单。 

PPM>search 

安装模块 

PPM>install DBI 

自动完成DBI模块从下载到安装的全过程。 

退出 

PPM>q 

如果您的机器位于防火墙之后,通过http代理上网,那么可以使用下面的方法。 

对于老的基于perl 5.005的ActivePerl版本(ActivePerl 522以下版本,不包括ActivePerl 522),从http://www.ActiveState.com/ppmpackages/5.005/zips/下载您需要的Perl模块,例如DBI.zip。 

将其解压缩在C:/TEMP/DBI下 

cd /TEMP/DBI 

ppm install DBI.PPD 

最新的基于perl 5.6的ActivePerl版本(ActivePerl 613及以上版本)的安装方法略有不同。安装ActivePerl 613前需要先安装Microsoft的windows Installer。 

windows Installer从这里下载: 

http://activestate.com/download/contrib/Microsoft/9x/InstMsi.exe 

ActivePerl 613从这里下载: 

http://activestate.com/download/ActivePerl/Windows/5.6/ActivePerl-5.6.0.613.msi 

对于基于perl 5.6的ActivePerl版本,从 

http://www.activestate.com/PPMPackages/5.6/ 

下载您需要的Perl模块的安装描述文件,例如DBI.PPD 

安装模块前需要先联上线 

ppm install DBI.PPD。

perl模块的卸载方法:

所谓库其实就是一个.pm文件,执行:

perl -e 'print join "/n",@INC'

会print出所有模块和库的安装目录,到这些目录下找到相应pm文件,删除掉就可以了。

列出具体的pm文件,执行:

perl -Mfile::Find -le 'finddepth({wanted=>sub{print $_ if//.pm$/},no_chdir=>1},@INC)'

搜索你需要卸载的模块,如:

perl -Mfile::Find -le 'finddepth({wanted=>sub{print $_ if//.pm$/},@INC)' |grep 'GD'

然后删除就ok了。

perldoc -l GD  也可以返回GD模块的地址。

或者

% perl -MCGI -e 'print $INC{"CGI.pm"}'

各种平台下Perl模块的安装方法

[root@test]# perl -MCPAN -e 'install Time::HiRes'

[root@test]# perl -MCPAN -e 'install file::Tail'

[root@test]# perl -MCPAN -e 'install Date::Parse'

[root@test]# perl -MCPAN -e 'install Net::Netmask'

What to do once you’ve downloaded A Module from the CPAN

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:

·       DECOMPRESS the file

·       UNPACK the file into a directory

·       BUILD the module (sometimes unnecessary)

·       INSTALL the module.

Here's how to perform each step for each operating system. This is not a substitute for reading the README and INSTALL files that might have come with your module!

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 perl Makefile.PL,you can substitute perl Makefile.PL PREFIX=/my/perl_directory to install the modules into /my/perl_directory. Then you can use the modules from your Perl programs with use lib "/my/perl_directory/lib/site_perl"; or sometimes just use "/my/perl_directory";.

1.                            If you're on Unix,

(You can use Andreas König's CPAN module to automate the entire process,from DECOMPRESS through INSTALL.)

A. DECOMPRESS

Decompress the file with gzip -d yourmodule.tar.gz

You can get gzip from @L_502_12@.

Or,you can combine this step with the next to save disk space:

gzip -dc yourmodule.tar.gz | tar -xof -

B. UNPACK

Unpack the result with tar -xof yourmodule.tar

C. BUILD

Go into the newly-created directory and type:

perl Makefile.PL

make

make test

D. INSTALL

While still in that directory,type:

make install

Make sure you have the appropriate permissions to install the module in your Perl 5 library directory. Often,you'll need to be root.

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,and 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.

2.    If you're running windows 95 or NT with the ActiveState port of Perl,

A. DECOMPRESS

You can use WinZip (shareware) to decompress and unpack modules.

B. UNPACK

If you used WinZip,this was already done for you.

C. BUILD

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,you're on your own. You can try compiling it yourself if you have a C compiler. If you're successful,consIDer uploading the resulting binary to the CPAN for others to use. If it doesn't,go to INSTALL.

D. INSTALL

copy the module into your Perl's lib directory. That'll be one of the directorIEs you see when you type perl -e "print qq(@INC)".

3.                            If you're running windows 95 or NT with the core Windows distribution of Perl,

A. DECOMPRESS

When you download the module,make sure it ends in either .tar.gz or .zip. windows browsers sometimes download .tar.gz files as _tar.tar,because early versions of windows prohibited more than one dot in a filename.

You can use WinZip (shareware) to decompress and unpack modules.

Or,you can use InfoZIP's unzip utility to uncompress .zip files; type unzip yourmodule.zip in your shell.

Or,if you have a working tar and gzip,you can type

gzip -cd yourmodule.tar.gz | tar xvf -

in the shell to decompress yourmodule.tar.gz. This will UNPACK your module as well.

B. UNPACK

All of the methods in DECOMPRESS will have done this for you.

C. BUILD

Go into the newly-created directory and type:

perl Makefile.PL

dmake

dmake test

Depending on your perl configuration,dmake might not be available. You might have to substitute whatever perl -V:make says. (Usually,that will be nmake or make.)

D. INSTALL

While still in that directory,type:

dmake install

4.    If you're using a Macintosh,

A. DECOMPRESS

You can either use Stuffit Expander in combination with DropStuff with Expander Enhancer (shareware),or MacGzip(freeware).

B. UNPACK

If you're using DropStuff or Stuffit,you can just extract the tar archive. Otherwise,you can use suntar (freeware).

C. BUILD

Does the module require compilation?

1. If it does,

OvervIEw: You need MPW and a combination of new and old CodeWarrior compilers for MPW and librarIEs. Makefiles created for building under MPW use the Metrowerks compilers. It's most likely possible to build without other compilers,but it has not been done successfully,to our kNowledge. Read the documentation in MacPerl: Power And Ease on porting/building extensions,or find an existing @R_403_3013@ binary,or hire someone to build it for you.

Or,ask someone on the mac-perl mailing list to build it for you. To subscribe to the mac-perl mailing List,send mail tomac-perl-request@iis.ee.ethz.ch.

2. If the module doesn't require compilation,go to INSTALL.

D. INSTALL

Make sure the newlines for the modules are in Mac format,not Unix format. Move the files manually into the correct folders.

Move the files to their final destination: This will most likely be in $ENV{MACPERL}site_lib: (i.e.,HD:MacPerl folder:site_lib:). You can add new paths to the default @INC in the Preferences menu item in the MacPerl application ($ENV{MACPERL}site_lib: is added automagically). Create whatever directory structures are required (i.e.,for Some::Module,create $ENV{MACPERL}site_lib:Some: and put Module.pm in that directory).

Run the following script (or something like it):

  #!perl -w

  use autoSplit;

  my $dir = "${MACPERL}site_perl";

  autosplit("$dir:Some:Module.pm","$dir:auto",1,1);

Eventually there should be a way to automate the installation process; some solutions exist,but none are ready for the general public yet.

5.    If you're on DOS (the DJGPP port),

A. DECOMPRESS

djtarx will both uncompress and unpack.

B. UNPACK

See above.

C. BUILD

Go into the newly-created directory and type:

perl Makefile.PL

make

make test

You will need the packages mentioned in Readme.dos in the Perl distribution.

D. INSTALL

While still in that directory,type:

make install

You will need the packages mentioned in Readme.dos in the Perl distribution.

6.    If you're on OS/2,

Get the EMX development suite and gzip/tar,from either Hobbes or LEO,and then follow the instructions for Unix.

7.    If you're on VMS,

When downloading from CPAN,save your file with a .tgz extension instead of .tar.gz. All other periods in the filename should be replaced with underscores. For example,Your-Module-1.33.tar.gz should be downloaded as Your-Module-1_33.tgz.

A. DECOMPRESS

Type

gzip -d Your-Module.tgz

or,for zipped modules,type

unzip Your-Module.zip

Executables for gzip,zip,and VMStar: Alphas, Vaxen.

gzip and tar are also available at ftp://ftp.digital.com/pub/VMS.

Note that GNU's gzip/gunzip is not the same as Info-ZIP's zip/unzip package. The former is a simple compression tool; the latter permits creation of multi-file archives.

B. UNPACK

If you're using VMStar:

VMStar xf Your-Module.tar

Or,if you're fond of VMS command Syntax:

tar/extract/verbose Your_Module.tar

C. BUILD

Make sure you have MMS (from Digital) or MMK (freeware from MadGoat). Then type this to create the DESCRIP.MMS for th emodule:

perl Makefile.PL

Now you're ready to build:

mms

mms test

Substitute mmk for mms above if you're using MMK.

D. INSTALL

Type

mms install

Substitute mmk for mms above if you're using MMK.

8.    If you're on MVS,

Introduce the .tar.gz file into an HFS as binary; don't translate from ASCII to EBCDIC.

A. DECOMPRESS

Decompress the file with gzip -d yourmodule.tar.gz

You can get gzip from http://www.s390.ibm.com/products/oe/bpxqp1.html.

B. UNPACK

Unpack the result with

pax -o to=IBM-1047,from=ISO8859-1 -r < yourmodule.tar

The BUILD and INSTALL steps are IDentical to those for Unix. Some modules generate Makefiles that work better with GNU make,which is available from http://www.mks.com/s390/gnu/index.htm.

 


 

If you have any suggested changes for this page, let me know. Please don't send me mail asking for help on how to install your modules. There are too many modules,and too few Orwants,for me to be able to answer or even ackNowledge all your questions. Contact the module author instead,or post to comp.lang.perl.modules,or ask someone familiar with Perl on your operating system.

Jon Orwant

The Perl Journal

with invaluable help from Brandon Allbery,Charles Bailey,Graham barr,Dominic Dunlop,Jarkko HIEtanIEmi,Ben Holzman,Tom Horsley,Nick Ing-Simmons,Tuomas J. Lukka,Laszlo Molnar,Chris Nandor,Alan olsen,Peter Prymmer,Gurusamy Sarathy,Christoph Spalinger,Dan Sugalski,Larry Virden,and Ilya Zakharevich.

© 1998 Jon Orwant. All Rights Reserved. This file may be copIEd and distributed under the same terms as Perl itself.

 

perl 的编译安装

http://www.webjx.com  更新日期:2005-02-26 23:07  出处:网页教学网  作者:

perl 的源码安装相当简单,而 perl 5.84 的安装最快就是以下方式

rm -f config.sh Policy.sh

sh Configure -de

make

make test

make install

RedHat 发行的高级服务器版,这个加了升级包的 linux 比较成熟而安全,服务器上预安装是  perl 5.80  版本,perl 解释器是在  /usr/bin/perl  而库文件在  /usr/lib/perl5/perl5.8.0/ 目录下

我们直接从  http://www.cpan.org  下载 最新的发行版  5.84 文件是  stable.tar.gz 我们下载后传到 /usr/local/ 目录下

2. 解开源码

tar xfzv  ./stable.tar.gz

解开后是一个新目录 /usr/local/perl5.8.4

我们作一个符号连接  ln -s /usr/local/perl5.8.4 /usr/local/perl

下面我们的安装就在 /usr/local/perl 目录中进行 

cd /usr/local/perl

注: 如果你想安装一份完整的 perl 执行程序,也可以新建一个目录  mkdir /usr/local/perl

3. 下面是配置 perl 源码

    ./Configure -des -Dprefix=/usr/local/perl -Dusethreads -Uinstalluserbinperl

注1:在老式的安装配置中 还有一个先项是 -Duse5005threads 这是使用 perl 5.005 版本老式的 多线程,而在 新版 DBI 1.2 后,不再支持 5.005 多线程,所以,我们取消这一项

注2: -Dprefix=/usr/local/perl 是指定安装目录

4. 编译与安装

 make && make install

一般情况下,到这里已经安装完成。

5. 替换原 perl

 最后,为了让原来的 perl / CGI 程序可以使用新版本 perl ,我们需要修改原 perl

 

  cd /usr/bin

  mv perl perl.5.8.0

  ln -s /usr/local/perl/perl /usr/bin/perl

注1: mv perl perl.5.8.0 这是把原来的 perl 改名

注2: ln -s /usr/local/perl/perl  /usr/bin/perl 这是作一个符号连接,让代码里使用  #!/usr/bin/perl 可以直接不用修改

6. 安装必要的模块,如 DBI / CGI 等

    perl -MCPAN -eshell

  直接按提示配置好 cpan 后,我们就可以安装需要的模块了

   install DBI

   install CGI

   install Apache::DBI

当然,还有一些模块,如 DBD::MysqL ,需要手动安装

   到这里,我们的安装已经完成

  perl -V 可以检查到已经是最新版

注:  perl 安装在 /usr/local/perl 目录下, 相应的 pm 模块文件目录已经改变,原来安装过的模块最好是重新安装,特别是需要编译的模块,如 DBI 等,而纯 perl 模块而不需要。

总结

以上是内存溢出为你收集整理的各种平台下Perl模块的安装方法全部内容,希望文章能够帮你解决各种平台下Perl模块的安装方法所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1289654.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存