Linux Tactic

Go for It! Installing Go on CentOS 7 Made Easy

Programming can be a daunting task, but with the right programming language and a clear guide, anyone can learn to code. Go, also known as Golang, is a popular open-source programming language developed by Google.

It is widely used in developing Kubernetes, Docker, Hugo, Caddy, and much more. In this article, we will guide you on how to install Go on your CentOS 7 system.

Prerequisites

Before installing Go, you should ensure that you have sudo privileges on your system. Sudo privileges enable you to perform administrative tasks on your system.

To check if you have sudo privileges, run the following command:

$ sudo -v

If you have sudo privileges, it will prompt you to enter your password. If not, you will need to contact your system administrator to grant you sudo privileges.

Installing Go

There are various ways to install Go on your system, but in this guide, we will install the stable version from a tarball provided by the official Go website. To download and install Go, follow the steps below:

Step 1: Download the Go tarball from the official website using the command below:

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

Step 2: Verify the tarball by checking its SHA256 checksum using the sha256sum command.

$ sha256sum go1.16.6.linux-amd64.tar.gz

Step 3: Extract the tarball using the tar command and move it to the /usr/local directory. $ sudo tar -C /usr/local -xzf go1.16.6.linux-amd64.tar.gz

Step 4: Adjust the PATH variable to include the Go binary in the environment.

This is done by adding the following line to the /etc/profile or .bash_profile file:

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

Step 5: Test the installation by creating a workspace and running a “Hello World” program. To do this, create a directory named “hello” in the src directory and add a file named main.go with the following content:

package main

import “fmt”

func main() {

fmt.Printf(“Hello Worldn”)

}

Then run the following commands in your terminal:

$ mkdir ~/go

$ mkdir ~/go/src

$ mkdir ~/go/src/hello

$ cd ~/go/src/hello

$ go build

$ ./hello

If everything runs smoothly, you will see “Hello World” printed on your terminal.

Conclusion

Installing Go on a CentOS 7 system may seem like an intimidating task at first, but it is relatively straightforward. With this guide, you should be able to download and install the stable version of Go from a tarball provided by the official Go website, verify the tarball, extract the tarball, adjust the PATH variable, and test the installation by creating a workspace and running a “Hello World” program.

With Go installed on your system, you can start developing your Go projects today. In this article, we showed you how to install Go on a CentOS 7 system.

Go is a popular open-source programming language used in developing various applications, including Kubernetes, Docker, Hugo, and Caddy. We highlighted the prerequisites, downloading and installing Go, verifying the tarball, extracting it, adjusting the PATH variable, and testing the installation.

With Go installed on your system, you can start developing Go projects today. Learning to code in Go is important for anyone interested in programming, and this guide should help you take the first step.

Popular Posts