×


Install Go on CentOS 8 - Best Method ?

Also known as Golang , Go is an open-source language developed by Google Inc for creating robust, efficient, and reliable software applications. Popular tools built using Go include Terraform, Kubernetes, Docker, Istio, and InfluxDB.

Here at Ibmi Media, as part of our Server management Services, we regularly help our Customers to perform related Server Monitoring queries.

In this context, we shall look into how to install Go on an instance of CentOS 8.


How to Install Go on CentOS ?

Before performing this Installation procedure, ensure that your are using a sudo rights enabled user. 

Then, follow the steps given below.


1. Update the system

To begin, log in and update your CentOS 8 server as shown.

$ sudo dnf update

Then, Hit 'y' when prompted and press ENTER.


2. Download Go binary file

The next step is to download the Go binary package which comes in a tarball file. This is available on the Go downloads page. At the moment, the latest version of Go is Go version 1.16.5. This is likely to vary by the time you are viewing this guide.

To download the Go compressed file on the terminal, use the wget command as shown:

$ wget https://golang.org/dl/go1.16.5.linux-amd64.tar.gz 

To confirm the existence of the tarball file, use the ls command:

$ ls

Next, extract the tarball file to the /usr/local directory which is mostly used for installing software applications locally:

$ sudo tar -xvf go1.16.5.linux-amd64.tar.gz -C /usr/local

Again, use the ls command to verify the go directory in the /usr/local path.


3. Configure environment variables

We need to configure the $PATH variable to point the Linux system on the location of the Go executable binaries. These binaries are found under the /usr/local/go/bin path.

So, add the line below to the ~/.bashrc file:

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

Save the changes and exit the file.

Next, load the environment variable into the shell session by invoking the source command as shown:

$ source ~/.bashrc

Then verify if Go is installed by checking the version as shown:

$ go version


4. Test go installation

Before concluding this guide, we are going to test if Go was indeed correctly installed by creating a workspace and create a simple program.

Here, we'll create a workspace which is a directory called greetings and later navigate into it.

$ mkdir greetings && cd greetings

Next, create a go module as follows:

$ go mod init greetings

Next, we will create a simple Go file.

$ vim greetings.go

We will write a simple Go program that prints a simple message to stdout:

package main
import "fmt"
func main() {
fmt.Printf("Hello guys, Welcome to Go language\n")
}

Save and exit. 

Then run the Go program as shown.

$ go run greetings.go

You should get the output displayed below as indicated:

Hello guys, Welcome to Go language


[Need help in fixing Linux System Software Installation errors? We can help you. ]


Conclusion

This article covers how to install Go on CentOS 8. Go language was designed to resolve the common criticisms of other languages while maintaining their positive characteristics and most widely used for writing servers these days.


Run the below command to see the version of the Go language:

$ go version