当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 在 Red Hat Enterprise Linux (RHEL) 上安装 PowerShell

作者:精品下载站 日期:2024-12-14 03:06:47 浏览:14 分类:玩电脑

在 Red Hat Enterprise Linux (RHEL) 上安装 PowerShell


所有包都可以在我们的 GitHub 发布页面上找到。安装之前,请检查下面支持的版本列表。安装软件包后,从终端运行 pwsh。如果您安装了预览版,请运行 pwsh-preview

笔记

PowerShell 7.4 是一项就地升级,删除了以前版本的 PowerShell 7。PowerShell 预览版本可以与其他版本的 PowerShell 并行安装。如果需要与以前的版本并行运行 PowerShell 7.4,请使用二进制存档方法重新安装以前的版本。

RHEL 7 使用 yum,RHEL 8 及更高版本使用 dnf 包管理器。

通过包存储库安装

Microsoft 为 Linux 系统构建并支持各种软件产品,并通过 Linux 打包客户端(apt、dnf、yum 等)提供它们。这些 Linux 软件包托管在 Microsoft 产品的 Linux 软件包存储库 (https://packages.microsoft.com,也称为 PMC) 上。

从 PMC 安装 PowerShell 是首选安装方法。

笔记

此脚本仅适用于受支持的 RHEL 版本。

###################################
# Prerequisites

# Get version of RHEL
source /etc/os-release
if [ $(bc<<<"$VERSION_ID < 8") = 1 ]
then majorver=7
elif [ $(bc<<<"$VERSION_ID < 9") = 1 ]
then majorver=8
else majorver=9
fi

# Download the Microsoft RedHat repository package
curl -sSL -O https://packages.microsoft.com/config/rhel/$majorver/packages-microsoft-prod.rpm

# Register the Microsoft RedHat repository
sudo rpm -i packages-microsoft-prod.rpm

# Delete the downloaded package after installing
rm packages-microsoft-prod.rpm

# RHEL 7.x uses yum and RHEL 8+ uses dnf
if [ $(bc<<<"$majorver < 8") ]
then
    # Update package index files
    sudo yum update
    # Install PowerShell
    sudo yum install powershell -y
else
    # Update package index files
    sudo dnf update
    # Install PowerShell
    sudo dnf install powershell -y
fi

直接下载安装

PowerShell 7.2 引入了一个通用包,使安装更加容易。从发布页面将通用包下载到您的 RHEL 计算机上。

当前版本的链接是:

  • 适用于受支持的 RHEL 版本的 PowerShell 7.4.4 通用包

      https://github.com/PowerShell/PowerShell/releases/download/v7.4.4/powershell-7.4.4-1.rh.x86_64.rpm
  • 适用于受支持的 RHEL 版本的 PowerShell 7.2.22 通用包

      https://github.com/PowerShell/PowerShell/releases/download/v7.2.22/powershell-7.2.22-1.rh.x86_64.rpm
    • 适用于受支持的 RHEL 版本的 PowerShell 7.5-preview.3 通用包

        https://github.com/PowerShell/PowerShell/releases/download/v7.5.0-preview.3/powershell-preview-7.5.0_preview.2-1.rh.x86_64.rpm
      • 以下 shell 脚本下载并安装 PowerShell 的当前预览版本。您可以更改 URL 以下载要安装的 PowerShell 版本。

        在 RHEL 8 或 9 上:

        sudo dnf install https://github.com/PowerShell/PowerShell/releases/download/v7.4.4/powershell-7.4.4-1.rh.x86_64.rpm
        

        卸载PowerShell

        在 RHEL 8 或 9 上:

        sudo dnf remove powershell
        

        支持 Arm 处理器

        PowerShell 7.2 及更高版本支持使用 64 位 Arm 处理器在 RHEL 上运行。使用在 Linux 上安装 PowerShell 的替代方法中描述的安装 PowerShell 的二进制存档安装方法。

        PowerShell 路径

        • $PSHOME/opt/microsoft/powershell/7/
        • 配置文件脚本存储在以下位置:

          • AllUsersAllHosts - $PSHOME/profile.ps1
        • AllUsersCurrentHost - $PSHOME/Microsoft.PowerShell_profile.ps1
        • CurrentUserAllHosts - ~/.config/powershell/profile.ps1
        • CurrentUserCurrentHost - ~/.config/powershell/Microsoft.PowerShell_profile.ps1
      • 模块存储在以下位置:

        • 用户模块 - ~/.local/share/powershell/Modules
      • 共享模块 - /usr/local/share/powershell/Modules
      • 默认模块 - $PSHOME/Modules
      • PSReadLine 历史记录记录在 ~/.local/share/powershell/PSReadLine/ConsoleHost_history.txt
      • PowerShell 遵循 Linux 上的 XDG 基本目录规范。

        支持的版本

        Microsoft 支持 PowerShell,直到 PowerShell 达到支持终止或 RHEL 版本达到支持终止为止。

        还可以从 https://packages.microsoft.com/ 获取安装包文件 (.rpm)。

        包含适用于 x64 的 PowerShell 7.2、PowerShell 7.4 和 PowerShell 7.5 预览版的 Docker 映像可从 Microsoft Artifact Registry 获取以下版本的 RHEL:

        • RHEL 8 - 操作系统支持将于 2029 年 5 月 31 日结束
        • RHEL 9 - 操作系统支持将于 2032 年 5 月 31 日终止

        PowerShell 在红帽通用基础映像 (UBI) 上进行了测试。有关更多信息,请参阅 UBI 信息页面。

        这很重要

        Docker 映像是根据操作系统发行商提供的官方操作系统 (OS) 映像构建的。这些映像可能没有最新的安全更新。 Microsoft 建议您将操作系统软件包更新到最新版本,以确保应用最新的安全更新。

        安装支持

        Microsoft 支持本文档中的安装方法。其他第三方来源可能还提供其他安装方法。虽然这些工具和方法可能有效,但 Microsoft 无法支持这些方法。

        您需要 登录账户 后才能发表评论

        取消回复欢迎 发表评论:

        关灯