VSCode macOS 安装
说明在 macOS 上获取通用架构压缩包、将应用移入 Applications、通过聚焦搜索或启动台首次打开并确认安全提示,以及配置终端 code 命令的方法。
学完这一章,你能够
- 说明在 macOS 上获取通用架构压缩包、将应用移入 Applications、通过聚焦搜索或启动台首次打开并确认安全提示,以及配置终端 code 命令的方法。
系统要求与 macOS 下载包获取
在 macOS 上部署 VS Code 前同样建议先确认操作系统满足下表的基础兼容要求,以保障桌面客户端与扩展运行稳定。
打开 VS Code 官网首页(`https://code.visualstudio.com/`)时会自动识别 macOS 环境并呈现 “Download for macOS” 按钮;也可在下载页(`https://code.visualstudio.com/Download`)按 Apple Silicon、Intel 或 Universal 架构按需获取。
解压部署到应用程序目录与首次启动
点击 “Download for macOS” 后会获得名为 `VSCode-darwin-universal.zip` 的通用架构压缩包。双击解压得到 `Visual Studio Code.app` 应用包后,务必将其拖入系统的 `Applications(应用程序)` 文件夹,这样它既能被 Launchpad(启动台)识别,也能稳定保持更新权限。
启动方式有两种:一是按下 `Command ⌘` + 空格打开聚焦搜索(Spotlight),键入 `Visual` 并选择 Visual Studio Code;二是在启动台直接点击图标。首次运行来自互联网的应用时,macOS Gatekeeper 会弹出安全确认对话框,点击 “Open(打开)” 即可进入 VS Code 欢迎界面。
在 macOS 终端中启用 code 命令
macOS 解压拖放安装后并不会自动向终端 `PATH` 写入 `code` 符号链接。可在 VS Code 中按下 `⇧⌘P`(Windows/Linux 为 `Ctrl + Shift + P`)唤出命令面板,输入 `>shell command` 并选择 `Shell Command: Install 'code' command in PATH`,编辑器即会在 `/usr/local/bin/code` 建立指向应用内部二进制的链接。本站离线脚本已校验通用包路径、Spotlight 快捷键及符号链接目标。
VS Code 跨平台基础系统要求
| 操作系统 | 最低版本要求 |
|---|---|
| Windows | Windows 7 64 位或更高版本(当前官方新版本建议 Windows 10/11 64 位) |
| macOS | macOS 10.11 El Capitan 或更高版本(支持 Universal 通用包) |
| Linux | Ubuntu 16.04+、Debian 9+、Fedora 30+、CentOS 7+ 及兼容发行版 |
运行 macOS 通用应用包路径、聚焦搜索快捷键与 Shell Command PATH 符号链接离线校验
"""Offline VS Code macOS installation & Shell Command PATH verifier for Ch04 (macos-install)."""
import json
VERSION = "CPython 3.12.14 offline macOS bundle & PATH verifier"
def check(name, summary, expected, actual):
return {
"name": name,
"summary": summary,
"expected": expected,
"actual": actual,
"passed": actual == expected,
}
def main():
cases = []
# Case 1: macOS universal archive, Applications drag target, Spotlight & OS matrix
min_os = {
"Windows": "Windows 7 64 位或更高版本",
"macOS": "macOS 10.11 El Capitan 或更高版本",
"Linux": "Ubuntu 16.04+, Debian 9+, Fedora 30+, CentOS 7+",
}
macos_flow = {
"archive": "VSCode-darwin-universal.zip",
"app_bundle": "Visual Studio Code.app",
"install_path": "/Applications/Visual Studio Code.app",
"spotlight_shortcut": "Command ⌘ + Space",
"gatekeeper_confirm_button": "Open",
}
cases.append(
check(
"macos_bundle_and_os_requirements",
"Verify macOS universal archive, /Applications bundle path, Spotlight shortcut, and OS matrix",
{
"os_count": 3,
"archive": "VSCode-darwin-universal.zip",
"install_path": "/Applications/Visual Studio Code.app",
"spotlight_uses_cmd": True,
"gatekeeper_confirm": "Open",
},
{
"os_count": len(min_os),
"archive": macos_flow["archive"],
"install_path": macos_flow["install_path"],
"spotlight_uses_cmd": "Command ⌘" in macos_flow["spotlight_shortcut"],
"gatekeeper_confirm": macos_flow["gatekeeper_confirm_button"],
},
)
)
# Case 2: Shell Command: Install 'code' command in PATH symlink resolution
symlink_target = "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code"
symlink_link = "/usr/local/bin/code"
path_list = ["/opt/homebrew/bin", "/usr/local/bin", "/usr/bin", "/bin"]
cases.append(
check(
"macos_shell_command_path_symlink",
"Verify macOS Shell Command PATH symlink location and Command Palette invocation",
{
"palette_command": "Shell Command: Install 'code' command in PATH",
"symlink_in_path": True,
"target_inside_app_bundle": True,
"macos_palette_shortcut": "⇧⌘P",
},
{
"palette_command": "Shell Command: Install 'code' command in PATH",
"symlink_in_path": "/usr/local/bin" in path_list and symlink_link.startswith("/usr/local/bin/"),
"target_inside_app_bundle": symlink_target.startswith("/Applications/Visual Studio Code.app/"),
"macos_palette_shortcut": "⇧⌘P",
},
)
)
print(json.dumps({"version": VERSION, "cases": cases}, ensure_ascii=False, indent=2))
if __name__ == "__main__":
main()
- 验证 VSCode-darwin-universal.zip 解压至 /Applications 路径、Command ⌘ 聚焦启动流程及 /usr/local/bin/code 符号链接配置。
所需环境:Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。
当前源码 SHA256:f87b918d6d8c02935f5bc76b18ca0767f81f9ca52c338c111609a9b4a6baf4a3
本地运行
解压后按 README 说明在对应本地环境运行脚本。
所需环境:Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。
ZIP SHA256:e82fb4d3a4177ce45282bfddadf41ebf8a3c966787dc50e8145a55a6f3f9d681
常见错误与边界
- 实际端口、文档资源与应用配置都应和测试条件一致。
练习与解答
在 macOS 上解压 `VSCode-darwin-universal.zip` 后,为什么建议将 `Visual Studio Code.app` 拖入 `/Applications` 目录,并如何让终端识别 `code` 命令?
展开参考解答
移入 `/Applications` 可让系统启动台与自动更新机制正常工作,避免在下载目录只读运行;启用 `code` 命令只需在命令面板(`⇧⌘P`)运行 `Shell Command: Install 'code' command in PATH`。