Goland終端Terminal的PowerShell不能使用,明明windows上升級了PowerShell 7設置了配置文件,但是只能在windows終端下使用,goland終端下直接失效報錯,安裝升級PowerShell請看Windows11終端升級PowerShell7 - HashFlag - 博客園
問題:
? 在goland的終端Terminal中使用PowerShell的時候執行g ls
等配置或安裝的命令可能出現報錯(Windows終端的Power Shell 7不會出現問題):
Windows PowerShell
版權所有(C) Microsoft Corporation。保留所有權利。安裝最新的 PowerShell,了解新功能和改進!https://aka.ms/PSWindowsPS D:\wyl\workspace\go\board> g ls
g : 無法將“g”項識別為 cmdlet、函數、腳本文件或可運行程序的名稱。請檢查名稱的拼寫,如果包括路
徑,請確保路徑正確,然后再試一次。
所在位置 行:1 字符: 1
+ g ls
+ ~+ CategoryInfo : ObjectNotFound: (g:String) [], CommandNotFoundException+ FullyQualifiedErrorId : CommandNotFoundException
原因:
? goland的終端Terminal默認只會使用windows下的 PowerShell 5(問題路徑:C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe),這可能是因為goland和windows的兼容問題導致的
解決辦法:
? 找到PowerShell 7的可執行文件pwsh.exe,把goland的默認終端選項修改為正確的地址即可,一般golang默認使用的PowerShell 5地址就是這個C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
(這里可能還有其他的比如cmd和git bash等就不介紹了,不人為更改的話默認就是PS)
? 正確地址(可以直接復制粘貼-如果是PS7-preview版本):C:\Program Files\PowerShell\7-preview\pwsh.exe
? 如果直接粘貼沒有生效或者找不到文件,大概率是版本不同導致的,可以按照C:\Program Files\PowerShell
一級一級找下去,直到找到正確的為止
操作:
? 路徑:Goland > File > Settings > Tools > Terminal > Shell path: > Select Path / Shell executable path
? 按照上面的路徑在goland的設置中找到工具下的終端Terminal的Shell path,點擊右側的...
會彈出一個Select Path的窗口,可以看到Shell executable path的一個標題,標題下面就是查找路徑,找到對應的正確的pwsh.exe位置選中即可
驗證:
關閉已打開的終端,即可看到默認頭已經改變
舊頭:
Windows PowerShell
版權所有(C) Microsoft Corporation。保留所有權利。安裝最新的 PowerShell,了解新功能和改進!https://aka.ms/PSWindowsPS D:\wyl\workspace\go\board>
新頭:
PowerShell 7.6.0-preview.4
PS D:\wyl\workspace\go\board>
再次執行g ls
發現已經可以使用