Configure Visual Studio Code for Go development

In this quickstart, you'll install and configure the Go for Visual Studio Code extension.

In the Go Developer Survey 2020 Results, 41% of respondents chose Visual Studio Code as their most preferred editor for Go. This makes Visual Studio Code the most popular editor for Go developers.

Visual Studio Code and the Go extension provide IntelliSense, code navigation, and advanced debugging. In this quickstart, you'll configure Visual Studio Code. Then you'll write, run, and debug a sample Go program.

A screenshot showing a Go program within Visual Studio Code

1. Install Go

Follow these steps to install Go:

  1. In a web browser, go to golang.org/doc/install.
  2. Download the version for your operating system.
  3. Once downloaded, run the installer.
  4. Open a command prompt, then run go version to confirm Go was installed.

2. Install Visual Studio Code

Follow these steps to install Visual Studio Code:

  1. In a web browser, go to code.visualstudio.com.
  2. Download the version for your operating system, supports Windows, Linux, and macOS.
  3. Once downloaded, run the installer. This will only take a minute.

3. Install the Go extension

Instructions Screenshot
In Visual Studio Code, bring up the Extensions view by clicking on the Extensions icon in the Activity Bar. Or use keyboard shortcut (Ctrl+Shift+X). A screenshot showing how search for the Go extension.
Search for the Go extension, then select install. A screenshot showing how to use the search box in the top tool bar to find App Services in Azure.

4. Update the Go tools

Instructions Screenshot
In Visual Studio Code, open Command Palette's Help > Show All Commands. Or use the keyboard shortcut (Ctrl+Shift+P) A screenshot showing how search the Command Palette.
Search for Go: Install/Update tools then run the command from the pallet A screenshot showing how to run the Go: install/update tool from the command pallet.
When prompted, select all the available Go tools then click OK. A screenshot showing how to update all the available Go tools.
Wait for the Go tools to finish updating. A screenshot showing all the Go tools that were updated.

5. Write a sample Go program

Instructions Screenshot
In Visual Studio Code, open the folder where you'll create the root directory of your Go application. To open the folder, click the Explorer icon in the Activity Bar then click Open Folder. A screenshot showing how to create a new folder.
Click New Folder in the Explorer panel, then Create the root director for your sample Go application named sample-app A screenshot showing how to create a folder in vs code.
Click New File in the Explorer panel, then name the file main.go A screenshot showing how to create a file in vs code.
Open a terminal, Terminal > New Terminal, then run the command go mod init sample-app to initialize your sample Go app. A screenshot running the go mod init command.
Copy the following code into the main.go file. A screenshot displaying a sample Go program.

Sample code:

package main

import "fmt"

func main() {
    name := "Go Developers"
    fmt.Println("Azure for", name)
}

6. Run the debugger

Instructions Screenshot
Create a break point on line 7 by left clicking to the left of the numbered line. Or place your cursor on line 7 and hit F9. A screenshot showing how to set a breakpoint.
Bring up the Debug view by clicking on the debug icon in the Activity Bar on the side of Visual Studio Code. Or use keyboard shortcut (Ctrl+Shift+D). A screenshot showing how to navigate to the debug panel.
Click Run and Debug, or hit F5 to run the debugger. Then Hover over the variable name on line 7 to see its value. Exit the debugger by clicking Continue on the debugger bar or hit F5. A screenshot showing running the debugger in VS code.

Next steps