AlgoMaster Logo

Installing Go

Last Updated: May 22, 2026

Low Priority
7 min read

Before you can write Go code, you need Go installed on your machine. This lesson walks through installation on macOS, Linux, and Windows, then covers the key environment variables that control where Go finds your code and tools.

Downloading Go

Go releases are distributed from the official site at go.dev/dl. You'll see downloads for macOS, Linux, and Windows, with installers for the current stable release at the top of the page.

Pick the download that matches your operating system and CPU architecture. Most modern Macs use Apple Silicon (arm64), while most Windows and Linux machines use x86-64 (amd64). If you're unsure which architecture your machine uses, the sections below show how to check.

The diagram below shows the three installation paths.

Installing on macOS

You have two options on macOS: the official .pkg installer or Homebrew. Both work well. The .pkg installer is the most straightforward. Homebrew is convenient if you already use it for other tools.

Option 1: The .pkg Installer

  1. Go to go.dev/dl and download the macOS installer. Choose the ARM64 version for Apple Silicon Macs (M1/M2/M3/M4) or the x86-64 version for older Intel Macs.

Not sure which you have? Open Terminal and run:

If the output is arm64, you have Apple Silicon. If it's x86_64, you have Intel.

  1. Open the downloaded .pkg file and follow the installer prompts. It installs Go to /usr/local/go and adds /usr/local/go/bin to your system PATH automatically.
  1. Open a new Terminal window (this is important, the old window won't see the updated PATH) and verify:

You should see something like:

Option 2: Homebrew

If you use Homebrew, installation is one command:

Homebrew handles the download, places Go in its own prefix, and links the go binary onto your PATH. Verify with:

The output looks the same as above. One thing to keep in mind: Homebrew manages the Go version for you. When a new Go release comes out, brew upgrade go updates it. With the .pkg installer, you'd download and run the new installer manually.

Installing on Linux

Linux uses a tarball that you extract manually. This is the standard approach across all Linux distributions.

  1. Download the tarball from go.dev/dl. You can do this from the command line:

Replace the version number with the latest version shown on the download page.

  1. Remove any previous Go installation, then extract the tarball to /usr/local:

The rm -rf step is important. Extracting a new version over an old one can leave stale files that cause confusing errors.

  1. Add Go's bin directory to your PATH. Open your shell profile (~/.bashrc for Bash, ~/.zshrc for Zsh) and add this line:
  1. Reload your profile and verify:

Unlike macOS and Windows, the Linux installation doesn't update your PATH automatically. If you skip step 3, your shell won't find the go command.

Installing on Windows

  1. Download the .msi installer from go.dev/dl.
  1. Run the installer. It installs Go to C:\Program Files\Go by default, which is fine for most setups. It also adds C:\Program Files\Go\bin to your system PATH.
  1. Open a new Command Prompt or PowerShell window and verify:

Same as macOS, you need a new terminal window to see the updated PATH. Any command prompt that was open before the installation won't have it.

Verifying Your Installation

Regardless of your operating system, two commands confirm that Go is set up correctly.

go version

This prints the installed Go version and your platform:

The format is go version goX.Y.Z OS/ARCH. If this command works, Go is installed and on your PATH.

go env

This shows all of Go's environment variables and their current values:

The output is long, but a few key variables matter right now. You can also query a specific variable:

The next section covers what these variables mean.

Key Environment Variables

Go uses environment variables to control where it stores code, tools, and caches. You don't need to change most of them, the defaults work well. But understanding what they do helps you troubleshoot when something isn't where you expect.

VariableDefaultWhat It Controls
GOROOTWhere Go was installed (e.g., /usr/local/go)Location of the Go standard library and compiler
GOPATH$HOME/go (macOS/Linux) or %USERPROFILE%\go (Windows)Where go install puts binaries and where older pre-modules code lived
GOBIN$GOPATH/binWhere go install places compiled binaries
GOPROXYhttps://proxy.golang.org,directModule proxy for downloading dependencies

GOROOT

GOROOT points to the directory where Go itself is installed. The standard library source code, the compiler, and the linker all live here. You almost never need to change this. If you installed Go using the methods above, it's set automatically.

One common mistake: manually setting GOROOT to the wrong directory. If your Go tools start behaving strangely, check that GOROOT actually points to your Go installation. Most of the time, leaving it unset and letting Go figure it out is the right call.

GOPATH

GOPATH was critical before Go introduced modules in Go 1.11. All Go source code had to live inside $GOPATH/src. That's no longer the case. With modules (which is how all modern Go projects work), you can create projects anywhere on your file system.

GOPATH still matters for one thing: go install puts compiled binaries in $GOPATH/bin. So if you install a Go tool like golangci-lint using go install, the binary ends up there.

To run installed tools directly from your terminal, add $GOPATH/bin to your PATH. In your shell profile:

GOBIN and GOPROXY

GOBIN overrides where go install puts binaries. If it's not set, binaries go to $GOPATH/bin. Most developers leave it unset.

GOPROXY controls which module proxy Go uses to download dependencies. The default (https://proxy.golang.org,direct) means Go first checks the official proxy, then falls back to fetching directly from the source. This default is fine for almost everyone.

Setting Up a Project Directory

With modules, your Go code can live anywhere. There's no requirement to use $GOPATH/src or any special directory. Pick a location that makes sense for your workflow.

For the e-commerce application we'll be building throughout this course, let's create a dedicated workspace:

This is just a regular directory. Nothing Go-specific about it yet. You'll initialize a Go module here and write your first program. For now, the important point is that you're free to organize your projects however you like, as long as each project has its own go.mod file.

Here's a typical directory layout you might end up with as the project grows:

Don't worry about this structure yet. It's here to give you a sense of where things are headed.

Editor and IDE Setup

A good editor makes Go development significantly more productive. Go has excellent tooling support, and most editors can provide autocompletion, inline error checking, automatic formatting, and documentation on hover.

Visual Studio Code with the official Go extension is the most popular setup in the Go community.

  1. Install VS Code if you don't have it already.
  1. Open VS Code, go to the Extensions panel (the square icon in the sidebar), search for "Go", and install the extension published by the Go Team at Google.
  1. When you open a .go file for the first time, VS Code prompts you to install additional tools (including gopls, the Go language server). Click Install All.

You can also install these tools manually from the command line:

  1. Verify gopls is available:

If this command fails with "command not found," make sure $GOPATH/bin is on your PATH (covered in the environment variables section above).

The Go extension gives you:

FeatureWhat It Does
AutocompletionSuggests functions, types, and fields as you type
Error highlightingShows compilation errors before you run the code
Auto-formattingRuns gofmt on save so your code follows Go standards
Go to definitionJump to any function or type definition
Documentation on hoverSee function signatures and docs without leaving the editor

GoLand

GoLand by JetBrains is a dedicated Go IDE. It works out of the box with no additional setup, all the Go tools are built in. It's a paid product, though JetBrains offers free licenses for students and open-source projects. If you're used to IntelliJ or PyCharm, you'll feel at home.

Vim/Neovim with gopls

If you prefer Vim or Neovim, the key piece is gopls, the same language server that powers the VS Code extension. Plugins like vim-go or Neovim's built-in LSP client connect to gopls and provide the same autocompletion, error checking, and formatting capabilities.

The common thread across all these editors is gopls. It's the official Go language server, and it powers the smart features in every editor that supports the Language Server Protocol.

Troubleshooting Common Issues

Even with straightforward installers, a few things can trip you up.

ProblemLikely CauseFix
go: command not foundGo's bin directory isn't on your PATHAdd /usr/local/go/bin to your PATH (see installation steps above)
go version shows an old versionA previous Go installation is shadowing the new oneRun which go (macOS/Linux) or where go (Windows) to see which binary your shell finds. Remove the old one.
gopls not found after installing$GOPATH/bin isn't on your PATHAdd $(go env GOPATH)/bin to your PATH
GOROOT mismatch errorsGOROOT manually set to wrong directoryUnset it with unset GOROOT and let Go detect it automatically

When something isn't working, go env is your best diagnostic tool. It shows you exactly what Go thinks its configuration is. Compare those values against what you expect, and you'll usually spot the issue quickly.