Install Go

In this lesson you’ll install Go 1.27 on Windows, macOS or Linux, check that it works with go version, and set up VS Code so it understands your Go code. It takes about ten minutes, and you only have to do it once.

Download Go

Go is free and open source. I always install it from the official download page, go.dev/dl, because that’s where the newest release shows up first. At the top of the page you’ll see “Featured downloads” for the most common systems. Pick the one that matches your computer:

Your computerFile to download
Windows (most PCs)go1.27.3.windows-amd64.msi
Windows on ARMgo1.27.3.windows-arm64.msi
Mac with Apple silicon (M1 and later)go1.27.3.darwin-arm64.pkg
Mac with an Intel processorgo1.27.3.darwin-amd64.pkg
Linux on a regular PC or servergo1.27.3.linux-amd64.tar.gz
Linux on ARM (Raspberry Pi 4/5 with a 64-bit OS, ARM servers)go1.27.3.linux-arm64.tar.gz

The version number will be higher if a newer release came out after I wrote this. That’s fine: take the newest one. In the file names, amd64 means a 64-bit Intel or AMD processor and arm64 means a 64-bit ARM processor. Not sure which one you have? On a Mac, open the Apple menu and choose About This Mac: if it lists an “Apple M” chip, you want arm64. On Linux, run uname -m: x86_64 means amd64, aarch64 means arm64.

Install on Windows

  1. Double-click the .msi file you downloaded and follow the prompts. By default it installs Go in Program Files, and it adds Go to your PATH so you can run the go command from any folder.
  2. Close every open Command Prompt, PowerShell or terminal window. Windows only hands the updated PATH to windows you open after the installer finished.
  3. Open a new terminal (press the Start button, type cmd or PowerShell, press Enter) and check the installation, as shown in “Check that Go works” below.

Install on macOS

  1. Double-click the .pkg file and follow the prompts. The package installs Go in /usr/local/go and puts /usr/local/go/bin on your PATH (it does that by creating the file /etc/paths.d/go).
  2. Close and reopen the Terminal app so it picks up the new PATH.

Go 1.27 needs macOS 13 Ventura or later. On an older Mac, the installer for Go 1.27 won’t help you; you’d have to stay on an older Go release.

Install on Linux

On Linux you get a .tar.gz archive that you unpack into /usr/local. First remove any older Go in that spot, because unpacking a new archive on top of an old /usr/local/go leaves you with a broken mix of both. In a terminal, in the folder where you downloaded the file:

sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.27.3.linux-amd64.tar.gzCode language: Bash (bash)

(Use the file name you actually downloaded.) Next, add Go’s bin folder to your PATH. Open ~/.profile in an editor and add this line at the end:

export PATH=$PATH:/usr/local/go/binCode language: Bash (bash)

Changes to ~/.profile apply the next time you log in. To use them right away in the current terminal, run source ~/.profile.

Package managers: Homebrew, apt and friends

You can also install Go with a package manager. On a Mac with Homebrew, brew install go works well and brew upgrade go keeps it current. Linux distributions ship Go too (sudo apt install golang-go on Debian and Ubuntu, sudo dnf install golang on Fedora).

Distribution packages often lag behind, sometimes by several releases, especially on long-term-support versions of Debian and Ubuntu. This tutorial uses Go 1.27. If your package manager gives you something older, uninstall it and use the official download instead.

Check that Go works

Open a new terminal and run:

go versionCode language: Bash (bash)

On my Mac it prints this:

go version go1.27.3 darwin/arm64Code language: plaintext (plaintext)

The last part is your operating system and processor, so on a typical Windows PC you’ll see windows/amd64 and on Linux linux/amd64. As long as you see a version of 1.27 or newer, you’re done with the install.

If you get go: command not found (macOS, Linux) or 'go' is not recognized as an internal or external command (Windows), your terminal can’t find Go yet. Almost always the fix is to close the terminal and open a new one. If that doesn’t help, check that Go’s bin folder is on your PATH (on Linux, the export line above).

GOROOT, GOPATH and GOBIN in one minute

Older tutorials spend pages on setting up a “GOPATH workspace”. You don’t need to do any of that anymore. Since Go 1.16, the go command works in module mode by default: a project is just a folder with a go.mod file in it, and it can live anywhere on your disk. You’ll create one in Build and run a Go program.

