GoLand
 
Get GoLand

GOROOT and GOPATH

Last modified: 12 November 2024

Go tools expect a certain layout of the source code. GOROOT and GOPATH are environment variables that define this layout.

GOROOT is a variable that defines where your Go SDK is located. You do not need to change this variable, unless you plan to use different Go versions.

In Go development, the GOPATH variable, which defaults to $HOME/go on Unix and %USERPROFILE%\go on Windows, serves several purposes:

  • Binaries are installed to $GOBIN by go install, with $GOBIN defaulting to $GOPATH/bin.

  • Modules are cached in $GOMODCACHE by go get, defaulting to $GOPATH/pkg/mod.

  • Checksum database state is cached in $GOPATH/pkg/sumdb by go get.

For details about the GOPATH variable, refer to the go command documentation.

The concept of GOPATH development mode, which precedes Go modules, is now deprecated. Prior to Go modules, the GOPATH was used to install binaries and compiled packages, as well as downloading source code to specified paths. For more information about developing with GOPATH, refer to GOPATH development mode at go.dev.

Consider the following video where we change the Go SDK from 1.16 Beta 1 to 1.20.1.