GOPATH

  • The Go path is used to resolve import statements.
  • On Unix, the value is a colon-separated string.
  • On Windows, the value is a semicolon-separated string.

If the environment variable is unset, GOPATH defaults to a subdirectory named "go" in the user's home directory $HOME/go

Run go env GOPATH to see the current GOPATH (its better to run this intead of echoing the GOPATH variable, because if it is unset it will show the default gopath)

go env GOPATH

/Users/mimigonz/go

Structure of a gopath directory

Each directory listed in GOPATH must have a prescribed structure:

src directory
pgk directory
Example
Here's an example directory layout:
    GOPATH=/home/user/go
    /home/user/go/
        src/
            foo/
                bar/               (go code in package bar)
                    x.go
                quux/              (go code in package main)
                    y.go
        bin/
            quux                   (installed command)
        pkg/
            linux_amd64/
                foo/
                    bar.a          (installed package object)