Install Golang from the official distribution for your operating system. After installation, the go command becomes the center of your workflow. The same command is used for running, building, testing, formatting, documentation, modules, and dependency management.
A beginner-friendly setup is Golang, VS Code or GoLand, the Golang editor extension, and a terminal. You do not need a large framework to begin because the standard library already includes packages for files, HTTP, JSON, testing, command-line flags, strings, time, and more.
After installing, close and reopen your terminal so the updated PATH is loaded. If go version does not work, the most common issue is that the Golang binary directory was not added to PATH.
go version
go env GOPATH
go env GOMOD
Older Golang projects often depended heavily on GOPATH. Modern Golang development uses modules. A module is a versioned collection of packages defined by a go.mod file.
When go env GOMOD prints a path to go.mod, you are inside a module. When it prints nothing or /dev/null depending on the environment, you are outside a module. For new projects, create a module first.
| Term | Meaning |
|---|---|
GOPATH | Workspace location used by older workflows and module cache defaults. |
GOMOD | Path to the active go.mod file. |
go.mod | Module name, Golang version, and dependency requirements. |
go.sum | Dependency checksums for repeatable builds. |
Create a new folder, initialize a module, add a main.go file, and run it. The command go run . compiles and executes the current module in one step, which is convenient while learning.
The module path can be a repository-style path such as github.com/company/project. For local practice, an example path is fine. The path becomes important when other modules import your packages.
mkdir hello-golang
cd hello-golang
go mod init example.com/hello-golang
go run .
An executable Golang program uses package main and a function named main. This function is the entry point of the compiled program.
Save this file as main.go inside the module folder. Then run go run .. If the program prints the message, your setup is working.
package main
import "fmt"
func main() {
fmt.Println("Golang setup is ready")
}
Golang ships with a complete command-line workflow. You should learn the core commands early because they appear in almost every real project.
go build compiles a binary, gofmt standardizes formatting, and go test runs tests. These tools make Golang projects consistent even across large teams.
| Command | Purpose |
|---|---|
go run . | Compile and run the current module. |
go build | Create a binary executable. |
gofmt -w . | Format Golang files in place. |
go test ./... | Run all tests in the module. |
go doc fmt.Println | Read documentation from the terminal. |
go mod tidy | Clean missing and unused dependency requirements. |
Use an editor that can format on save, show type errors, run tests, and navigate to definitions. VS Code with the official Golang extension is a common choice, while GoLand provides a full IDE experience.
Turn on format on save. Golang teams expect formatted code, and gofmt removes style debates from the workflow. If your editor reports missing tools, allow it to install the recommended Golang tools.
go command handles running, building, testing, formatting, docs, and modules.
go.mod file.
package main and func main().
gofmt or format on save to keep code consistent.
go test ./... regularly as projects grow.
Explore 500+ free tutorials across 20+ languages and frameworks.