Installing Go

A step-by-step guide to installing Go on Windows, macOS and Linux, verifying the setup with go version, and understanding modules and workspaces.

Prerequisites

Learning objectives

  • Install Go on Windows, macOS or Linux
  • Verify the installation with go version
  • Understand why GOPATH is no longer needed with modules

To write Go you need the Go toolchain: the compiler, the standard library and the go command. This lesson installs Go on Windows, macOS or Linux, checks that it works, and clears up the old questions about GOPATH.

Download from go.dev/dl

The official downloads live at go.dev/dl. The page offers an installer or archive for every platform, and it always highlights the current stable release. When in doubt, pick the package that matches your operating system and CPU (most modern machines use the amd64 or arm64 build).

Install on Windows

Download the .msi installer from go.dev/dl and double-click it. The wizard copies Go to C:\Program Files\Go and adds the go command to your PATH automatically. Close and reopen your terminal afterwards so the new PATH is picked up.

If you prefer a package manager, winget works too:

winget install GoLang.Go

Install on macOS

The simplest option is Homebrew:

brew install go

Alternatively, download the .pkg installer from go.dev/dl and run it; it installs Go to /usr/local/go and puts go on your PATH.

Install on Linux

Use the official archive from go.dev/dl. Remove any old install first, then extract the new one into /usr/local (replace the version number with the current release):

sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.24.0.linux-amd64.tar.gz

Then add Go’s bin directory to your PATH by appending this line to ~/.profile (or ~/.bashrc):

export PATH=$PATH:/usr/local/go/bin

Open a new terminal, or run source ~/.profile, so the change takes effect.

Verify the installation

Whatever your platform, confirm Go is available by printing its version:

go version

You should see a line similar to this one:

go version go1.24.0 linux/amd64

If instead you get “command not found”, your PATH is not set yet — reopen the terminal or re-check the PATH step for your operating system.

Do I still need GOPATH?

No. Since Go modules became the default (Go 1.16), you keep your projects anywhere on disk. You no longer place source code under GOPATH/src, and you do not set GO111MODULE by hand.

GOPATH still exists — it defaults to ~/go — but now it is only a cache and tools directory: downloaded dependencies land in GOPATH/pkg/mod, and binaries installed with go install land in GOPATH/bin. A project becomes a module as soon as it contains a go.mod file, which you create with go mod init. That single file, not a special folder, defines your workspace.

Run a program to confirm it works

The best proof that Go is installed is running a real program. Create a file called hello.go with the following complete program:

package main

import "fmt"

func main() {
	fmt.Println("Go is installed!")
}

From the same folder, run it with:

go run hello.go

Go compiles and executes the file, printing:

Go is installed!

Common mistakes

  • Forgetting to reopen the terminal. PATH changes only apply to new shells, so go version may fail until you open a fresh terminal.
  • Keeping two installs. Installing via Homebrew and the .pkg can leave two go binaries; check which one wins with which go.
  • Recreating GOPATH by habit. You do not need a ~/go/src folder for your projects anymore — a go.mod file is enough.

Practice

Install Go using the method for your platform, verify it with go version, then write and run a program that prints your name in a greeting.

Show the solution

After go version prints a version line, create greeting.go:

package main

import "fmt"

func main() {
	fmt.Println("Hello, I am learning Go!")
}

Run it with go run greeting.go. Seeing your message in the terminal confirms that the compiler and standard library are both working.

Summary

  • Download Go from go.dev/dl, or use brew install go / winget / the Linux archive.
  • Confirm the install with go version, then run a program with go run.
  • Modules replaced GOPATH for organising code: a go.mod file defines your project, wherever it lives.

With Go installed, you are ready to build your first Go program, and then move on to variables and types.

Your progress is stored only in this browser. No account is required.

Search

Search runs entirely in your browser.