蓝色天空.知识 · 实践 · 创造
我的收藏
VS Code 教程目录 25章
VS Code / LEARN BY DOING

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 跨平台基础系统要求

操作系统最低版本要求
WindowsWindows 7 64 位或更高版本(当前官方新版本建议 Windows 10/11 64 位)
macOSmacOS 10.11 El Capitan 或更高版本(支持 Universal 通用包)
LinuxUbuntu 16.04+、Debian 9+、Fedora 30+、CentOS 7+ 及兼容发行版

运行 macOS 通用应用包路径、聚焦搜索快捷键与 Shell Command PATH 符号链接离线校验

含完整源码 · 82 行
展开查看收起
python
"""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 符号链接配置。

查看独立实例 ↗ 在独立页面查看源码、运行环境与工程包

本地运行

解压后按 README 说明在对应本地环境运行脚本。

下载本章实验包 (mbskycom202612a2214.zip) ↓ 查看运行说明 ↗

本章附件与实例包

下载课程关联工程包:VS Code

课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a2214.zip

下载课程关联工程包:VS Code

课程关联工程包(登记关联25章) · 含当前章节或实例 · mbskycom202612a2203.zip

常见错误与边界检查

  • 实际端口、文档资源与应用配置都应和测试条件一致。

技术规范与官方资料

练习与参考解答

查看参考解答

移入 `/Applications` 可让系统启动台与自动更新机制正常工作,避免在下载目录只读运行;启用 `code` 命令只需在命令面板(`⇧⌘P`)运行 `Shell Command: Install 'code' command in PATH`。

SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习