在 Red Hat Enterprise Linux 上安裝 PowerShell (RHEL)
所有套件都可在我們的 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
下列殼層腳本會下載並安裝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 上執行。 使用二進位封存安裝方法來安裝PowerShell,如替代方式在Linux上安裝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 版本
- 圖示 指出該操作系統版本不再支援PowerShell版本
- 圖示 表示我們尚未在該 OS 上完成 PowerShell 測試
- 圖示 表示不支援操作系統或PowerShell版本
- 當操作系統版本和 PowerShell 版本都有 圖示時,支援該組合
RHEL | 7.2 (LTS-previous) | 7.3 | 7.4 (LTS-current) |
---|---|---|---|
9 | |||
8 | |||
7 |
PowerShell 已在 Red Hat 通用基底映射 (UBI) 上進行測試。 如需詳細資訊,請參閱 UBI 資訊頁面。
RHEL 支援下列處理器架構的PowerShell。
RHEL | 7.2 (LTS-current) | 7.3 | 7.4 (LTS-current) |
---|---|---|---|
所有支援的版本 | x64 | x64 | x64 |
安裝支援
Microsoft 支援本檔中的安裝方法。 可能還有其他第三方來源可用的安裝方法。 雖然這些工具和方法可能正常運作,但 Microsoft 無法支援這些方法。
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應