How to Set Up a Go/Golang Development Environment on Windows

  • Last updated Apr 25, 2024

In this tutorial, we will guide you through the process, ensuring that you have everything you need to write, compile, and run your Go code seamlessly.

Follow these steps to set up Your Go/Golang development environment on Windows:

  1. Download and Install Go:
  2. Download the latest stable version of Go by visiting the official Go website at https://go.dev/dl and select the Windows installer.

    After you have downloaded the Go installer, double-click on the downloaded file to initiate the installation process.

  3. Verify Go Installation:
  4. Once the installation is complete, open Command Prompt or PowerShell and run the following command to verify that Go is installed correctly:

    go version

    You should see the Go version information displayed.

  5. Set Up a Workspace:
  6. It's essential to set up a workspace directory where all your Go projects will reside. Create a directory for your Go code, often referred to as the 'workspace' or 'GOPATH'. You can place this workplace directory in any location on your computer. To demonstrate this example, I will create a directory called 'go-workspace' on the E drive of my computer.

    To create a directory for go workspace, open a Windows PowerShell or Command Prompt and navigate to the location where you want to create the workspace. Then, run this command:

    mkdir go-workspace
  7. Set Environment Variables:
  8. The next step is to set environment variables for Go. To do this, navigate to 'System Properties' by entering 'env' in the taskbar's search box, and then click on the 'Edit the system environment variables' shortcut, as shown in the image below:

    In the System Properties window, click on the 'Environment Variables' button.

    In the User Variables section, select 'GOPATH' and click the Edit button if 'GOPATH' already exists. Then, browse and select the 'go-workspace' directory you created.

    If 'GOPATH' does not exist, then click the NEW button. Enter 'GOPATH' in the Variable name field. In the Variable value field, browse and select the 'go-workspace' directory you created, as shown in the image below:

    Next, click the OK button and restart your computer.

  9. Download and Set up Visual Studio Code IDE for Go:
  10. To write code in Go, you'll need a code editor. Please download Visual Studio Code from its official website at https://code.visualstudio.com/download and proceed with the installation.

    After the installation is complete, launch the application and navigate to the Extensions Marketplace by clicking on the 'Extensions' icon in the left sidebar (resembling a square puzzle piece). Alternatively, you can use the keyboard shortcut Ctrl+Shift+X (Windows/Linux) or Cmd+Shift+X (macOS) to open the Extensions view. In the Extensions view, you'll find a search bar at the top. Use it to search for 'Go' and proceed to install the extension, as shown in the image below:

    The environment setup for the Go programming language is complete. Next, we will guide you on how to create and run a program in Go.