在 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
# Register the Microsoft RedHat repository
curl -sSL -O https://packages.microsoft.com/config/rhel/$majorver/packages-microsoft-prod.rpm
# Register the Microsoft repository keys
sudo rpm -i packages-microsoft-prod.rpm
# Delete the repository keys 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 通用包
https://github.com/PowerShell/PowerShell/releases/download/v7.4.2/powershell-7.4.2-1.rh.x86_64.rpm
- 适用于受支持的 RHEL 版本的 PowerShell 7.3.12 通用包
https://github.com/PowerShell/PowerShell/releases/download/v7.3.12/powershell-7.3.12-1.rh.x86_64.rpm
- 适用于受支持的 RHEL 版本的 PowerShell 7.2.19 通用包
https://github.com/PowerShell/PowerShell/releases/download/v7.2.19/powershell-7.2.19-1.rh.x86_64.rpm
以下 shell 脚本用于下载并安装 PowerShell 的当前预览版本。 可以更改 URL 以下载要安装的 PowerShell 版本。
在 RHEL 8 或 9 上:
sudo dnf install https://github.com/PowerShell/PowerShell/releases/download/v7.4.2/powershell-7.4.2-1.rh.x86_64.rpm
在 RHEL 7 上:
sudo yum install https://github.com/PowerShell/PowerShell/releases/download/v7.4.2/powershell-7.4.2-1.rh.x86_64.rpm
卸载 PowerShell
在 RHEL 8 或 9 上:
sudo dnf remove powershell
在 RHEL 7 上:
sudo yum 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
- AllUsersAllHosts -
- 模块存储在以下位置:
- 用户模块 -
~/.local/share/powershell/Modules
- 共享模块 -
/usr/local/share/powershell/Modules
- 默认模块 -
$PSHOME/Modules
- 用户模块 -
- PSReadline 历史记录将记录到
~/.local/share/powershell/PSReadLine/ConsoleHost_history.txt
中
PowerShell 采用 Linux 上的 XDG 基目录规范。
支持的版本
下表列出了当前支持的 PowerShell 版本以及支持它们的 RHEL 版本。 这些版本在 PowerShell 版本到达支持终止日期或 RHEL 版本到达支持终止日期之前仍受支持。
- 图标指示仍支持 OS 或 PowerShell 版本
- 图标指示该 OS 版本不再支持 PowerShell 版本
- 图标指示我们尚未在该 OS 上完成 PowerShell 的测试
- 图标指示不支持 OS 或 PowerShell 版本
- 当 OS 版本和 PowerShell 版本都具有 图标时,将支持该组合
RHEL | 7.2(LTS-早期) | 7.3 | 7.4(LTS-当前) |
---|---|---|---|
9 | |||
8 | |||
7 |
PowerShell 在 Red Hat 通用基础映像 (UBI) 上进行了测试。 有关详细信息,请参阅 UBI 信息页。
以下处理器体系结构在 RHEL 上支持 PowerShell。
RHEL | 7.2 (LTS-current) | 7.3 | 7.4(LTS-当前) |
---|---|---|---|
所有支持的版本 | X64 | X64 | X64 |
安装支持
Microsoft 支持本文档中的安装方法。 其他第三方源可能会提供其他安装方法。 尽管这些工具和方法可能有效,但 Microsoft 无法支持这些方法。
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