Linux 中间件 | Perl 及 Perl 模块安装

Perl 作为脚本语言,应用范围也比较广泛。

本文环境,Amazon Linux release 2,全程用 root 用户。

Perl 安装

一、通常系统会自带,先确认一下 rpm -qa | grep perl

二、没有自带,或者版本不满足,可手动安装

  • 官网下载需要的版本,后续步骤改成自己下载的名字

    wget https://www.cpan.org/src/5.0/perl-5.16.3.tar.gz

  • 解压

    tar zxvf perl-5.16.3.tar.gz

  • 进入解压后的目录

    cd perl-5.16.3

  • 编译

    ./Configure -des -Dprefix=/usr/local/lib64/perl5 -Dusethreads -Uversiononly

    make

    make install

  • 覆盖旧命令或创建新命令文件

    # 找到旧命令
    which perl
    whereis perl
    
    # 新安装的 perl 命令文件覆盖掉旧文件
    # 根据自己的实际情况调整
    cp -p /usr/local/perl/bin/perl /usr/bin/perl
    
    
  • 确认安装的 Perl 信息

    perl -v

    This is perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux-thread-multi
    (with 44 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.
    

模块安装

一、确认已经安装的模块

perldoc -t perllocal | grep Module

二、安装

CPAN 自动安装

perl -MCPAN -e shell
  • 然后一路回车,

  • 最后一步选一个离自己近的 CPAN 镜像站点。

  • 最后出现 cpan>

  • 注意防火墙

  • 安装模块,同时会安装依赖模块

    # 例:安装 Jcode 模块
    
    # install 会自动下载并解压安装包
    
    # 安装包解压在 ~/.cpan/build/ 目录
    
    cpan>install Jcode
    

常用 CPAN 命令

  • cpan>help 查看帮助文档

  • cpan>d <module name> 查看模块

  • cpan>install <module name> 安装模块

  • cpan>quit 退出 cpan


手动安装

有时候自动安装没有成功,又不好解决,可以尝试手动安装

  • CPAN 下载安装包,或者从 ~/.cpan/build/ 目录找到已经解压好的模块包

  • 下载解压,进入解压后的目录后·,编译安装

    perl Makefile.PL
    make
    make install
    
  • 有些模块需要下面这种方式编译安装

    perl Build.PL
    ./Build
    ./Build install
    

三、使用过程中的 QA

Q1:Can't load '/usr/local/lib64/perl5/auto/Pg/Pg.so' for module Pg: libpq.so.5: cannot open shared object file: No such file or directory at /usr/lib64/perl5/DynaLoader.pm line 190. at top.pl line 7. 
Compilation failed in require at top.pl line 7.
BEGIN failed--compilation aborted at top.pl line 7.

A1:# ln -s /usr/local/pgsql/lib/libpq.so.5 /usr/lib64/libpq.so.5


posted @ 2023-03-23 12:39  菜乌  阅读(1444)  评论(0编辑  收藏  举报