Blog Logo

13-May-2025 ~ 3 min read

Setup Golang On New Mac


In this post, we will walk through the steps required to set up a minimal Golang development environment on a new macOS machine. This includes installing Go, configuring environment variables and creating a simple Hello, World! program.

Table of Contents

🧠 Mental Model: “From Zero to Go”

Think of this like building a minimal Go ecosystem:

  1. System setup (Tooling prerequisites)

  2. Install Go (Language/runtime)

  3. Environment wiring (PATH, GOPATH, etc.)

  4. Hello World creation (Write, build, run)

✅ Step-by-Step Breakdown

1. 💻 Prerequisites

Make sure your Mac has Command Line Tools installed:

xcode-select --install

Required for basic tools like git and make

2. ⬇️ Install Go

Option 1: Use official Go installer Download macOS pkg from: https://go.dev/dl/

It installs to /usr/local/go by default.

Option 2: Use Homebrew

brew install go

This installs Go and sets it up under /opt/homebrew/ (for Apple Silicon) or /usr/local/ (for Intel).

3. 🧭 Set Up Environment Variables

Open (or create) your shell config file (~/.zshrc for zsh or ~/.bash_profile for bash):

# Go binary location
export PATH=$PATH:/usr/local/go/bin

# Workspace (optional but common)
export GOPATH=$HOME/go

# Ensure Go binaries installed via `go install` are accessible
export PATH=$PATH:$GOPATH/bin

Then reload:

source ~/.zshrc  # or source ~/.bash_profile

🔑 Global Environment Variables

VariablePurposeExample
PATHMust include /usr/local/go/bin/usr/local/go/bin
GOPATHWorkspace directory for Go projects/Users/yourname/go
GOROOT(Optional) Root of Go install (auto)/usr/local/go
GOBIN(Optional) Where Go installs binaries$GOPATH/bin

⚠️ GOPATH is less important with Go modules (modern Go projects), but it’s still relevant for some tooling.

4. 👋 Write Your First Program

mkdir -p ~/go/hello
cd ~/go/hello

Create hello-world.go:

package main

import "fmt"

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

5. ▶️ Run It

You can compile and run:

go run hello-world.go

Or build:

go build hello-world.go
./hello-world

🧠 Optional: Go Modules (Modern Approach)

If you’re using Go 1.13+ (which you should), you can use modules instead of GOPATH:

go mod init hello
go run .

No need to worry about GOPATH layouts as much.

🧪 Verify Setup

Check versions and paths:

go version
go env

This will show:

GOROOT (should be where Go is installed)

GOPATH (if set)

GO111MODULE (usually set to on)