Perl 7 - 使用 Perlbrew 管理perl 版本

Perlbrew是一个工具,允许用户在自己的家目录中安装和管理多个Perl版本,无需root权限。它可以用来试验新版本的Perl,安装CPAN模块,且不会影响系统级别的Perl环境。安装过程包括下载安装脚本、初始化环境和安装特定Perl版本。此外,Perlbrew还支持切换Perl版本、安装cpanm以及执行特定Perl环境的程序。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入图片描述



关于 Perlbrew


相关文档:


Perlbrew 是一个工具,用于管理您$HOME 目录(或您指定的任何位置)中的多个perl安装。
它们是完全孤立的 perl 环境,与系统perl没有关系,彼此之间也没有关系。

有以下好处:

  • 不再需要运行sudo来安装CPAN模块。
  • 轻松尝试每月发布的新perl,并学习新的语言特性。
  • 针对不同的perl版本测试代码。
  • 在使用verndor perl(操作系统自带的)运行应用程序时,避免一些常见的危险,例如:
  • 供应商perl通常有自己的用途,把它弄得太乱可能是个坏主意。升级供应商提供的CPAN模块可能已经是一个坏主意。
  • 升级供应商perl通常伴随着它附带的所有CPAN模块的升级——这可能不是期望的。
  • 一些供应商介绍了他们自己的perl错误,两次!
  • 用于破解perl内部,因此需要在perl .git中安装来自特定提交的多个版本
  • 可以只是为了跟上潮流,一直使用最新的perl版本。

安装 Perlbrew

# 下载安装 
curl -L https://install.perlbrew.pl | bash

# 激活
source ~/perl5/perlbrew/etc/bashrc

Perlbrew 安装包地址:~/perl5/perlbrew/bin/perlbrew


# 查看版本
perlbrew --version
# /Users/xx/perl5/perlbrew/bin/perlbrew  - App::perlbrew/0.97

# 查看帮助
perlbrew -h

# 查看更详细的帮助
perlbrew help

Usage:
    perlbrew command syntax:

        perlbrew <command> [options] [arguments]

    Commands:

        init           Initialize perlbrew environment.
        info           Show useful information about the perlbrew installation

        install        Install perl
        uninstall      Uninstall the given installation
        available      List perls available to install
        lib            Manage local::lib directories.
        alias          Give perl installations a new name
        upgrade-perl   Upgrade the current perl

        list           List perl installations
        use            Use the specified perl in current shell
        off            Turn off perlbrew in current shell
        switch         Permanently use the specified perl as default
        switch-off     Permanently turn off perlbrew (revert to system perl)
        exec           Execute programs with specified perl environments.

        list-modules   List installed CPAN modules for the current Perl version in use
        clone-modules  Re-installs all CPAN modules from one installation to another

        self-install       Install perlbrew itself under PERLBREW_ROOT/bin
        self-upgrade       Upgrade perlbrew itself.

        install-patchperl  Install patchperl
        install-cpanm      Install cpanm, a friendly companion.
        install-cpm        Install cpm, a faster but still friendly companion.
        install-multiple   Install multiple versions and flavors of perl

        download       Download the specified perl distribution tarball.
        clean          Purge tarballs and build directories
        version        Display version
        help           Read more detailed instructions

    Generic command options:

        -q --quiet     Be quiet on informative output message.
        -v --verbose   Tell me more about it.

    See `perlbrew help` for the full documentation of perlbrew, or

    See `perlbrew help <command>` for detail description of the command.


使用 perlbrew 安装/管理 perl 版本

1、查看可安装的 perl 版本

perlbrew available

得到如下版本信息:

# perl
   perl-5.38.0   
   perl-5.36.1   
   perl-5.34.1   
   perl-5.32.1   
   ... 
    perl-5.6.2   


# cperl


2、 安装 perl

perlbrew install perl-5.36.1

安装最新的版本

perlbrew install perl-blead

如果安装失败,可执行下面代码来升级 patchperl

perlbrew install-patchperl

查看已安装的 perl

perlbrew list
# * perl-5.32.0   

3、切换 perl

# 切换到 perl-5.36.1 
perlbrew switch perl-5.36.1

# 在当前 shell 临时使用
perlbrew use perl-blead

4、运行测试

perlbrew exec perl myprogram.pl

perlbrew exec -- perl -E 'say $]'
# 5.032000

5、退出 perlbrew
可返回使用系统 perl

perlbrew off

使用 perlbrew switch 可继续切换为使用 perlbrew


安装 CPAN 模块

perlbrew install-cpanm

# 使用 cpanm 命令安装 CPAN 模块:
cpanm CGI::simple

2023-07-10(一)晴天

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

编程乐园

请我喝杯伯爵奶茶~!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值