通常情况下,我们会直接安装perl module到当前perl环境中,直接下载源码来安装即可。这里以perl 5.8.8 和DBI-1.57为例。
[root@rhel6164 perl]# wget ftp://ftp.tw.freebsd.org/pub/ports/distfiles/DBI-1.57.tar.gz //下载源码
[root@rhel6164 perl]# tar xzf DBI-1.57.tar.gz //解压
[root@rhel6164 DBI-1.57]# perl ./Makefile.PL && make && make install //编译和安装
安装perl module之后,在当前perl的目录下会生成相关module的文件,XXX/lib/site_perl/5.8.8/x86_64-linux XXX为perl的环境目录。FYI我这里使用的RHEL6 64bit的,如果是32bit的环境,就不是x86_64,而是i686。可以用下面简单的perl脚本去测试安装的module。
[root@rhel6164 perl]# cat test.pl
use DBI;
my $version = DBI->VERSION;
print "DBI version: $version\n";
[root@rhel6164 perl]# perl ./test.pl
DBI version: 1.57
[root@rhel6164 perl]# wget ftp://ftp.tw.freebsd.org/pub/ports/distfiles/DBI-1.57.tar.gz //下载源码
[root@rhel6164 perl]# tar xzf DBI-1.57.tar.gz //解压
[root@rhel6164 DBI-1.57]# perl ./Makefile.PL PREFIX=XXX //指定安装perl module的路径
<pre name="code" class="plain">[root@rhel6164 DBI-1.57]# make && make install //编译和安装
这种安装之后如果要使用perl module就要设置PERL5LIB变量。
[root@rhel6164 perl]# export PERL5LIB=XXX/lib/site_perl/5.8.8/x86_64-linux:$PERL5LIB //XXX为module的安装路径
[root@rhel6164 perl]# perl ./test.pl
DBI version: 1.57