GOPATH?In early versions of Go (before Go modules were introduced in Go 1.11 / made default in Go 1.16), the GOPATH environment variable defined the workspace directory where all your Go code, dependencies, and binaries lived.
It typically looked like this:
$GOPATH/
βββ src/ # source code for your projects and dependencies
βββ pkg/ # compiled package objects
βββ bin/ # compiled executables (from `go install`)
For example:
GOPATH=/home/maelton/go,/home/maelton/go/src/github.com/maelton/myapp/home/maelton/go/binThis structure was mandatory back then β you couldnβt just put your project anywhere.
Because Go needed a deterministic way to:
Without modules, the GOPATH was essentially the global "workspace root."
Since Go modules (go mod init, go.mod) became the default in Go 1.16 (2021), you no longer need to put code inside GOPATH.
With modules: