← Back to Go Examples
Getting Started · Go

Install Go

Go ships as a single download: the compiler, the code formatter, the test runner, and the package manager all arrive together, and there is no separate runtime to install afterwards. This page takes you from nothing to a working go command on Linux, macOS, or Windows, then has you build and run a first program so you know the whole chain works. Pick your operating system, follow one step, and skip the others — every path ends at the same go version check.

The finish line — what you'll see when it's done
$ go version go version go1.27.1 linux/amd64 $ go run . Hello, Go!
Current release go1.27.1
This guide has a few 💡 Explain it simply prompts. When you reach one, answer it out loud in plain words before revealing the answer. An install you can explain is an install you can fix when it breaks.
STEP 01

Know what you're installing.

Some languages make you assemble a toolchain from parts: a compiler here, a package manager there, a formatter from somewhere else. Go doesn't. One archive from go.dev/dl gives you the go command, and that single command does everything:

  • go run — compile and run a program in one step, leaving nothing behind.
  • go build — produce a standalone binary you can copy to another machine.
  • go fmt — format your code to the one official Go style. Arguments about braces are over.
  • go test — run the tests in the current package.
  • go mod — manage modules and their dependencies.

The install is roughly 250 MB unpacked and lives in one directory. Removing Go later means deleting that directory. There's nothing scattered around the system to hunt for.

Which version

Always take the current release from go.dev/dl. As of this writing that's go1.27.1, and the commands below use that number — swap in whatever the download page shows today. Go keeps strong backward compatibility, so newer is safe: every example on this site runs on any release from the last few years.

One download, one directory, one command. That's the whole toolchain.

STEP 02

Linux — unpack the tarball into /usr/local.

This works on any distribution — Ubuntu, Debian, Fedora, Arch, a Raspberry Pi, a rented VPS. Open a terminal and download the archive for your architecture. Most desktops and servers are amd64; a Raspberry Pi or an ARM server wants arm64 instead. uname -m tells you which you have (x86_64 means amd64, aarch64 means arm64).

terminal — download and unpackthree commands
# 1. download (check go.dev/dl for the current version number)
wget https://go.dev/dl/go1.27.1.linux-amd64.tar.gz

# 2. remove any previous install so nothing stale is left underneath
sudo rm -rf /usr/local/go

# 3. unpack into /usr/local — this creates /usr/local/go
sudo tar -C /usr/local -xzf go1.27.1.linux-amd64.tar.gz

Step 2 matters more than it looks. Go's own instructions say to remove the old directory rather than extract over it, because a newer archive may not contain every file the old one did, and leftovers from two versions in the same tree cause strange build errors later. Deleting first is the safe path.

Now the go binary exists at /usr/local/go/bin/go, but your shell doesn't know to look there yet. Tell it by adding that directory to your PATH. Append this line to ~/.profile (or ~/.bashrc if that's where your shell setup lives):

~/.profile — add to the end
export PATH=$PATH:/usr/local/go/bin

Then reload it so the current terminal picks up the change:

source ~/.profile

Any terminal you open from now on will already have it. Jump to Step 05 to verify.

Why not apt install golang?

You can, and it works — but distribution packages lag the real release by a year or more. Ubuntu 24.04 ships Go 1.22, and the go.dev tarball is the version the Go team actually supports. The tarball route takes the same three commands and gives you today's compiler, so it's the one this site recommends.

💡 Explain it simply

You unpacked Go, typed go version, and the shell said command not found. Explain in plain words what PATH is and why the file being on disk wasn't enough.

Reveal a plain-language answer

PATH is the shell's short list of folders to search when you type a command. The go file was sitting in /usr/local/go/bin, but that folder wasn't on the list, so the shell never looked there. Adding the folder to PATH doesn't move anything — it just tells the shell one more place to check. That's also why the fix is a one-line edit and not a reinstall.

STEP 03

macOS — Homebrew, or the .pkg installer.

If you already use Homebrew, this is one command. Brew picks the right build for Apple Silicon or Intel and handles the PATH for you:

terminal — Homebrew
brew install go

Upgrading later is brew upgrade go. That's the whole maintenance story.

Without Homebrew

Download the .pkg installer from go.dev/dl — there's one for Apple Silicon (darwin-arm64) and one for Intel Macs (darwin-amd64). If you're not sure which Mac you have, open the Apple menu → About This Mac and look at the Chip line: “Apple M…” is arm64, “Intel” is amd64. Double-click the package and click through. It installs to /usr/local/go and drops a file in /etc/paths.d/ so every new terminal already has go on the PATH.

Open a new terminal

Whichever route you took, a terminal that was already open before the install won't see the new PATH. Close it and open a fresh one before running the check in Step 05. This one detail accounts for most “I installed it but it says command not found” reports.

STEP 04

Windows — the .msi installer, or winget.

