PowerShell 7以降をscoopでインストールする方法を紹介します。対象OSはWindowsです。
Microsoftが推奨するインストール方法
MicrosoftはPowerShellをWingetでインストールすることを推奨しています。ただWingetを使うとシステムに1つのPowerShellしかインストールできません。複数のバージョンを使う方法として公式はZipパッケージを示していますが、scoopを使うとZipを意識せずにインストールできます。
インストール可能な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を素直に使ってもいい気もします。
-
Windows PowerShellからの
scoop uninstall pwshでも同様の挙動になるのは解せない↩