PowerShell 是跨平台的自动化脚本语言,非常适合管理系统配置和批量任务。而 VS Code 则是开发者首选的轻量级编辑器。本文将手把手教你如何在 macOS 上通过 Homebrew 安装 PowerShell 并配置 VS Code 正确识别它。
推荐通过 Homebrew 安装 PowerShell:
brew install powershell/tap/powershell
安装完成后,确认 PowerShell 可执行文件路径:
command -v pwsh
通常会是:
/opt/homebrew/bin/pwsh
安装好 PowerShell 后,在 VS Code 中打开 .ps1 脚本时,可能会出现如下报错:
“Unable to find PowerShell! Do you have it installed?”

这是因为 VS Code 默认不会去 /opt/homebrew/bin/ 下面查找 pwsh。
"powershell.powerShellAdditionalExePaths": {
"Homebrew PowerShell": "/opt/homebrew/bin/pwsh"
},
"powershell.powerShellDefaultVersion": "Homebrew PowerShell"
完整示例(保留你已有的设置):
{
"redhat.telemetry.enabled": true,
"powershell.powerShellAdditionalExePaths": {
"Homebrew PowerShell": "/opt/homebrew/bin/pwsh"
},
"powershell.powerShellDefaultVersion": "Homebrew PowerShell"
}
保存后重启 VS Code,右下角应该可以看到 PowerShell 已加载。


"powershell.integratedConsole.showOnStartup": false,
"powershell.scriptAnalysis.enable": true,
"powershell.codeFormatting.autoCorrectAliases": true
解释:
如果你看到以下类似配置:
"parallels-desktop.git.path": "/usr/bin/git",
"parallels-desktop.brew.path": "/opt/homebrew/bin/brew"
说明你安装了 Parallels 的 VS Code 插件,用于与虚拟机环境交互。这些配置不会影响 PowerShell 的使用。
如果你不再使用 Parallels 插件,可以手动移除相关配置项,不影响其他功能。
配置 VS Code 正确识别 Homebrew 安装的 PowerShell,只需 3 步:
至此,你的 macOS + VS Code + PowerShell 开发环境就准备好了!可以尽情享受跨平台脚本的快乐 🚀

