Go September 27, 2024 Aditya Rawas

How to Install Go on Linux, macOS, and Windows

If you’re excited to start coding in Go (Golang), you’re in the right place. This guide walks you through installing Go on Linux, macOS, and Windows — plus how to configure your editor, understand Go’s environment variables, and fix the most common installation errors.

Head to the official Go download page first and grab the installer for your operating system.


Quick Overview

OSInstaller TypeDefault Install Path
Linux.tar.gz archive/usr/local/go
macOS.pkg installer/usr/local/go
Windows.msi installerC:\Program Files\Go

Installing Go on Linux

Step 1: Remove Any Previous Go Installation

If you’ve installed Go before, always remove the old version first to avoid conflicts:

sudo rm -rf /usr/local/go

Step 2: Extract the Archive

Extract the downloaded tarball into /usr/local:

sudo tar -C /usr/local -xzf go1.23.1.linux-amd64.tar.gz

Important: Never extract into an existing /usr/local/go folder — always remove it first. Extracting on top of an old version can corrupt the installation.

Step 3: Add Go to Your PATH

Open $HOME/.profile (for your user only) or /etc/profile (system-wide) and append:

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

Apply the change immediately without restarting:

source $HOME/.profile

If you use zsh, add the same line to ~/.zshrc and run source ~/.zshrc.

Step 4: Verify the Installation

go version

You should see output like:

go version go1.23.1 linux/amd64

Installing Go on macOS

Step 1: Run the Installer

After downloading the .pkg file, open it and follow the installation wizard. Go installs automatically to /usr/local/go.

Step 2: Verify PATH

The .pkg installer typically adds /usr/local/go/bin to your PATH automatically. Verify by opening a new terminal and running:

go version

If the command isn’t found, add it manually. For zsh (default on macOS Catalina and later):

echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.zshrc
source ~/.zshrc

For bash:

echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bash_profile
source ~/.bash_profile

Step 3: Confirm with go env

go env GOPATH
go env GOROOT

If both print valid paths, your installation is complete.


Installing Go on Windows

Step 1: Run the MSI Installer

Open the downloaded .msi file and follow the installation wizard. Go installs to C:\Program Files\Go by default.

Step 2: Verify PATH

The installer automatically adds Go to your system PATH. Close and reopen any Command Prompt or PowerShell windows — existing terminals won’t see the updated PATH.

Step 3: Verify the Installation

Open a new Command Prompt or PowerShell and run:

go version

Expected output:

go version go1.23.1 windows/amd64

Understanding GOROOT and GOPATH

Two environment variables control how Go finds its tools and your code.

GOROOT

GOROOT is where Go itself is installed — the standard library, compiler, and toolchain. You almost never need to set this manually; Go sets it automatically based on where it was installed.

go env GOROOT
# Output: /usr/local/go

Don’t change GOROOT unless you’re installing multiple Go versions side-by-side (use a tool like gvm for that).

GOPATH

GOPATH is your personal Go workspace — where downloaded packages and compiled binaries go. It defaults to $HOME/go on Linux/macOS and %USERPROFILE%\go on Windows.

go env GOPATH
# Output: /home/aditya/go

Inside GOPATH, Go maintains three directories:

~/go/
├── bin/      ← compiled binaries (go install puts executables here)
├── pkg/      ← compiled package cache
└── src/      ← legacy source location (not needed with Go modules)

With Go modules (Go 1.11+), you don’t need to put your projects inside GOPATH/src anymore. You can create a Go project anywhere on your filesystem. GOPATH is mainly relevant for the bin directory.

Add GOPATH/bin to Your PATH

To run tools installed with go install (like gopls, air, golangci-lint), add the Go bin directory to your PATH:

export PATH=$PATH:$(go env GOPATH)/bin

Add this to your .zshrc or .bash_profile alongside the GOROOT export.


Setting Up VS Code for Go

VS Code with the official Go extension is the most popular Go development environment.

Step 1: Install the Go Extension

Open VS Code, go to Extensions (Ctrl+Shift+X), and search for “Go” by the Go Team at Google. Install it.

Step 2: Install Go Tools

Open the Command Palette (Ctrl+Shift+P) and run:

Go: Install/Update Tools

Select all tools and click OK. This installs essential tools including:

ToolPurpose
goplsLanguage server (autocomplete, go-to-definition)
dlvDelve debugger
staticcheckStatic analysis / linter
golangci-lintComprehensive linter
goimportsAuto-format + organize imports

Step 3: Verify the Extension Works

Create a file main.go:

package main

import "fmt"

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

You should see autocomplete suggestions as you type. Run it with:

go run main.go

Verifying Your Full Environment

Run go env to see your complete Go environment:

go env

Key variables to check:

VariableWhat It Should Show
GOROOTPath to your Go installation
GOPATHYour workspace (~/go by default)
GOARCHYour CPU architecture (amd64, arm64)
GOOSYour operating system (linux, darwin, windows)
GOMODCACHEWhere downloaded modules are cached

Troubleshooting Common Errors

”go: command not found”

The Go binary isn’t in your PATH. Make sure /usr/local/go/bin (Linux/macOS) or C:\Program Files\Go\bin (Windows) is in your PATH, and that you’ve opened a new terminal after making changes.

”permission denied” on Linux

You forgot sudo when extracting the archive. Run:

sudo tar -C /usr/local -xzf go*.tar.gz

Changes to .profile / .zshrc not taking effect

Run source ~/.zshrc (or the relevant file) to apply changes in the current terminal session without restarting.

Multiple Go versions on the same machine

Use gvm (Go Version Manager) on Linux/macOS to install and switch between Go versions:

gvm install go1.23.1
gvm use go1.23.1 --default

On Windows, use g or manage versions manually.

Windows: go found in PowerShell but not CMD (or vice versa)

The PATH change may only be in the user environment, not the system environment. Open System Properties → Environment Variables and confirm C:\Program Files\Go\bin is in the System PATH (not just User PATH).


What to Do After Installing Go

Once Go is running, the natural next steps are:

  1. Write your first Go program — create main.go with package main and run it with go run main.go
  2. Initialize a Go module — run go mod init your-module-name in your project directory, or follow the complete Go modules tutorial
  3. Learn Go fundamentals — start with Go data types and then Go structs
  4. Explore the standard library — Go ships with an excellent standard library at pkg.go.dev

Key Takeaways

  • Download from go.dev/dl and follow the OS-specific steps — the installer handles most configuration automatically.
  • GOROOT is where Go lives. GOPATH is your workspace — defaults to ~/go.
  • With Go modules, you can put projects anywhere — you’re not limited to GOPATH/src.
  • Add both /usr/local/go/bin and $(go env GOPATH)/bin to your PATH to access Go tools.
  • Install the VS Code Go extension and run “Go: Install/Update Tools” for a complete development environment.
  • Run go env to inspect your full environment and diagnose issues.
Aditya Rawas

Written by

Aditya Rawas

Full-stack engineer writing deep-dives on JavaScript, TypeScript, React, AWS, Docker, and Kubernetes. Passionate about making complex engineering concepts accessible to developers at every level.