Tuesday, May 9, 2017

GOPATH and Go Environment Variables

I was a bit confused by The Internet's many comments on Go environment variables.  Here's my simple-minded take.

Go Environment Variables
  • go env will show you all the environment variables Go cares about and what Go believes them to be set to.
  • You can ignore most of them, they have details 
Basic GOPATH
  • Default GOPATH is $HOME/go.
  • If you're fine with this default, you don't need to set this.
  • I set it anyways, just for fun

Don't Set GOROOT or GOROOT_BOOTSTRAP

GOROOT is used to handle non-standard installations.  GOROOT_BOOTSTRAP is used when compiling Go from source.  In a future post I'll cover using these when building Go from source.

Using Multiple GOPATHs

When you're first starting out, plan on keeping your various projects together under $HOME/go.

Later, you may want to have multiple GOPATHs:

  • You might be working for different clients, and not run the risk of mingling their code or dependencies.
  • You might have particular revision control needs; for example, a larger project may have a subproject written in go.
I don't quite grok Go's project/subdirectory mapping at this time.  I'm studying it now and I'll write about it in the very near future.


blogodex = {"toc" : "GOPATH", "idx" : ["environment variables"]};

No comments:

Post a Comment