The quickest route is the package manager built into Windows 10 and 11. Open PowerShell or Windows Terminal and run:

PowerShell — winget
winget install GoLang.Go

Or download the .msi installer from go.dev/dl (you want windows-amd64 for almost every PC) and run it. Accept the defaults; it installs to C:\Program Files\Go and adds that folder's bin directory to your PATH for you.

Either way, close PowerShell and open a new window before testing — Windows only hands out the updated PATH to programs started after the change.

PowerShell — check it took
go version
go version go1.27.1 windows/amd64
Using WSL?

If you do your development inside Windows Subsystem for Linux, you're really on Linux — follow Step 02 inside the WSL terminal instead. A Go installed on the Windows side isn't visible from WSL, and vice versa, so install it where you'll actually be typing go run.

STEP 05

Verify it.

One command tells you whether the install worked and which version you've got:

go version
go version go1.27.1 linux/amd64

The last part will read darwin/arm64 on an Apple Silicon Mac or windows/amd64 on a PC. Any version string at all means you're done with installation. If you want to see where Go put itself and where it will keep downloaded packages:

go env GOROOT GOPATH
/usr/local/go /home/you/go

GOROOT is the toolchain you just installed. GOPATH is a cache directory Go creates on first use for modules it downloads. You don't need to set either one — the defaults are right, and you'll never need to put your own code under GOPATH.

If it says command not found

  1. Open a new terminal. The old one was started before PATH changed.
  2. Linux: confirm the file exists with ls /usr/local/go/bin/go. If it does, the missing piece is the export PATH line from Step 02 — check it's in the file your shell actually reads (~/.profile for login shells, ~/.bashrc for bash, ~/.zshrc for zsh).
  3. Windows: a reboot is the blunt fix, and it works.
STEP 06

Your first program, as a module.

Modern Go organises code into modules. A module is just a folder with a go.mod file in it that names the module and records the Go version it targets. Every project starts the same way: make a folder, initialise the module, add a file.

terminal — create the module
mkdir hello
cd hello
go mod init example/hello
go: creating new go.mod: module example/hello

The name example/hello is arbitrary for a local project; it only matters if you publish the code for others to import. Now create main.go in that folder:

main.go7 lines
package main

import "fmt"

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

Three things to notice. package main marks this as a program rather than a library. import "fmt" pulls in the formatted-printing package from the standard library. And func main() is where the program starts — every runnable Go program has exactly one. Run it:

go run .
Hello, Go!

The . means “the package in the current directory.” go run compiled the program to a temporary location, ran it, and cleaned up. When you want a binary you can keep:

go build
./hello
Hello, Go!

That hello file (hello.exe on Windows) is a complete, statically linked executable. Copy it to another machine with the same OS and it runs with no Go install, no runtime, no dependencies. That property is a large part of why people reach for Go for servers and command-line tools.

Format as you go

Run go fmt ./... in any project and every file is rewritten into the standard Go style. Set your editor to run it on save and you'll never think about formatting again. Every code block on this site has already been through it.

💡 Explain it simply

Explain to a friend what go mod init did, and what the difference is between go run . and go build.

Reveal a plain-language answer

go mod init wrote one small file, go.mod, that says “this folder is a project called example/hello.” That file is how Go knows where the project starts and, later, which outside packages it depends on. go run . is the quick loop: compile, run, throw the result away — perfect while you're editing. go build is the same compile but it keeps the result as a file you can hand to someone. Same code, one keeps the output and one doesn't.

STEP 07

An editor that understands Go.

Any text editor works, but the Go team ships a language server called gopls that gives you completion, jump-to-definition, and errors as you type. Two easy ways to get it:

  • VS Code — install the official Go extension (published by the Go Team at Google). The first time you open a .go file it offers to install gopls and the other tools; say yes.
  • Vim / Neovim — install the server yourself with go install golang.org/x/tools/gopls@latest, then point your LSP config at it. It lands in ~/go/bin, so add that directory to your PATH the same way you did in Step 02.

Upgrading later

Go releases twice a year. To move up: on Linux repeat the three commands from Step 02 with the new version number; on macOS brew upgrade go; on Windows winget upgrade GoLang.Go or run the newer .msi. Your projects keep working — Go's compatibility promise means code written for an older release compiles on a newer one.

STEP 08

Where to go next.

You have a compiler, a module, and a program that prints. Everything else on the Go examples page assumes exactly that and nothing more.

1

Basic Go

A quick-reference sheet: variables, slices, maps, functions, structs, goroutines, and channels, each with a complete-the-code exercise.

2

Learning to Code by Bowling

Build a real program from scratch, then rebuild it a quarter of the size. The lesson is how to improve code you've already written.

3

The projects

A concurrent fetcher, a chat server, a URL shortener, a blog. Each one is a complete program you can go run the moment you paste it in.