以下の内容はhttps://tech.guitarrapc.com/entry/2025/01/13/235839より取得しました。


scoopでPowerShell(pwsh)をインストールする

PowerShell 7以降をscoopでインストールする方法を紹介します。対象OSはWindowsです。

Microsoftが推奨するインストール方法

MicrosoftはPowerShellをWingetでインストールすることを推奨しています。ただWingetを使うとシステムに1つのPowerShellしかインストールできません。複数のバージョンを使う方法として公式はZipパッケージを示していますが、scoopを使うとZipを意識せずにインストールできます。

Installing PowerShell on Windows | Microsoft Learn

インストール可能なPowerShell

scoopでインストール可能なPowerShellは、PowerShell(mainバケット)とPowerShell Preview(versionsバケット)です。PowerShell Previewはpwsh-betaとなっています。

$ scoop search pwsh
Results from local buckets...

Name      Version    Source   Binaries
----      -------    ------   --------
pwsh      7.4.6      main
pwsh-beta 7.5.0-rc.1 versions

PowerShellをインストール

scoopでPowerShellを追加します。PowerShell 7はpwshという名前でMainバケットに登録されていいます。

$ scoop install pwsh

mainバケットはデフォルトで利用できますが、もし追加する場合は次のコマンドを実行してください。

$ scoop bucket add main

プレビューバージョンのインストール

プレビューバージョンのPowerShellをインストールする場合は、versionsバケットを追加してからインストールします。

$ scoop bucket add versions
Checking repo... OK
The versions bucket was added successfully.
$ scoop install versions/pwsh-beta

アンインストール

アンインストールは次のコマンドで行います。

$ scoop uninstall pwsh
$ scoop uninstall versions/pwsh-beta

注意

pwshとpwsh-betaの同時インストールは避けたほうがいい

pwshのインストールとpwsh-betaのインストールはshimsで競合するため、pwshをアンインストールしてからpwsh-betaをインストールしてください。ちょっといやな挙動です。

pwsh-betaをインストール後にscoop uninstall pwshができない

pwsh-betaが入っているときにscoop uninstall pwshするとpwsh-betaが呼ばれてプロセス利用中のためアンインストールできなくなります。1

$ scoop uninstall versions/pwsh-beta
Uninstalling 'pwsh-beta' (7.5.0-rc.1).
ERROR The following instances of "pwsh-beta" are still running. Close them and try again.

 NPM(K)    PM(M)      WS(M)     CPU(s)      Id  SI ProcessName
 ------    -----      -----     ------      --  -- -----------
     67    50.74     109.63       0.48   24392  18 pwsh

アンインストールする場合は、%USERPROFILE%\scoop\shims\pwsh.shims|exe%USERPROFILE%\scoop\apps\pwsh-betaの両方を削除します。

if (Test-Path "${env:USERPROFILE}\scoop\shims\pwsh.shims") {
    Remove-Item "${env:USERPROFILE}\scoop\shims\pwsh.shims"
}
if (Test-Path "${env:USERPROFILE}\scoop\shims\pwsh.exe") {
    Remove-Item "${env:USERPROFILE}\scoop\shims\pwsh.exe"
}
if (Test-Path "${env:USERPROFILE}\scoop\apps\pwsh-beta") {
    Remove-Item "${env:USERPROFILE}\scoop\apps\pwsh-beta" -Recurse
}

いやな挙動ですが、いったんしょうがないか...

まとめ

scoopで異なるバージョンの利用にversionsバケットを使うのはpwsh-betaでも同様ですが、挙動がちょっと嫌な感じでですね。 scoopにこだわらずWingetを素直に使ってもいい気もします。


  1. Windows PowerShellからのscoop uninstall pwshでも同様の挙動になるのは解せない



以上の内容はhttps://tech.guitarrapc.com/entry/2025/01/13/235839より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14