Egbert Lin's Blog

“Life is not a race, but a journey to be savoured each step of the way” by Brian Dyson

Run Visual Studio Code on macOS - Tutorial

Visual Studio Code installation and run it from Terminal on macOS

Background

Visual Studio Code is a free source-code editor made by Microsoft for Windows, Linux and macOS.
Features include support for debugging, syntax highlighting, intelligent code completion, snippets, code refactoring, and embedded Git. Users can change the theme, keyboard shortcuts, preferences, and install extensions that add additional functionality.

Installation

  1. Download Visual Studio Code for macOS directly.
  2. Go to your browser's lownloaded archive.
  3. Extract VSCode-darwin-stable.zip file
  4. Drag Visual Studio Code.cpp to the Applications folder, making it available in the macOS Launchpad.

Launching from the command line

You can type 'code .' in any folder to start editing files in that folder.
Notice: you will meet an error message: “code .” command is not working

Solution: You must add Visual Studio Code to the path first:

  1. Create bash_profile file if it doesn't exist in your system.
    1
    $ touch ~/.bash_profile
  2. Open this file, click 'i' to edit.
    1
    $ vi ~/.bash_profile
  3. Paste it as below, and type ':' + 'wq' to write & quit.<
    1
    export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
  4. Preserve your current shell, if you miss it, you will repeat step2-step3 again when you reopen the terminal.
    1
    $ source ~/.bash_profile