Install Go & Set Up VS Code

Go · Lesson 2 of 32 6 min read Updated

Before you can write Go programs you need the Go toolchain: the go command plus the compiler and standard library. It is free, open source and installs in a couple of minutes.

In this lesson you will install Go, check that it works, set up VS Code for Go, and run a tiny program to prove everything is ready.

Download Go

Always download Go from the official site, go.dev/dl. The page offers an installer for every common system. At the time of writing the newest version is Go 1.27.3; take whatever 1.27.x (or newer) version is listed at the top.

SystemFile to pickWhere Go is installed
Windows (64-bit).msi installer for windows-amd64C:\Program Files\Go by default
macOS (Apple chip).pkg installer for darwin-arm64/usr/local/go
macOS (Intel).pkg installer for darwin-amd64/usr/local/go
Linux (64-bit).tar.gz archive for linux-amd64/usr/local/go (you extract it)

The words amd64 and arm64 describe the processor family. Most Windows laptops sold in India use amd64 (Intel or AMD chips). Newer Macs use arm64.

Install on your system

Windows: double-click the .msi file and click through the steps. When it finishes, close every open terminal window and open a new one, so it picks up the updated PATH (the list of folders where Windows looks for programs).

macOS: open the .pkg file and follow the prompts. The installer also adds /usr/local/go/bin to your PATH.

Linux: remove any old copy, then extract the archive into /usr/local. Never extract a new version on top of an old /usr/local/go folder, because mixed files break the install.

Terminal
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.27.3.linux-amd64.tar.gz
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.profile
source ~/.profile

The echo line adds Go's bin folder to your PATH permanently, and source reloads the settings in the current terminal. Use the exact file name you downloaded.

Check that Go works

Open a new terminal and run:

Terminal
go version
Output
go version go1.27.3 windows/amd64

You should see your version and your system, for example linux/amd64 or darwin/arm64. If you see "command not found" or "go is not recognized", the PATH was not updated: open a new terminal, or sign out and back in.

Go also has an environment report. Two settings are useful to know:

Terminal
go env GOROOT GOPATH
Output
C:\Program Files\Go
C:\Users\Aarav\go

GOROOT is where Go itself is installed. GOPATH is a folder in your home directory where Go keeps downloaded modules (in pkg\mod) and programs you install with go install (in bin). You do not need to change either one. Your projects can live in any folder you like.

Set up VS Code

You can write Go in any editor, but VS Code with the official extension gives you autocomplete, error underlines, formatting on save and a debugger.

  1. Install VS Code from code.visualstudio.com.
  2. Open the Extensions panel and install Go (published by the Go Team at Google).
  3. Open the Command Palette (Ctrl+Shift+P) and run Go: Install/Update Tools. Select all tools and press OK.

The most important tool is gopls (say "go please"), the Go language server. It reads your code as you type and powers autocomplete and error checking. Another is dlv, the standard Go debugger. GoLand from JetBrains is a good paid alternative.

Run a test program

Let us prove the setup works. Create a folder, start a module (a Go project, explained in Modules & Packages) and add one file:

Terminal
mkdir hello
cd hello
go mod init example.com/hello
Output
go: creating new go.mod: module example.com/hello

Now create main.go in that folder with this code:

Go
package main

import (
	"fmt"
	"runtime"
)

func main() {
	fmt.Println("Go is ready on", runtime.GOOS)
	fmt.Println("Version:", runtime.Version())
}

Run it from the same folder:

Terminal
go run .
Output
Go is ready on windows
Version: go1.27.3

The runtime package reports facts about the running program: runtime.GOOS is the operating system and runtime.Version() is the Go version that built it. The dot in go run . means "the package in this folder".

Common mistakes

  • Using an old terminal window. Terminals read PATH when they open. After installing, always open a new one.
  • Running go run main.go outside a module. It works for one file, but bigger programs need a go.mod file. Make go mod init a habit for every new folder.
  • Installing two Go versions. An old Go from apt and a new one in /usr/local/go can both be on the PATH. Run go version and check which one wins.

Key points

  • Download Go only from go.dev/dl and pick the file for your system and processor.
  • Windows and macOS installers set the PATH for you; on Linux you add /usr/local/go/bin yourself.
  • go version confirms the install; go env shows settings such as GOROOT and GOPATH.
  • VS Code plus the Go extension and gopls gives autocomplete, formatting and debugging.
  • Start every project with go mod init and run it with go run ..

Exercise

Install Go, then create a folder greeting with a module named example.com/greeting. Write a program that prints your name, your city and the operating system it runs on. Run it with go run ..

Show solution
Terminal
mkdir greeting
cd greeting
go mod init example.com/greeting
Go
package main

import (
	"fmt"
	"runtime"
)

func main() {
	fmt.Println("Name: Meera")
	fmt.Println("City: Kochi")
	fmt.Println("System:", runtime.GOOS)
}
Output
Name: Meera
City: Kochi
System: linux

The last line shows windows, darwin (macOS) or linux, depending on your computer.

Quick Quiz

1. Which command confirms that Go is installed and shows its version?

2. What is gopls?

3. You installed Go but the terminal says "go is not recognized". What should you try first?

Learn Go with a mentor

Free lessons get you started. Our Programming & Software Development training adds real projects and code reviews from working developers.

  • Project-based learning
  • Mentor code reviews
  • Free counselling call