在 macOS 上安裝 Visual Studio Code

Visual Studio Code 提供可供下載的磁碟映像檔,適用於 macOS。VS Code 支援 Intel 架構的 Mac 以及配備 Apple Silicon 的 Mac。

在 macOS 上安裝 VS Code

  1. 下載適用於 macOS 的 Visual Studio Code

  2. 開啟已下載的 .dmg 檔案。

  3. Visual Studio Code.app 拖曳至 Applications 資料夾。

  4. Applications 資料夾中按兩下圖示以開啟 VS Code。

  5. 若要將 VS Code 保留在 Dock 中,請在 Dock 中的圖示上按住 Control 鍵並按一下,然後選取 選項 > 保留在 Dock 中

注意

下載 Visual Studio Code 頁面也列出了 Universal (通用)、Intel 晶片和 Apple Silicon 組建。

從命令列啟動 VS Code

若要從終端機輸入 code 來執行 VS Code,請將 VS Code 新增至 $PATH 環境變數中。

設定包含 VS Code 的 PATH

  1. 啟動 VS Code。

  2. 開啟命令選擇區 (Cmd+Shift+P),輸入 shell command,然後執行 Shell Command: Install 'code' command in PATH 命令。

    Screenshot showing the Shell Command command in the Command Palette on macOS.

  3. 重新啟動終端機以使新的 $PATH 值生效。

    在任何資料夾中執行 code .,即可開始編輯該資料夾中的檔案。

注意

如果舊版 VS Code 的 .bash_profile 或對應的 shell 設定檔中仍殘留舊的 code 別名,請將其移除,然後再次執行 Shell Command: Install 'code' command in PATH 命令。

手動設定 PATH

若要手動將 VS Code 新增至您的路徑,請執行適用於您 shell 的命令。

Zsh:

cat << EOF >> ~/.zprofile
# Add Visual Studio Code (code)
export PATH="\$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
EOF

Bash:

cat << EOF >> ~/.bash_profile
# Add Visual Studio Code (code)
export PATH="\$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
EOF
注意

\$PATH 中的開頭反斜線可防止 $PATH 在字串串接期間展開。直接在終端機中執行 export 命令時,請移除反斜線。

啟動新的終端機以套用變更。在任何資料夾中執行 code .,即可開始編輯該資料夾中的檔案。

更新

VS Code 每週發布更新版本,並在有新版本可用時支援自動更新。當 VS Code 提示您進行更新時,接受提示即可安裝新版本。

注意

如果您偏好按照自己的時程更新 VS Code,請停用自動更新

Touch Bar 支援

VS Code 在支援的 Mac 上新增了以下 Touch Bar 動作

  • 編輯器歷史紀錄導覽。
  • 用於控制偵錯工具的偵錯工具列。

Screenshot showing VS Code Touch Bar actions on macOS.

安裝之後

安裝 VS Code 後,請完成開發工作流程的設定

常見問題

為什麼 Visual Studio Code 會要求存取我的行事曆?

在 macOS Mojave 上,對話方塊可能會顯示「Visual Studio Code 想存取您的行事曆、聯絡資訊或照片。」這些對話方塊來自 macOS 的隱私權保護,並非 VS Code 專屬。請選取不允許,因為 VS Code 不需要存取這些資料夾。

VS Code 更新失敗

如果重新啟動後 VS Code 未更新,可能是 macOS 將其設為隔離狀態。請遵循 issue #7426 中的步驟來解決此問題。

VS Code 可以在 Apple Silicon 電腦上執行嗎?

可以。VS Code 支援在配備 Apple Silicon 的 Mac 上執行的 macOS Arm64 組建。請安裝同時包含 Intel 與 Apple Silicon 組建的 Universal (通用) 組建,或是安裝特定的平台組建。

English 한국어 中文(简体) 中文(繁體)
© . This website operates independently and is not affiliated with or endorsed by Microsoft. All brand names, logos, and trademarks are the property of their respective owners.