How to build Go development environment


Build Go development environment is always easy. Take Linux OS as an example (Because I work as a root user, so if you login as a non-root user, maybe you need sudo to execute some commands), what you should do is just download the binary package which matches your system from here, and uncompress it:

  1. # wget https://storage.googleapis.com/golang/go1.6.2.linux-amd64.tar.gz
  2. # tar -C /usr/local/ -xzf go1.6.2.linux-amd64.tar.gz

Now, there is an extra go directory under /usr/local. It’s done! Too easy, right? Yes, but there are still some windup work to do:

(1) To run Go utilities (go, gofmt, etc) conveniently, you should add /usr/local/go into $PATH environment variable:

  1. # cat /etc/profile
  2. ......
  3. PATH=$PATH:/usr/local/go/bin
  4. export PATH
  5. ......

(2) It is strongly recommended to install Go in /usr/local/go under *nix and c:\Go under Windows since these default directories have already been embedded in Go binary distributions. If you choose another directory, you must set $GOROOT environment variable:

  1. # cat /etc/profile
  2. ......
  3. GOROOT=/path/to/go
  4. export GOROOT

So the $GOROOT is only need when you install Go on a custom directory, not default.

References:
Getting Started;
You don’t need to set GOROOT, really.