How to install Go languange Golang on Centos 7

How to Install Go Language or Golang on Centos 7

Go language or often called as Golang is an open-source programming language which was designed and created by Google. Go was designed at Google in 2007 to improve programming productivity in an era of multicore, networked machines and large codebases. Go was publicly announced in November 2009, and version 1.0 was released in March 2012. At this article, we will study how to install Golang on Centos 7, the tutorial will be as detailed as possible. The latest stable version of Go is version 1.13.5 and we will use this version as our binnary file source.

The Go Installation article will divided with subtopics as below :

  1. Prerequisites
  2. Download Gol binnary file tarball
  3. Go Installation
  4. Go language testing

1. Prerequisite

When we are going to install or add new software to our CentOS, we are advised to do the space availability checking to ensure the sufficient storage for new software and having a user with sudo privilege. We also have to do system update which is useful for updating a repository or software dependency to the latest version, the command will be used for this purpose is :

 [ramans@localhost ramans] sudo yum update

2. Getting Go Binary tarball File

When this article is being written, the latest stable version of Go is version 1.13.5. Before downloading the tarball, visit the official Go downloads page and check if there is a new version available. The URL is located on https://golang.org/dl/.

How to install Golang on Centos 7 | donwload page location

2.1 Download Go tarball File

Download the Go binnary with wget or curl command line from our CentOS environment. At this time, I use the wget command line. The tarball file size is about 115MB for Linux OS.

[ramans@localhost ramans] wget https://dl.google.com/go/go1.13.5.linux-amd64.tar.gz
Go binary file is being downloaded

2.2 Verify Golang tarball File

Once the download was successful, then we verify the checksum of tarball file to ensure its validity with the sha256sum command by submitting command :

[ramans@localhost ~]$ sha256sum go1.13.5.linux-amd64.tar.gz
 512103d7ad296467814a6e3f635631bd35574cab3369a97a323c9a585ccaa569  go1.13.5.linux-amd64.tar.gz
The checksum code was valid

Go binnary file checksum result was the same with the number stated ont the official website.

3. Go Languange Installation

3.1 Extract tarball File

We will continue the installation of GO language by extracting tarball file to the /usr/local/ directory. We need the sudo privilige on executing this task.

 [ramans@localhost ~]$ sudo tar -C /usr/local -xzf go1.13.5.linux-amd64.tar.gz

It will add new directory /usr/local/go and Golang binary files will be exist inside it.

3.2 Adjust the Path Variable

Go executable binaries path is needed when we will build or execute Go files, to do so we need to add the Go binaries location to the user profile file. For this purpose we need to modify /etc/profile file append new line for Golang binaries location.

[ramans@localhost local]$  vi ~/.bash_profile 
add the following line :
export PATH=$PATH:/usr/local/go/bin 

Than to enable this changed, we submit command :

 [ramans@localhost local]$  source ~/.bash_profile 

Golang Installation Test

4.1 Create Workspace Directory

The next step is testing, to know whether Go is installed correctly or not, we will create a workspace and build a simple “Hello world” program. By default, the workspace directory is set to $HOME/go. The task will be done, by submitting command below to create new directory to be used for workspace directory.

[ramans@localhost go]$ mkdir /home/ramans/go/src/hello/

4.2 Testing GO functionalities

Direct to the /home/ramans/go/src/hello/ directory and create a new file on it. At this case, we will make the simple application which is showing “Hello Word’ via command line. The steps will be as follow :

  1. create hello.go file
  2. build hello.go file
  3. execute hello.go
[ramans@localhost hello]$ vi hello.go 

hello.go file will be containing Golang script, as below :

[ramans@localhost hello]$ go build
[ramans@localhost hello]$ ./hello
 Hello, World. This is my first Go application

Conclusion

So far, the Golang installation process was completed, where the application could be used to build and run the GO language script at the end. Have a nice holiday.. !

Share this article via :

Leave a Reply

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