Alpine Linux への PowerShell のインストール

すべてのパッケージは GitHub リリース ページにあります。 パッケージがインストールされたら、ターミナルから pwsh を実行します。 プレビュー リリースをインストールした場合は、pwsh-preview を実行します。 インストールする前に、後述の「サポートされているバージョン」の一覧を確認してください。

Note

PowerShell 7.4 はインプレース アップグレードであり、以前のバージョンの PowerShell 7 は削除されます。 PowerShell のプレビュー バージョンは、他のバージョンの PowerShell と一緒にインストールできます。 PowerShell 7.4 と以前のバージョンを side-by-side 実行する必要がある場合は、バイナリ アーカイブの方法を使用して以前のバージョンを再インストールします。

インストール手順

Alpine へのインストールは、リリース ページから tar.gz パッケージをダウンロードする方法に基づいて行います。 パッケージの URL は、インストールする PowerShell のバージョンによって異なります。

  • PowerShell 7.4.3 - https://github.com/PowerShell/PowerShell/releases/download/v7.4.3/powershell-7.4.3-linux-musl-x64.tar.gz
  • PowerShell 7.2.21 - https://github.com/PowerShell/PowerShell/releases/download/v7.2.21/powershell-7.2.21-linux-alpine-x64.tar.gz
  • PowerShell 7.5-preview.3 - https://github.com/PowerShell/PowerShell/releases/download/v7.5.0-preview.3/powershell-7.5.0-preview.3-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.3/powershell-7.4.3-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 がサポート終了になるか、Alpine のバージョンがサポート終了になるまで PowerShell をサポートします。

Alpine 3.17 - OS サポートは 2024 年 11 月 22 日に終了します

現時点では、PowerShell の Docker イメージは Alpine 3.18 と 3.19 では利用できません。

プレビュー バージョンの PowerShell は、テストとフィードバック用にのみ提供されています。

インストールのサポート

Microsoft は、このドキュメントでインストール方法をサポートしています。 他のサードパーティのソースには、他のインストール方法を利用できる場合があります。 そのようなツールと方法は機能するかもしれませんが、Microsoft ではそれらの方法をサポートできません。