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
| OS | Installer Type | Default Install Path |
|---|---|---|
| Linux | .tar.gz archive | /usr/local/go |
| macOS | .pkg installer | /usr/local/go |
| Windows | .msi installer | C:\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/gofolder — 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/srcanymore. You can create a Go project anywhere on your filesystem.GOPATHis mainly relevant for thebindirectory.
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:
| Tool | Purpose |
|---|---|
gopls | Language server (autocomplete, go-to-definition) |
dlv | Delve debugger |
staticcheck | Static analysis / linter |
golangci-lint | Comprehensive linter |
goimports | Auto-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:
| Variable | What It Should Show |
|---|---|
GOROOT | Path to your Go installation |
GOPATH | Your workspace (~/go by default) |
GOARCH | Your CPU architecture (amd64, arm64) |
GOOS | Your operating system (linux, darwin, windows) |
GOMODCACHE | Where 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:
- Write your first Go program — create
main.gowithpackage mainand run it withgo run main.go - Initialize a Go module — run
go mod init your-module-namein your project directory, or follow the complete Go modules tutorial - Learn Go fundamentals — start with Go data types and then Go structs
- 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.
GOROOTis where Go lives.GOPATHis 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/binand$(go env GOPATH)/binto 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 envto inspect your full environment and diagnose issues.
Related Articles
Understanding Structs in Go: The Foundation of Data Modeling
Learn how Go structs work — defining custom types, creating instances, passing by value vs pointer, adding methods, constructor functions, struct tags for JSON, anonymous structs, and struct embedding.
GoCreating Your First Go Module: A Step-by-Step Tutorial
Learn how to create, link, and publish Go modules — build a reusable math utilities module, use go mod init, the replace directive, go workspaces, semantic versioning, and publish to pkg.go.dev.
GoDemystifying Go's fmt.Sprintf: A Practical Guide
Master Go's fmt.Sprintf() with format verbs (%v, %s, %d, %q, %b, %x), width and padding, zero-padding, argument indexing, fmt.Fprintf for HTTP responses, fmt.Sscanf for parsing, and common pitfall fixes.
Written by
Aditya RawasFull-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.