Share via


在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.2.19 - https://github.com/PowerShell/PowerShell/releases/download/v7.2.19/powershell-7.2.19-linux-alpine-x64.tar.gz
  • PowerShell 7.5-preview.2 - https://github.com/PowerShell/PowerShell/releases/download/v7.5.0-preview.2/powershell-7.5.0-preview.2-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 \
    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 基底目錄規格

支援的版本

Microsoft 支援 PowerShell,直到 PowerShell 達到終止支援 或 Alpine 版本 達到生命週期結束為止。

Alpine 3.16 - OS 支持終止於 2024-05-23

Alpine 3.17 - OS 支持終止於 2024-11-22

  • 您可以從 Microsoft 成品登錄 取得包含 PowerShell 7.2、PowerShell 7.4 和 PowerShell 7.5-preview for x64 的 Docker 映射

PowerShell 的 Docker 映射目前不適用於 Alpine 3.18 和 3.19。

PowerShell 的預覽版本僅供測試和意見反應使用。

安裝支援

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