← Back to Go Course | Chapter 1: Setup & Basics | Lesson 2 of 7

Installing Go

Installing Go means downloading the official toolkit onto your computer so it knows how to turn your code into a running program.

Downloading the Go Toolchain

Go ships as a single installer per platform containing the compiler, standard library, and tools like 'go build' and 'go fmt'. On macOS and Windows you run a graphical installer; on Linux you typically extract a tarball to /usr/local/go or use your distribution's package manager. Because this is an installation step performed in your own terminal, it isn't something that runs inside this page's live-code box.

Note: Always get Go from the official https://go.dev/dl page or your OS package manager (e.g. 'brew install go', 'apt install golang-go').

Example: Downloading the Go Toolchain

bash
# Linux
wget https://go.dev/dl/go1.22.0.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.22.0.linux-amd64.tar.gz

# Windows
# Download MSI installer from https://go.dev/dl/
# Run the installer — it sets PATH automatically

⚠️ Run this command in your terminal.

Adding Go to your PATH

The Go binaries live in a bin folder that your shell needs to know about so typing go works from any directory. On Linux/macOS this usually means exporting the Go install location onto the PATH environment variable; on Windows the installer does this automatically. Without this step, the terminal reports 'go: command not found' even though Go is installed.

Note: Add this line to ~/.bashrc, ~/.zshrc, or your shell's profile file so it persists across terminal sessions.

Example: Adding Go to your PATH

bash
# Linux/macOS — add to ~/.bashrc or ~/.zshrc
export PATH=$PATH:/usr/local/go/bin

# Windows — PATH is set automatically by the MSI installer

⚠️ Run this command in your terminal.

Verifying the Installation

Once installed, run 'go version' in a terminal to confirm the toolchain is set up correctly and see which release you have. This is the quickest sanity check before starting any project, and it's the command most bug reports ask for first.

Example: Verifying the Installation

bash
go version

⚠️ Run this command in your terminal.

What Gets Installed

Installing Go gives you the go command-line tool, which bundles the compiler, the standard library source, formatter (gofmt), and dependency manager -- all in one download, unlike languages that need separate installers for a compiler, package manager, and linter. This single-tool philosophy is part of what keeps Go project setup simple.

Example: What Gets Installed

markup
package main

import "fmt"

func main() {
	fmt.Println("If this compiles and runs, your Go installation works!")
}
Common Mistakes
  1. Downloading Go from an unofficial mirror instead of go.dev/dl, risking an outdated or tampered installer.
  2. Forgetting to add Go's bin directory to the system PATH, so the go command is not found in the terminal.
  3. Installing multiple conflicting versions of Go side by side without removing the old one first, causing 'go version' to report the wrong version.
Chapter Summary
  • Go is installed from the official installer or package manager at go.dev/dl for Windows, macOS, and Linux.
  • After installation, the go command must be available on your system PATH.
  • 'go version' confirms the installed compiler version.
  • Modern Go (1.16+) no longer requires manually configuring GOPATH for everyday projects.
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.