在Alpine Linux上安裝PowerShell

所有套件都可在我們的 GitHub 版本 頁面上取得。 安裝套件之後,請從終端機執行 pwsh 。 如果您已安裝預覽版本,請執行 pwsh-preview 。 安裝之前,請先檢查下方支援的版本清單

注意

PowerShell 7.4 是移除舊版 PowerShell 7 的就地升級。 PowerShell 的預覽版本可以與其他 PowerShell 版本並存安裝。 如果您需要與舊版並存執行 PowerShell 7.4,請使用 二進位封存 方法重新安裝舊版。

安裝步驟

Alpine 上的安裝是以從 發行 頁面下載tar.gz套件為基礎。 套件的 URL 取決於您要安裝的 PowerShell 版本。

  • PowerShell 7.4.2 - https://github.com/PowerShell/PowerShell/releases/download/v7.4.2/powershell-7.4.2-linux-musl-x64.tar.gz
  • PowerShell 7.3.12 - https://github.com/PowerShell/PowerShell/releases/download/v7.3.12/powershell-7.3.12-linux-alpine-x64.tar.gz
  • PowerShell 7.2.19 - https://github.com/PowerShell/PowerShell/releases/download/v7.2.19/powershell-7.2.19-linux-alpine-x64.tar.gz

然後,在終端機中,執行下列殼層命令來安裝 PowerShell 7.3:

# install the requirements
sudo apk add --no-cache \
    ca-certificates \
    less \
    ncurses-terminfo-base \
    krb5-libs \
    libgcc \
    libintl \
    libssl1.1 \
    libstdc++ \
    tzdata \
    userspace-rcu \
    zlib \
    icu-libs \
    curl

sudo apk -X https://dl-cdn.alpinelinux.org/alpine/edge/main add --no-cache \
    lttng-ust

# Download the powershell '.tar.gz' archive
curl -L https://github.com/PowerShell/PowerShell/releases/download/v7.4.2/powershell-7.4.2-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
  • 模組會儲存在下列位置:
    • 使用者模組 - ~/.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 基底目錄規格

支援的版本

下表列出支援的 PowerShell 版本,以及其支援的 Alpine 版本。 支援這些版本,直到 PowerShell 版本 達到終止支援 為止,或 Alpine 版本 達到生命週期結束為止。

  • 圖示 支援 表示仍支援 OS 或 PowerShell 版本
  • 圖示 不受支援 指出該操作系統版本不再支援PowerShell版本
  • 圖示 在測試中 表示我們尚未在該 OS 上完成 PowerShell 測試
  • 圖示 不支援 表示不支援操作系統或PowerShell版本
  • 當操作系統版本和 PowerShell 版本都有 支援 圖示時,支援該組合
Alpine 7.2 (LTS-previous) 7.3 7.4 (LTS-current)
支援 3.18 不支援 不支援 不支援
支援 3.17 在測試中 在測試中 在測試中
支援 3.16 在測試中 在測試中 在測試中
不受支援 3.15 在測試中 在測試中 在測試中
不受支援 3.14 不受支援 不受支援 不受支援

Alpine 支援下列處理器架構的PowerShell。

Alpine 7.2 (LTS-current) 7.3 7.4 (LTS-current)
所有支援的版本 x64 x64 x64

PowerShell 尚未使用 Arm 處理器在 Alpine 上進行測試。

安裝支援

Microsoft 支援本檔中的安裝方法。 可能還有其他第三方來源可用的安裝方法。 雖然這些工具和方法可能正常運作,但 Microsoft 無法支援這些方法。