Installing Go & Development Environment
Before writing production Go, you need a reliable toolchain: the Go SDK, an editor with gopls (Go language server), and environment variables configured correctly.
Introduction
Before writing production Go, you need a reliable toolchain: the Go SDK, an editor with gopls (Go language server), and environment variables configured correctly.
This lesson covers installing Go 1.22+ on macOS, Linux, or Windows; choosing between VS Code + Go extension and GoLand; and verifying your setup with go version and go env. Enterprise teams pin Go versions in go.mod and CI so every developer and pipeline builds identically.
A correct setup prevents hours of "works on my machine" friction. You will initialize your first module, understand module cache and vendor folders, and configure workspace settings — habits interviewers expect from day one.
The story
A platform team onboarding five engineers across macOS, Linux, and Windows CI runners standardizes on Go 1.22+ with a checked-in go.mod and toolchain directive. Without that pin, one developer compiles with Go 1.21 while GitHub Actions uses 1.22, and a for range over an integer loop behaves differently — a subtle bug that only surfaces in the pipeline.
They install gopls for IDE navigation, enable go vet and staticcheck in pre-commit hooks, and verify setup with a hello-world binary that prints the runtime version. That five-minute setup prevents hours of "works on my laptop" incidents before code reaches a Kubernetes cluster.
Understanding the topic
Key concepts
- The Go toolchain includes the compiler, linker, go fmt, go test, go mod, and godoc.
- GOROOT points to the SDK installation; GOPATH is legacy — modules replaced it as the default workflow.
- go.mod declares module path and Go version; go.sum records dependency checksums for reproducibility.
- gopls provides IDE features: autocomplete, go-to-definition, refactoring, and diagnostics.
- Cross-compilation: GOOS and GOARCH build binaries for any supported platform from one machine.
- asdf, mise, or goenv manage multiple Go versions on developer laptops.
Step-by-step explanation
- Download Go from go.dev/dl or install via Homebrew (brew install go), apt, or winget.
- Run go version to confirm 1.22.x and go env to inspect GOROOT, GOPATH, GOOS, GOARCH.
- Install VS Code with the Go extension (gopls installs on first open) or JetBrains GoLand.
- Create a project: mkdir hello && cd hello && go mod init example.com/hello && go run .
- Open the folder in your IDE — gopls indexes packages for autocomplete and error highlighting.
- Commit go.mod and go.sum; add .gitignore entries for bin/ and coverage artifacts.
Practical code example
Initialize a module and verify the toolchain with a minimal go.mod and main.go:
// go.modmodule github.com/techlearningpro/hellogo 1.22// main.gopackage mainimport "fmt"func main() {fmt.Println("TechLearningPRO Go setup verified!")fmt.Printf("Module: %s\n", "github.com/techlearningpro/hello")}
Output
TechLearningPRO Go setup verified! Module: github.com/techlearningpro/hello
Line-by-line code explanation
module github.com/techlearningpro/hellois the first line of go.mod and gives the module its name, which is also the import path prefix for its packages.go 1.22declares the Go language version this module is written for.package mainbegins main.go, the second file shown, and marks it as an executable program.import "fmt"brings in the standard formatting package; a single import needs no parentheses.func main() {defines the entry point, the function that runs when the program starts.fmt.Println("TechLearningPRO Go setup verified!")prints the text and a newline. If you see this message, your Go toolchain can build and run the program.fmt.Printf("Module: %s\n", "github.com/techlearningpro/hello")prints a second line, inserting the string argument where %s appears. The text matches the module name in go.mod, but it is typed here as a plain string rather than read from go.mod.
Key takeaway: The go directive in go.mod pins the minimum language version. CI should use the same version via actions/setup-go or equivalent.
Real-world use
Where you'll use this in production
- Onboarding new hires to a Go microservice monorepo with pinned Go version in go.mod.
- Setting up CI agents (GitHub Actions, GitLab CI) with matching go-version matrix.
- Teaching bootcamp students an identical environment across macOS and Linux laptops.
- Cross-compiling Linux amd64 binaries from a Mac developer machine for Docker builds.
Best practices
- Pin Go version in go.mod and CI configuration for every team repository.
- Run go fmt ./... and go vet ./... before every commit; add golangci-lint in CI.
- Use go work for local multi-module development without replace hacks.
- Store secrets in environment variables or secret managers — never in source control.
- Verify install with go version after every SDK upgrade.
- Enable Go modules mode explicitly if legacy tooling interferes: GO111MODULE=on.
- Document setup steps in README.md for reproducible onboarding.
Common mistakes
- Installing an outdated Go version — check go.dev for current stable release.
- Mixing GOPATH mode with modules — always use go mod init for new projects.
- Ignoring go.sum changes in PRs — they protect against dependency tampering.
- Checking compiled binaries into Git — add /bin or /dist to .gitignore.
- Not installing gopls — IDE shows no autocomplete or type information.
Advanced interview questions
Interview Prep
Practice concise answers, then expand each card for the explanation.
1BeginnerQuestionWhat does the Go toolchain include?+
Answer
2BeginnerQuestionPurpose of go.mod?+
Answer
3IntermediateQuestionDifference between GOROOT and GOPATH?+
Answer
4IntermediateQuestionHow cross-compile for Linux from macOS?+
Answer
5AdvancedQuestionDescribe a professional Go repo layout.+
Answer
Summary
Install Go 1.22+ and an IDE (VS Code + Go extension or GoLand). Verify with go version; create projects via go mod init and go run. Pin Go versions in go.mod for team and CI consistency. Run go fmt and go vet early; add golangci-lint in CI. Next lesson: your first complete Go program structure and entry point.