Install and Run Go Programs on Ubuntu

I am currently in the processing of learning how to program in Go. These days Go is becoming popular and most of the opensource software that we use are built in Go. I am using Ubuntu and hence in this article I would like to share how to install and run Go programs on Ubuntu. If you don’t know the history of Go, here is the introduction from Wikipedia.

Go is a programming language created at Google in 2009 by Robert Griesemer, Rob Pike, and Ken Thompson. Go is a statically typed compiled language in the tradition of C, with memory safety, garbage collection, structural typing, and CSP-style concurrent programming features added. The compiler, tools and source code are all free and open source.

– Wikipedia

Install Go on Ubuntu

Go Lang is available as part of the default Ubuntu repositories. I am using Ubuntu 18.04 version. I installed Go lang using Ubuntu snap tool.

$ sudo snap install go --classic

The above command installs latest version of Go Lang. For me the version installed is 1.12.5. You can get the Go Lang version using the following command:

$ go version
go version go1.12.5 linux/amd64

Run Go Programs on Ubuntu

Now it’s time to build a sample program in Go Lang and run it on Ubuntu. Below a very simple, “Hello Go” program. This program will print “Hello! Go” on the terminal.

package main

import "fmt"

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

To run the Go Lang program you can use the below command:

$ go run hellogo.go
Hello! Go

We can build a binary executable file for the above program using the below command:

$ go build hellogo.go
$ ./hellogo
$ Hello! Go

Why Should I Learn Go Lang?

I am good at Python, Java, JavaScript, C and C++. Still I want to learn Go Lang. The reason being, it is becoming popular day by day and most of the tools or software’s that I am working are built using Go Lang. For example, Grafana and UniK.

Conclusion

This is a simple introduction on how to install and run Go programs on Ubuntu OS. You will see more Go lang programming examples in the future articles. Thanks for reading.

Leave a Reply

Your email address will not be published. Required fields are marked *