Create Go workspace

Once the Go build environment is ready, the next step is to create workspace for development:

(1) Set up a new empty directory - This is where your projects can reside:

mkdir $HOME/gowork

(2) Use a new environment variable $GOPATH to point it:

  # cat /etc/profile
  ......
  GOPATH=$HOME/gowork
  export GOPATH
  ......

If you are using bash or zsh, put the following in the respective file:

export GOPATH=$HOME/gowork

The workspace should contain 3 subdirectories:

src: contains the Go source code. pkg: contains the package objects. You could think them as libraries which are used in linkage stage to generate the final executable files. bin: contains the executable files.

Reference: How to Write Go Code. https://github.com/NanXiao/golang-101-hacks https://github.com/RHCloudServices/golang-intro


See also