Install Go & Set Up VS Code
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.
| System | File to pick | Where Go is installed |
|---|---|---|
| Windows (64-bit) | .msi installer for windows-amd64 | C:\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.
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 ~/.profileThe 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:
go versiongo 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:
go env GOROOT GOPATHC:\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.
- Install VS Code from code.visualstudio.com.
- Open the Extensions panel and install Go (published by the Go Team at Google).
- 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:
mkdir hello
cd hello
go mod init example.com/hellogo: creating new go.mod: module example.com/hello
Now create main.go in that folder with this code:
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:
go run .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
PATHwhen they open. After installing, always open a new one. - Running
go run main.gooutside a module. It works for one file, but bigger programs need ago.modfile. Makego mod inita habit for every new folder. - Installing two Go versions. An old Go from
aptand a new one in/usr/local/gocan both be on thePATH. Rungo versionand 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
PATHfor you; on Linux you add/usr/local/go/binyourself. go versionconfirms the install;go envshows settings such asGOROOTandGOPATH.- VS Code plus the Go extension and
goplsgives autocomplete, formatting and debugging. - Start every project with
go mod initand run it withgo 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
mkdir greeting
cd greeting
go mod init example.com/greetingpackage main
import (
"fmt"
"runtime"
)
func main() {
fmt.Println("Name: Meera")
fmt.Println("City: Kochi")
fmt.Println("System:", runtime.GOOS)
}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?
go version prints the installed version and the operating system and processor.
2. What is gopls?
gopls reads your code as you type and gives the editor autocomplete, diagnostics and more.
3. You installed Go but the terminal says "go is not recognized". What should you try first?
Terminals read PATH when they start, so an old window does not know about the new install.
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