You’ll still run into these three names, so here’s what they mean today:

  • GOROOT is where Go itself is installed, such as /usr/local/go. The go command figures it out on its own. Don’t set it.
  • GOPATH is a folder where Go keeps downloaded modules (in pkg/mod) and the programs you install. It defaults to go in your home folder: $HOME/go on macOS and Linux, %USERPROFILE%\go on Windows. Most people never change it. Your own code does not have to go in there.
  • GOBIN is where go install puts programs. If you don’t set it, that’s the bin folder inside your GOPATH, so $HOME/go/bin.

To see the values on your machine, ask the go command:

go env GOROOT GOPATHCode language: Bash (bash)

One thing worth doing now: add that bin folder to your PATH, so tools you install later with go install run from anywhere. On macOS (zsh) add this line to ~/.zshrc; on Linux add it to ~/.profile:

export PATH="$PATH:$(go env GOPATH)/bin"Code language: Bash (bash)

On Windows, add %USERPROFILE%\go\bin to your user Path variable (search the Start menu for “environment variables”).

Set up VS Code

You can write Go in any text editor, but a good editor shows mistakes while you type and fixes your formatting for you. I use Visual Studio Code: it’s free, runs on Windows, macOS and Linux, and the Go team maintains its Go extension. (GoLand, Vim, Emacs and others work fine too; see Editor plugins and IDEs on go.dev.)

  1. Install VS Code from code.visualstudio.com.
  2. Open the Extensions view (the four-squares icon on the left, or Ctrl+Shift+X, Cmd+Shift+X on a Mac), search for Go, and install the one published by the Go Team at Google (its ID is golang.go).
  3. Open a folder and create a file that ends in .go. The extension activates and, if it’s missing, installs gopls, the Go language server. When it’s ready, the status bar in the bottom right shows your Go version.

gopls (say “go please”) is the program that does the real work behind the scenes. It gives you code completion, shows compile errors as red squiggles before you even run anything, lets you jump to the definition of a function, and formats your file the standard Go way every time you save.

If VS Code ever complains that tools are missing or outdated, open the Command Palette (Ctrl+Shift+P, or Cmd+Shift+P on a Mac), run Go: Install/Update Tools, select all, and press OK.

A quick test drive

Let’s make sure everything fits together. Create a folder called hello, open it in VS Code, and create a file named hello.go with this content:

package main

import "fmt"

func main() {
	fmt.Println("Hello, world!")
}Code language: Go (go)
Hello, world!Code language: plaintext (plaintext)

Open the terminal inside VS Code (Terminal, New Terminal) and run go run hello.go. If you see Hello, world!, Go and your editor are ready. You don’t need to understand the code yet: I’ll take it apart line by line in Hello, world: your first Go program.

Updating Go later

Go gets a new major release about every six months, with bug-fix releases in between. To update, download the new version and install it the same way: run the new installer on Windows or macOS, or repeat the remove-and-unpack step on Linux. For installing several versions side by side, see Managing Go installations.

Also good to know: if you work on a project whose go.mod asks for a newer Go than you have, the go command can download the right toolchain for you automatically. The details are in Go Toolchains; for this tutorial you won’t need it.

Practice

Run go env GOPATH and open that folder in your file manager. It may not exist yet; Go creates it the first time it needs it. Then try this small exercise: write a program that prints the Go version it was built with, and your operating system and processor. Hint: the runtime package has runtime.Version(), runtime.GOOS and runtime.GOARCH.

Show a solution
package main

import (
	"fmt"
	"runtime"
)

func main() {
	fmt.Println("Go version:", runtime.Version())
	fmt.Println("System:", runtime.GOOS, runtime.GOARCH)
}Code language: Go (go)
Go version: go1.27.3
System: darwin arm64Code language: plaintext (plaintext)

Your output depends on your machine; on a Windows PC the second line reads System: windows amd64.

Key takeaways

  • Download Go from go.dev/dl and use the official installer (Windows, macOS) or archive (Linux).
  • Package managers work, but distribution packages can be several releases behind.
  • go version in a new terminal tells you whether the install worked.
  • You don’t need to set GOROOT or GOPATH. Projects are modules and can live in any folder.
  • VS Code with the official Go extension (powered by gopls) gives you completion, live errors and format-on-save.