Go Fix, Crash & Optimization Guide
Fix common Go setup, module, GOPATH and proxy errors, with real build-cache and performance tuning steps for Go developers.
Go Fix, Crash & Optimization Guide
Go (Golang) is a compiled, statically typed language from Google, popular for backend services and CLI tools. This guide covers the toolchain install, Go modules, and build/cache problems developers encounter.
Install / First Setup
- Official (cross-platform): download the installer from go.dev/dl, or on Linux extract the tarball:
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.xx.linux-amd64.tar.gz - macOS:
brew install go - Windows:
winget install GoLang.Go - Add Go's bin to PATH:
export PATH=$PATH:/usr/local/go/bin(Linux/macOS) or%USERPROFILE%\go\binfor your binaries.
Verify with go version.
Common Issues & Fixes
go: command not found
Cause: Go's bin directory is not on your PATH.
Fix: Add /usr/local/go/bin (Linux/macOS) or C:\Go\bin (Windows) to PATH, then reopen the terminal and run go version.
go: cannot find main module / no go.mod
Cause: You're running a go command outside a module, and modules are enabled (the default since Go 1.16).
Fix: Initialize a module in your project root: go mod init example.com/myproject. Then go build/go run work from inside it.
missing go.sum entry / checksum mismatch
Cause: go.sum is out of sync with go.mod, or a dependency's hash can't be verified.
Fix: Run go mod tidy to reconcile, or go mod download to fetch and record checksums. Commit both go.mod and go.sum.
go get fails behind a firewall / private modules
Cause: The default proxy proxy.golang.org is unreachable, or the module is private.
Fix: For a custom proxy set GOPROXY=https://your-proxy. For private repos, exclude them from the proxy with GOPRIVATE=github.com/yourorg/* (and matching GONOSUMDB/GONOSUMCHECK as needed) so Go fetches them directly via git.
Build cache grows too large / stale
Cause: Go caches build artifacts in GOCACHE, which can become large or corrupted.
Fix: Inspect with go env GOCACHE; clear with go clean -cache. Use go clean -modcache to drop downloaded modules.
Performance & Optimization
- Low-End: Rely on Go's build cache so incremental builds are fast; avoid pulling huge dependency trees. Use
go build(notgo runfor hot loops in prod). - Mid: Parallelize compilation with
GOMAXPROCS(defaults to CPU count). Strip binaries for smaller artifacts:go build -ldflags="-s -w". - Workstation: Use
-trimpathfor reproducible builds (go build -trimpath), and setGOCACHE/GOMODCACHEon a fast SSD. For tests,go test -p Ncontrols parallelism;go buildalready caches per-package.
General: Go's module cache (GOMODCACHE) is shared across projects, so repeated go mod download is usually instant.
Version & Compatibility Notes
- Go Modules became opt-in in Go 1.11 and on-by-default in Go 1.16 (
GO111MODULE=onis the default behavior now). - Go has no formal LTS line; the project supports roughly the last two major versions with security fixes.
GOPATHis largely irrelevant for module-based projects but still defines wherego installputs binaries ($GOPATH/bin).- For exact current version numbers and support policy, consult official release notes.
FAQ
Q: Do I still need to set GOPATH?
A: For module-based projects (the default today), no. GOPATH mainly determines where go install places binaries ($GOPATH/bin). You still add that bin dir to PATH.
Q: What's the difference between go build and go run?
A: go run main.go compiles and executes in one step (good for quick tests) but does not leave a binary. go build produces a binary you can deploy or re-run.
Q: How do I pin dependency versions?
A: Use go get example.com/[email protected], then go mod tidy. Versions are recorded in go.mod and verified by go.sum.
Q: Why is go get failing on a private repo?
A: Go routes private modules through the proxy by default. Set GOPRIVATE=github.com/yourorg/* so it fetches via git instead, and ensure your SSH/git credentials are configured.
Q: How do I free disk space used by Go?
A: go clean -cache clears the build cache and go clean -modcache clears downloaded modules.
Q: How do I cross-compile for another OS?
A: Set GOOS and GOARCH, e.g. GOOS=linux GOARCH=amd64 go build. No extra toolchain is needed for standard cross-compiles.
Related Guides
- Rust Fix & Optimization Guide
- Python Fix & Optimization Guide
- Java Fix & Optimization Guide
- Build Time Calculator
Accuracy Note
Commands and paths reflect common, real-world setups as of 2026-08. Always verify against your installed version and OS. When in doubt, consult the official Go documentation.
Calculator Recommended Adjustment Params
Run the Build Time Calculator with the values referenced in this guide to validate your rig before and after the fix.