Last Updated: May 22, 2026
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.
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.
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.
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.
.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.You should see something like:
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.
Linux uses a tarball that you extract manually. This is the standard approach across all Linux distributions.
Replace the version number with the latest version shown on the download page.
/usr/local:The rm -rf step is important. Extracting a new version over an old one can leave stale files that cause confusing errors.
bin directory to your PATH. Open your shell profile (~/.bashrc for Bash, ~/.zshrc for Zsh) and add this line: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.
.msi installer from go.dev/dl.C:\Program Files\Go by default, which is fine for most setups. It also adds C:\Program Files\Go\bin to your system PATH.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.
Regardless of your operating system, two commands confirm that Go is set up correctly.
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.
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.
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.
| Variable | Default | What It Controls |
|---|---|---|
GOROOT | Where 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/bin | Where go install places compiled binaries |
GOPROXY | https://proxy.golang.org,direct | Module proxy for downloading dependencies |
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 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 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.
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.
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.
.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:
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:
| Feature | What It Does |
|---|---|
| Autocompletion | Suggests functions, types, and fields as you type |
| Error highlighting | Shows compilation errors before you run the code |
| Auto-formatting | Runs gofmt on save so your code follows Go standards |
| Go to definition | Jump to any function or type definition |
| Documentation on hover | See function signatures and docs without leaving the editor |
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.
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.
Even with straightforward installers, a few things can trip you up.
| Problem | Likely Cause | Fix |
|---|---|---|
go: command not found | Go's bin directory isn't on your PATH | Add /usr/local/go/bin to your PATH (see installation steps above) |
go version shows an old version | A previous Go installation is shadowing the new one | Run 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 PATH | Add $(go env GOPATH)/bin to your PATH |
GOROOT mismatch errors | GOROOT manually set to wrong directory | Unset 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.