如何修改PowerShell默认路径?解决Scoop安装后系统仍指向旧版本问题
解决Scoop安装的新版PowerShell无法被系统及终端识别的问题
用户当前命令查找结果:
where.exe Powershell C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe where.exe pwsh E:\Apps\scoop\apps\powershell\current\pwsh.exe E:\Apps\scoop\shims\pwsh.exe
一、让powershell命令默认指向新版PowerShell
方式1:调整环境变量顺序
- 打开系统环境变量设置:右键「此电脑」→「属性」→「高级系统设置」→「环境变量」
- 在「用户变量」或「系统变量」的
Path列表中,将E:\Apps\scoop\shims条目拖动到C:\Windows\System32\WindowsPowerShell\v1.0之前 - 重启所有终端窗口,运行
where.exe powershell验证,此时应优先返回Scoop shims路径下的命令
方式2:创建Scoop别名
在PowerShell中执行以下命令,将powershell映射为pwsh的别名:
scoop alias add powershell pwsh
二、配置Windows Terminal使用新版PowerShell
- 打开Windows Terminal设置(快捷键
Ctrl+,) - 点击左下角「打开JSON文件」编辑配置
- 找到旧版PowerShell的配置项,修改
commandline字段为新版路径:
若已调整环境变量,直接写"commandline": "E:\\Apps\\scoop\\apps\\powershell\\current\\pwsh.exe""pwsh.exe"即可 - 可将该配置项设置为默认终端配置文件
三、配置VS Code使用新版PowerShell
- 打开VS Code设置(快捷键
Ctrl+,) - 搜索
terminal.integrated.profiles.windows,点击「编辑settings.json」 - 修改PowerShell的配置路径:
"terminal.integrated.profiles.windows": { "PowerShell": { "path": "E:\\Apps\\scoop\\apps\\powershell\\current\\pwsh.exe", "source": "PowerShell" } } - 搜索
powershell.powerShellExePath,将其值设置为新版pwsh.exe的路径,确保PowerShell扩展也使用新版
完成以上步骤后,重启所有应用即可生效。
内容的提问来源于stack exchange,提问作者Flamingo
相关产品推荐
相关产品推荐

