How To Set Up Go With VSCode For Windows

Introduction

 
Go (also known as the golang) is an open-source programming language that was introduced back in 2009 and is distributed under the BSD-style license. It was developed by Robert Griesemer, Rob Pike, and Ken Thompson at Google. In this article, we'll be looking at how we could install the Go compiler on our Windows operating system. Also how we could configure the Visual Studio Code editor to work with the Go programming language. So, let's get started.
 
My environment details are as follows:
  1. Windows 10 Home
  2. Visual Studio Code 1.52.1

Installing Go Programming Language

 
Let's start by installing the Go language. The first thing you need to do is navigate to the following URL:
 
https://golang.org/dl/
 
This will load the downloads page for Go.
 
How To Set Up Go With VSCode For Windows 
Download the installer for Windows operating system and start the installation.
 
The installation process is quite straightforward however if you face any challenges while installing the language do let me know in the comment section.
 
Once the installation is complete, open your terminal and run the following command.
  1. $ go version    
  2. go version go1.15.7 windows/amd64  

Adding GOPATH environment variable

 
GOPATH is an environment variable that is used to specify the root of your Go workspace. By default, the workspace located at %USERPROFILE%/go for Windows.
 
To configure GOPATH follow the steps mentioned below:
  • Create a new folder in your C drive called "C:\Projects\Go".
  • Open Run dialog by pressing win + r and type the sysdm.cpl ,3 inside the run dialog. And then click OK.
How To Set Up Go With VSCode For Windows
  • This will open the System Properties. Now hit the Environment Variables button at the bottom of that dialog box.
How To Set Up Go With VSCode For Windows
  • Now in the Environment Manager dialog click the new button from the System Variables section.
How To Set Up Go With VSCode For Windows
  • Set the GOPATH as name and C:\Projects\Go as its value, and hit the OK button.
How To Set Up Go With VSCode For Windows
 
This will configure the GOPATH for your PC.
 
To check if the GOPATH has been appropriately configured open run dialog by pressing win + r and type %GOPATH% and hit the OK button. If it takes you to the C:\Projects\Go directory, the configuration was successful.
 

Installing Visual Studio Code

 
Visual Studio Code is an open-source lightweight code editor by Microsoft that comes bundled with support for TypeScript, JavaScript, and Node.js. However, you could easily get support for Go Language by installing a handy extension. 
 
To install the Visual Studio Code editor, open the link mentioned below:
 
https://code.visualstudio.com/Download 
 
And download the installer for Windows. Again, the installation process is quite straightforward, however, if you face any challenges while installing the editor please let me know in the comments section.
 
After the installation process is complete launch the editor and open the extension manager by pressing Ctrl + Shift + x.
 
In the extension manager, search box type go and hit enter.
 
How To Set Up Go With VSCode For Windows 
 
In the search results, you'll find the Go extension by the GO team at Google. Hit the install button and let the installation process complete.
 
After installation, open the command palette by pressing Ctrl + Shift + p and run the Go: Install/Update Tools command.
 
How To Set Up Go With VSCode For Windows
 
This will present you with a list of tools you need to install. 
 
How To Set Up Go With VSCode For Windows
 
Install everything listed in the dropdown.
 
Let's write some code.
 
Once the installation process is complete create a new hello.go file in your vscode editor and add the following hello world program to the file.
  1. package main    
  2. import "fmt"    
  3. func main() {    
  4.     fmt.Println("Hello world...")    
  5. }    
Now let's test the autocomplete feature by deleting Println("Hello world...") and hitting Ctrl + Space after fmt.
 
How To Set Up Go With VSCode For Windows
 
You could also try running the program by using the following command in the terminal.
  1. $ go run hello.go
  2. hello world...  
And that's it!
 
To find more information on Go language or Visual Studio Code please visit the links mentioned below:
  • Visual Studio Code: https://code.visualstudio.com 
  • Go: https://golang.org 
I hope you found this article helpful. In case you've any queries or feedback regarding the installation process, feel free to drop a note in the comment section.


Similar Articles