Installing Go
Install the go command, confirm it with go version, and learn why GOPATH is no longer something you set.
go versionThe Go toolchain is the set of programs that build, run and check your code. You reach all of them through one command named go. Installing Go means putting that command on your computer and making your shell able to find it.
Installing
Downloads live at go.dev/dl. macOS and Windows have installers that do the whole job. On Linux you unpack the archive into /usr/local/go and add /usr/local/go/bin to PATH. PATH is the list of directories your shell searches when you type a command name. When a shell says go: command not found, PATH is nearly always the reason.
Confirm the install with go version. It prints the toolchain version, then the operating system and processor it was built for, like go version go1.27.0 darwin/arm64.
GOPATH is history
Older Go required every project to sit inside one directory tree named by GOPATH. That is over. Module mode became the default in Go 1.16, and a project can now live in any folder you like. GOPATH still exists, still defaults to $HOME/go, and is only where the toolchain keeps downloaded dependencies and the programs go install builds. You do not manage it.
One install, several versions
Since Go 1.21, when a project asks for a newer Go than the one you installed, the go command downloads that version and uses it for that project. You do not keep several toolchains by hand.
Example
// A one-file program whose only job is to prove the toolchain can build and run code.
// Save it as main.go in an empty directory, then run: go run .
package main
import "fmt"
func main() {
fmt.Println("install check passed")
}
// Output:
// install check passed
When to use it
- Set up a new laptop so it can build the team's Go services.
- Work out why a freshly installed command cannot be found by the shell.
- Check which toolchain version a build machine is actually using.
More examples
Checking the install
go env prints the toolchain's own settings, one per line and in the order you asked for them. GOROOT is where Go itself lives, GOPATH is where downloads and installed programs go, and the blank third line means GOBIN is unset, which is normal. Run this first whenever something builds on one machine and not another.
$ go version
go version go1.27.0 darwin/arm64
$ go env GOROOT GOPATH GOBIN
/usr/local/go
/Users/you/go
Installing on Linux from the archive
Removing /usr/local/go first matters: unpacking on top of an old install leaves files from both versions mixed together. The export line only lasts for the current shell, so add it to your shell's startup file to make it permanent. This is also the pattern used inside Docker images and CI machines.
$ curl -LO https://go.dev/dl/go1.27.0.linux-amd64.tar.gz
$ sudo rm -rf /usr/local/go
$ sudo tar -C /usr/local -xzf go1.27.0.linux-amd64.tar.gz
$ export PATH=$PATH:/usr/local/go/bin
$ go version
go version go1.27.0 linux/amd64Making installed programs runnable
The first line puts the default install directory on PATH, which is the fix for "I ran go install and the command still does not exist". go env -w writes the setting into Go's own configuration file so it survives new shells; use it when you would rather keep your binaries in one directory you already have on PATH.
$ echo 'export PATH=$PATH:$HOME/go/bin' >> ~/.zshrc
$ go env -w GOBIN=$HOME/bin # optional: send installed programs somewhere else
Discussion