Introduction

Go is a open source programming language created at Google in 2007. It is often referred as GoLang. The language borrows lot of concepts from Algol and C. It is compiled and statically typed with support for Garbage Collection, Memory Safety and Concurrent Programming.

In this Tutorial I will guide you through downloading and installing Go1.8, as well as building a simple Hello World application.

Prerequistes

To follow this tutorial, you will need:

  • Ubuntu 16.04 server, configured with a non-root user with sudo privileges

Step 1 - Updating Package List

    sudo apt update

Step 2 - Install wget

Next, Install wget, a non-interactive utility to download files from web

    sudo apt install wget

Step 3 - Download Go 1.8 package

Next, download the latest package of Go using the following command.

    sudo wget https://storage.googleapis.com/golang/go1.8.linux-amd64.tar.gz

Step 4 - untar and unzip the package

Next, untar and unzip the package downloaded using the following command. Also, delete the downloaded package as it is not required anymore.

    sudo tar -C /usr/local -xzf go1.8.linux-amd64.tar.gz

Step 5 - Add to Path

Final step in the installation process is to add the go binaries to Path. To do that, add the following ling to “.bashrc” file in your home folder.

    # This is in ~/.bashrc
    PATH=$PATH:/usr/local/go/bin

Source the bashrc again by executing the following command

    source ~/.bashrc

Step 6 - Test the installation

Now that Go is intalled and the paths are set, you can test to ensure that everything is working as expected. To check, execute the following command

    go version

The output should be similar to below ,

    go version go1.8 linux/amd64

Step 7 - Create a Hello world application

Lastly, copy the below code to “test.go” file in your home directory

    package main

    import "fmt"

    func main(){
        fmt.Println("Hello, World!")
    }

Compile and run the go program by executing the following command

    go run ~/test.go

The ouput should be as below,

    Hello, World!

Conclusion

The simple Hello World program established that you have working a Go development environment. You can read more about writing efficient Go code from the below links

References