The Go programming language has been getting popular for certain types of server-side programming. Installing the compiler and its tools and using them is not as straightforward as you might assume. Here are the steps I use:
Go to the Go language website and download the package.
Unzip the downloaded file and move it to
$ tar xvf go-package-you-downloaded.tar.gz $ sudo mv go /usr/local
/usr/local/go/bin to the
PATH variable of your shell.
Your Go source code and compiled binaries will reside inside a specific directory. Create it and set an environment variable named
GOPATH to it:
Your source code has to be put under
GOPATH in this directory hierarchy:
$GOPATH/src/github.com/someuser/someproject. For example, add the
hello.go from this page to
$GOPATH/src/github.com/joe/hello/main.go. You will need to create that directory hierarchy. If you are getting some Go code from Github, remember to clone it within that
The above source code can be compiled from anywhere using this command:
$ go install github.com/joe/hello
Note how the Go compiler will always look under the
$GOPATH/src for the above compilation.
After compilation, the binary will be placed at
$GOPATH/bin. This directory also needs to be added to the
PATH variable. Remember to do this cause when you start using Go code that calls other Go libraries, this is essential for that to work.
To run the program you compiled:
Tried with: Go 1.7 and Ubuntu 16.04