在Alpine Linux上安裝PowerShell
所有套件都可在我們的 GitHub 版本 頁面上取得。 安裝套件之後,請從終端機執行 pwsh
。 如果您已安裝預覽版本,請執行 pwsh-preview
。 安裝之前,請先檢查下方支援的版本清單。
注意
PowerShell 7.4 是移除舊版 PowerShell 7 的就地升級。 PowerShell 的預覽版本可以與其他 PowerShell 版本並存安裝。 如果您需要與舊版並存執行 PowerShell 7.4,請使用 二進位封存 方法重新安裝舊版。
注意
本文中的安裝命令適用於最新穩定版本的 PowerShell。 若要安裝不同版本的 PowerShell,請調整 命令以符合您需要的版本。 下列鏈接會引導您前往 GitHub 上 PowerShell 存放庫中每個版本的發行頁面。
- v7.5.0 - 穩定版本:https://aka.ms/powershell-release?tag=stable
- v7.4.7 - LTS 版本:https://aka.ms/powershell-release?tag=lts
- v7.6.0-preview.2 - 預覽版本:https://aka.ms/powershell-release?tag=preview
每個套件的下載連結都可以在 [發行] 頁面的 [Assets] 區段中找到。 [Assets] 區段可能會折疊,因此您可能需要點擊以展開它。
安裝步驟
Alpine 上的安裝是以從 發行 頁面下載tar.gz套件為基礎。 套件的 URL 取決於您要安裝的 PowerShell 版本。
- PowerShell 7.4 -
https://github.com/PowerShell/PowerShell/releases/download/v7.4.7/powershell-7.4.7-linux-musl-x64.tar.gz
- PowerShell 7.5 -
https://github.com/PowerShell/PowerShell/releases/download/v7.5.0/powershell-7.5.0-linux-musl-x64.tar.gz
然後,在終端機中,執行下列殼層命令來安裝 PowerShell 7.4:
# install the requirements
sudo apk add --no-cache \
ca-certificates \
less \
ncurses-terminfo-base \
krb5-libs \
libgcc \
libintl \
libssl3 \
libstdc++ \
tzdata \
userspace-rcu \
zlib \
icu-libs \
curl
apk -X https://dl-cdn.alpinelinux.org/alpine/edge/main add --no-cache \
lttng-ust \
openssh-client \
# Download the powershell '.tar.gz' archive
curl -L https://github.com/PowerShell/PowerShell/releases/download/v7.5.0/powershell-7.5.0-linux-musl-x64.tar.gz -o /tmp/powershell.tar.gz
# Create the target folder where powershell will be placed
sudo mkdir -p /opt/microsoft/powershell/7
# Expand powershell to the target folder
sudo tar zxf /tmp/powershell.tar.gz -C /opt/microsoft/powershell/7
# Set execute permissions
sudo chmod +x /opt/microsoft/powershell/7/pwsh
# Create the symbolic link that points to pwsh
sudo ln -s /opt/microsoft/powershell/7/pwsh /usr/bin/pwsh
# Start PowerShell
pwsh
卸載 PowerShell
sudo rm -rf /usr/bin/pwsh /opt/microsoft/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 的每個主機組態,因此預設主機特定配置檔存在於 Microsoft.PowerShell_profile.ps1
相同的位置。
PowerShell 遵循 Linux 上的 XDG 基底目錄規格 。
支援的版本
Microsoft支援 PowerShell,直到 PowerShell 到達終止支援 或 Alpine 版本 達到生命週期結束為止。
下列版本的 Alpine 可從 Microsoft 成品登錄 取得包含 PowerShell 7.4 和 PowerShell 7.5-preview for x64 的 Docker 映像:
- Alpine 3.20 - OS 支援於 2026-04-01 結束
PowerShell 的 Docker 映像不適用於 Alpine 3.21。
重要
Docker 映像是透過 OS 散發者所提供的官方作業系統 (OS) 映射所建置。 這些映像可能沒有最新的安全性更新。 Microsoft建議您將 OS 套件更新為最新版本,以確保套用最新的安全性更新。
安裝支援
Microsoft支援本檔中的安裝方法。 可能還有其他第三方來源可用的安裝方法。 雖然這些工具和方法可能正常運作,但Microsoft無法支持這些方法。