Home » repository » How to Install Go on CentOS 6 Linux

How to Install Go on CentOS 6 Linux

Update on:
Aug 7, 2019

Go is a very new and most popular open-source programming language; Google creates it. There are many popular software/applications developed using the Go language, including Grafana, Docker, Kubernetes, and many more.

In this tutorial, we will go through the process of setting the Go language environment in your CentOS 6 Linux from download to install step-by-step.

Prerequisites

Before starting the installation process for Go language, make sure your system runs on CentOS 6 Linux, and has user access with sudo privileges to execute administrative commands.

Installing Go on CentOS 6 Linux

The Go language installation and configuration in CentOS Linux is very easy; you can download and install Go into CentOS Linux in the few steps.

Follow the below steps to install Go on CentOS 6:

Step 1 – Downloading the Go tarball package.

Currently, the latest version of Go Language is 1.15.2 available; before downloading the tarball package, you can visit the official downloading page of Go and check available new version available.

You can download the Go binary, using either curl or wget command:

$ wget https://dl.google.com/go/go1.15.2.linux-amd64.tar.gz

Step 2 – Verify the Go tarball package.

You can verify the tarball checksum using the sha256sum command, as shown below:

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

You will get the output similar like below:

output:
68a2297eb099d1a76097905a2ce334e3155004ec08cdea85f24527be3c48e856  go1.15.2.linux-amd64.tar.gz

You should make sure the printed hash from the above command matches one from the download package mention on the download page.

Step 3 – Extract Go package.

You can use the tar command to extract the tarball package to the /usr/local directory, as shown below:

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

Step 4 – Configure the Path Variable

The CentOS operating system needs to manage Path for all executable programs to find the program’s executable binaries.

To configure Go executable binaries, PATH needs to adjust the $PATH environment variable. You can do this by appending the below line in the /etc/profile file:

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

After adding the line, save the file and load the new PATH environment variable into the same shell session using the following command:

$ source ~/.profile

Step 5 – Verify the Go Installation

You can verify the Go programming language installation on the CentOS system by checking the version as shown below:

$ go version

You will get the output similar like below:

output:
go version go1.15.2 linux/amd64

Go Language basics

In Go Language’s basic uses, we will set up a workspace and create a simple program, “program1,” that will print the message “hello world.”

To create a Go program, we will follow these four steps:

Step 1 – Create a Go workspace.

By default, we creating workspace directory is in the user’s home directory $HOME/go. To create it, use the following command:

$ mkdir ~/go

Step 2 – Create a program directory under the workspace.

It would be best if you created a new directory src/program1 inside the workspace, as shown below:

mkdir -p ~/go/src/program1

In the newly-created directory (program1), create a file named hello.go with the following go program:

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

If you want to learn more about the Go workspace directory hierarchy, please check this link.

Step 3 – Build a Go program.

To build the go application for the program, navigate to the ~/go/src/hello directory, and make a file using the go build command, as shown below:

$ cd ~/go/src/hello
$ go build

The above command will build and an executable file named program1.

Step 4 – Run the new Go program.

You can execute the new build program by running the command, as shown below:

./hello

You will get the output similar like below:

output:
Hello, World

Conclusion

Now you learn to download and install Go language in CentOS 6 Linux and learn to build workspace, write and run Go programs.

If you get any problem or having any feedback, please comment below.

Related Posts

How to Install MongoDB on CentOS 8 Linux

How to Install MongoDB on CentOS 8 Linux

MongoDB is an open-source and free NoSQL document based database system. Nowadays, it is prevalent as most application developers are using MongoDB, which can handle big data. As a MongoDB is a NoSQL database, It stores data in JSON-like documents where fields can...

How to Install OpenCV on CentOS 8 Linux

How to Install OpenCV on CentOS 8 Linux

OpenCV (Open Source Computer Vision Library) is an open-source computer vision and machine learning software library. OpenCV was built to provide a common infrastructure for computer vision applications and to accelerate the use of machine perception in commercial...

How to install and use FFmpeg on CentOS 8 Linux Operating System

How to install and use FFmpeg on CentOS 8 Linux Operating System

The FFmpeg is the most potent and useful command-line tool on Linux system for multimedia files transcoding. You can use FFmpeg to convert multimedia files between various video and audio formats and resize videos. It has multiple audio and video libraries such as...

How to Install VirtualBox on CentOS 8 Linux

How to Install VirtualBox on CentOS 8 Linux

VirtualBox is an Open Source tool, known as a cross-platform virtualization application or software. It used to run multiple operating systems or virtual machines simultaneously on a single hardware. In this VirtualBox installation tutorial, we will explain the...

Follow Us

Our Communities

More on CentOS

The Ultimate Managed Hosting Platform
Load WordPress Sites in as fast as 37ms!

0 Comments

0 Comments

Submit a Comment

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

three × one =

Shares