Centos7.2 安装perl环境

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/backkom_jiu/article/details/79240821

Centos7.2 安装perl环境

1、运行环境

  • [x] centos7.2
  • [x] 腾讯云
  • [x] lnmp

2、操作背景

应工作需要,某一软件需要perl的一些模块支持

但是由于centos自带的perl版本与需求不服

所以进行perl环境的安装

3、安装步骤

3.1 perl安装

3.11 安装

 # 下载安装包
 wget http://search.cpan.org/CPAN/authors/id/S/SH/SHAY/perl-5.26.1.tar.gz


 # 解包
 tar -zxvf perl-5.26.1.tar.gz
 # 进入文件目录
 cd perl-5.26.1
 #   
 ./Configure -des -Dprefix=/usr/local/perl

# 编译
make && make test
# 如出现All tests successful,可放心下一步

# 安装
make install

3.12 重定向

# 上一步完成基本代表着你已经把相关的perl安装成功
# 但是系统默认的还是原来的perl,所以我们要建立软连接

# 当前perl
perl -v

This is perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux-thread-multi
(with 29 registered patches, see perl -V for more detail)

Copyright 1987-2012, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

# 修改链接
# 不建议删除,还是备份比较好
mv /usr/bin/perl /usr/bin/perl.bak
# 建立软连接
ln -s /usr/local/perl/bin/perl /usr/bin/perl

# 查看当前perl
perl -v

This is perl 5, version 26, subversion 1 (v5.26.1) built for x86_64-linux

Copyright 1987-2017, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

3.2 perl模块安装

以Net::SNMP模块为例

3.2.1 手动安装

# 下载安装包
wget http://search.cpan.org/CPAN/authors/id/D/DT/DTOWN/Net-SNMP-v6.0.1.tar.gz

# 解压
tar -zxvf Net-SNMP-v6.0.1.tar.gz

# 编译安装
cd Net-SNMP-v6.0.1

perl Makefile.PL

make && make test

make install


# 特别注意
# 有一些模块使用Build.PL,可以通过readme进行查看
# 手动安装一定要先把依赖检测一下,先安装依赖

3.2.2 cpan安装

使用Perl自带的模块——CPAN.pm模块

perl -MCPAN -e shell

# 第一次进入选站点
Terminal does not support AddHistory.

cpan shell -- CPAN exploration and modules installation (v2.18)
Enter 'h' for help.

cpan[1]> install Net::SNMP

or

perl -MCPAN -e 'install Net::SNMP'

3.3 常见错误

3.3.1 wget未安装

# 例:
wget command not found

解决方法:
yum -y install wget

3.3.2 gcc未安装

运行会提示带有cc的语句,因为我的环境一般都安装了gcc,也就不举例了

解决方法:
yum -y install gcc

3.3.3 cpan未安装

Can't locate CPAN.pm in @INC (@INC contains: /usr/local/lib/perl5 /usr/local/share/perl5 /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5 /usr/share/perl5 .).
BEGIN failed--compilation aborted.

解决方法:
- yum -y install perl-CPAN
- 手动安装,版本要合适,步骤如上Net::SNMP

3.3.4 依赖未安装

# 例如
Checking prerequisites...
  recommends:
    *  Crypt::DES is not installed
    *  Crypt::Rijndael is not installed
    *  Digest::HMAC is not installed
    *  Digest::SHA1 is not installed
    *  Socket6 is not installed

解决方法:
- 安装依赖模块
- 使用强制安装
- 用cpan进行安装

猜你喜欢

转载自blog.csdn.net/backkom_jiu/article/details/79240821