Understand the contract
Install Go using the instructions for your operating system on go.dev, then verify the installation with go version. The toolchain includes a compiler, formatter, test runner and package tools. You can start with a terminal and a text editor; editor integration can come after the first program runs.
A module is a project boundary recorded in go.mod. Create it inside a new directory with go mod init. The example uses an illustrative module path, example.com/hello; it does not download code from that address. Your own published library would use the path from which consumers import it.
Work through the example
Run these commands in a terminal, then add the main.go file from the next lesson. After that, go run . compiles and executes the package, while go build . produces a binary for the current platform. Use go test ./... once the module contains test files.
go version
mkdir hello
cd hello
go mod init example.com/hello
go env GOMODWatch this boundary
If the terminal cannot find go, check the installation directory and PATH using the official platform instructions. Reopen the terminal after changing its environment. Avoid setting GOPATH as a workaround for a missing executable; a module-based exercise can live outside GOPATH.
Practice with a changed input
Write down the output of go version and go env GOMOD. After adding main.go, compare go run . with go build . and locate the resulting executable.
Lesson 2 of 50
View the full Go basics seriesReferences & further reading
Need help with your Go backend?
I work with engineering teams on focused Go and Kubernetes platform engagements, with limited consulting availability.
Explore Go consulting services