How to Install Go on Linux Mint 19

How to Install Go on Linux Mint 19
How to Install Go on Linux Mint 19

Installing Go on Linux Mint 19

Go is a Google Developed modern open-source programming language. Go also known as Golang and offers a robust set of libraries. Popular applications like Docker, Graphana, etc. are written in Golang. In this tutorial, you are going to learn how to install Go on Linux Mint 19 and to build a simple real-world application.

Prerequisites

Before you start to install Go on Linux Mint 19. You must have the root user account credentials of your system.

Download and Extract Go on Linux Mint

The current latest version of Golang available on the official website is 1.11.5 at the time of writing this tutorial. You can get the current latest version URL by visiting their download page.

First, go to the home directory and download Go tarball by using curl command:

cd ~ && curl -O https://dl.google.com/go/go1.11.5.linux-amd64.tar.gz

Now verify the downloaded tarball by using the following command:

sha256sum go1.11.5.linux-amd64.tar.gz

The output should look like this:

cde4af177ef9f218f51f5e12041f43004f9fa1b0e45d3b647c252aba04901035  go1.11.5.linux-amd64.tar.gz

The hash value printed in the above output should match with the hash value provided on the download page.

Now extract the downloaded tarball using following command inside /usr/local directory.

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

Set Go Path

Now you should set PATH in order to find Go executable binaries by the system.

Open /.profile file using below command:

sudo nano ~/.profile

And paste the following lines inside it:

export GOPATH=$HOME/work
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin

Now save and exit the file then reload the profile running below command:

source ~/.profile

Verify Go Installation

To confirm and verify the go installation type following command:

go version

the output should be:

go version go1.11.5 linux/amd64

Build a Hello world Program in Go

Here we will build a simple Hello World program in Golang. Use the following steps to build the program.

Create a new directory for go workspace by using the following command, to learn more about go workspace directory visit this page:

mkdir $HOME/work

Now create src directory inside it typing below command:

mkdir -p $HOME/work/src/hello

Now create hello.go file inside src/hello directory using below command:

sudo nano ~/work/src/hello/hello.go

With the following content:

package main

import "fmt"

func main() {
    fmt.Printf("Hello, World\n")
}

Now go to the

/work/src/hello

directory:

cd ~/work/src/hello

And build the program using typing:

go build

You can run the program using the following command:

./hello

The output should be:

Hello, World

Conclusion

You have successfully learned how to install Go on Linux Mint 19. If you have any queries please don’t forget to comment below.

LEAVE A REPLY

Please enter your comment!
Please enter your name here