Colloquially referred to 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. Let’s explore how you can install Go on an instance of CentOS 8.
Just before you embark on the procedure of installing Go, ensure that you have the following in check.
An instance of CentOS 8.
A sudo user configured on your instance.
A stable internet connection.
That said, let us get along with the installation of Go language.
Step 1: Update the system
Right off the bat, log in and update your CentOS 8 server as shown.
$ sudo dnf update
Hit ‘y’ when prompted and press ENTER.
Step 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.
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.
Step 4: 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.
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
Step 5: 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 as shown.
Save and exit. Then run the Go program as shown.
$ go run greetings.go
You should get the output displayed as indicated.
In this guide, we have demonstrated how to install Go on CentOS 8. It’s our hope that you had an easy time doing the same on your CentOS 8 system.