Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Introduction to Go  ›  Lesson

Setting Up Go

Setting up the Environment 12 minInstalling Go gives you one toolchain driven by the go command, and every project lives in a module described by a go.mod file, which can sit in any folder.

Setting Up Go

Before tally can count anything, your computer needs the Go toolchain. The good news: Go ships as one download, and a single command, go, compiles, runs, tests and formats everything.

The rule

Install one toolchain, start one module, and let go drive.

Install. Download the installer for your system from the official site, go.dev, or use a package manager such as Homebrew (brew install go). Then check it in a new terminal:

go version

If it prints a line such as go version go1.26.0 darwin/arm64, Go is installed and on your PATH. The version number on your machine may differ; anything recent is fine.

Start a module. A module is a folder of Go code with a go.mod file at its root. The file names the module and records which Go version and which outside packages it needs.

mkdir tally
cd tally
go mod init example.com/tally

That creates:

module example.com/tally

go 1.26

The module path looks like a web address because shared modules are usually named after where they live, such as github.com/you/tally. For a private project any sensible name works.

Let go drive. You do not configure a build system. go run, go build and go test read go.mod and work out the rest. If a module asks for a newer Go than you have, the go command can even download that toolchain for you.

A few names you will see:

  • GOROOT is where Go itself is installed. You rarely touch it.
  • GOPATH (by default ~/go) holds downloaded modules and installed tools. Old tutorials say your code must live inside it; with modules, that is no longer true. Put projects anywhere.
  • go env prints all these settings.

For an editor, install the Go extension for VS Code or use GoLand. Both talk to gopls, the Go language server, for completion, jump-to-definition and live errors.

The shortcut

Every new project is the same three moves: check, make a folder, init.

Starting tally from scratchStep 1 of 4
  1. Check

    go version prints a version, so the toolchain works.

The classic mistake is copying an old tutorial that sets up $GOPATH/src/... folders by hand. Modules replaced that workflow years ago.

Drills

Answer fast — trust the rule.

quick drill

Which command confirms that Go is installed and on your PATH?

quick drill

What does go mod init example.com/tally create?

quick drill

Where must a modern Go project live?

quick drill

What is gopls?

Remember

  • Install one toolchain, start one module, and let go drive.
  • Shortcut: check (go version), make a folder, go mod init.
  • Trap: old GOPATH-only tutorials; with modules your code can live anywhere.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainFrom nothing to a module

A friend has just installed Go and wants to start tally in a folder on their desktop. Explain the steps from checking the install to having a module ready, and what the go.mod file is for.