Gemini CLIをインストールするときに詰まったところ
Gemini CLIをインストールするときに詰まったところ
VS CodeのターミナルでGeminiコマンドが通らない
下記のメッセージで詰まった。 PC上のPowerShellではGemini CLIがうまく動くのに、VS Codeのターミナルでは動かない。 npmコマンドも同様に動かない。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
PS C:\Dev\Project> gemini
gemini : File C:\Users\Anonymous\AppData\Roaming\npm\gemini.ps1
cannot be loaded because running scripts is disabled on th
is system. For more information, see about_Execution_Polici
es at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ gemini
+ ~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSec
urityException
+ FullyQualifiedErrorId : UnauthorizedAccess
PS C:\Dev\Project> npm
npm : File C:\Program Files\nodejs\npm.ps1 cannot be loaded
because running scripts is disabled on this system. For mo
re information, see about_Execution_Policies at https:/go.m
icrosoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ npm
+ ~~~
+ CategoryInfo : SecurityError: (:) [], PSSec
urityException
+ FullyQualifiedErrorId : UnauthorizedAccess
解決策
結果として、Geminiに聞いて、PowerShellの実行ポリシーを変更することで解決した。
方法は以下の通り。
- Windowsのスタートメニューから「PowerShell」と検索します。
- 「Windows PowerShell」を右クリックし、「管理者として実行」を選択します。
- PowerShellのウィンドウが開いたら、
Set-ExecutionPolicy RemoteSigned
を入力してEnterキーを押します。1
Set-ExecutionPolicy RemoteSigned
- 実行ポリシーの変更を確認するメッセージが表示され、「はい」または「いいえ」の選択肢が出ます。A(はい、すべて)または Y(はい)を入力してEnterキーを押します。
- コマンドが正常に完了したら、PowerShellのウィンドウを閉じます。
実行結果は以下。
1
2
3
4
5
6
7
8
9
10
11
12
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows
PS C:\WINDOWS\system32> Set-ExecutionPolicy RemoteSigned
Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): A
とりあえずこれでGemini CLIとnpmコマンドがVS Codeのターミナルでも動くようになった。 よかったよかった。
今回の問題は、PowerShellの実行ポリシーがデフォルトでスクリプトの実行を禁止しているために発生したっぽい。
今回はRemoteSigned
に設定したけど、セキュリティ上の理由から、必要なときだけ変更するのが良いかもしれない。
参考情報
This post is licensed under CC BY 4.0 by the author.