Setup Go

Download the setup file from the official page. Then run the following command:

sudo tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz

It will unpack and extract the file and create a new folder go under /usr/local directory.

Add Go binary to your path

To work with Go, you need to add path to the environment variable. Run the following command:

export PATH=$PATH:/usr/local/go/bin

Testing a File

Create a directory called GoPlayground and change your directory to the newly created directory

mkdir GoPlayground
cd GoPlayground

Under the directory create a file demo.go and paste the following code:

package main

import "fmt"

func main() {
	fmt.Printf("hello, world\n")
}

Then build it with the go tool:

go build demo.go

The command above will build an executable named demo in the current directory alongside your source code. Execute it to see the greeting:

./demo

It will produce the following output:

hello, world