Linux Tutorials

How to Install Go Lang on CentOS 8

Go, often referred to as golang is a modern open-source programming language created by Google that allows you to build reliable and efficient applications.

Many popular applications, such as Kubernetes, Docker, Prometheus, and Terraform, are written in Go.

This tutorial explains how to download and install Go on a CentOS 8 system.

Download and install Go on CentOS 8

At the time of writing this article, the latest stable version of Go is version 1.13.4. Before downloading the tarball, visit the official Go downloads page and check if there is a new version available.

Perform the following steps below to download and install Go on CentOS 8:

Step 1:

Download the Go binary using either the wget or curl utility:

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

Step 2:

Once the archive is downloaded, verify the tarball checksum by typing:

sha256sum go1.13.4.linux-amd64.tar.gz

Make sure the hash printed from the sha256sum command matches the one from the downloads page.

Output

692d17071736f74be04a72a06dab9cac1cd759377bd85316e52b2227604c004c  go1.13.4.linux-amd64.tar.gz

Step 3:

Extract the tarball to the /usr/local directory using the tar command:

sudo tar -C /usr/local -xf go1.13.4.linux-amd64.tar.gz

The command above must be run as root or a user with sudo privileges.

Step 4:

Tell the system where to find the Go executable binaries by adjusting the $PATH environment variable.

You can do this by adding the following line to the /etc/profile file (for a system-wide installation) or to the $HOME/.bash_profile file (for a current user installation):

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

Save the file, and load the new PATH environment variable into the current shell session using the source command:

source ~/.bash_profile

That’s it. At this point, Go has been installed on your CentOS system.

Test the Installation

To test whether Go is installed correctly, we will set up a workspace and build a simple “Hello world” program.

Step 1:

The location of the workspace directory is specified with the GOPATH environment variable. By default, it is set to $HOME/go. To create the directory run the following command:

mkdir ~/go

Step 2:

Inside the workspace create a new directory src/hello:

mkdir -p ~/go/src/hello

In that directory create a file named hello.go:

nano ~/go/src/hello/hello.go

Paste the following code to the file:

package main

import "fmt"

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

Step 3:

Navigate to the ~/go/src/hello directory and run go build to build the code:

cd ~/go/src/hello
go build

The command above will build an executable named hello.

Step 4:

Run the executable by typing:

./hello

If you see the following output, then you have successfully installed Go.

Output

Hello, World

Conclusion

Now that you have downloaded and installed Go, you can start writing your Go code.

Arslan ud Din Shafiq

Alibaba Cloud MVP, Alibaba Cloud Technical Author, Dzone MVB, Software Engineer, Software Developer, Software Designer, Web Engineer, Web Developer, Web Designer, Database Designer, Database Developer, Cloud Computing Specialist, Linux Expert, Servers, 3D Modeling, Blogger, Facebook Map Editor, Google Map Editor

Recent Posts

I have 20 years of experience in computer security advancement. What I can recommend to regular PC users

If you are living in a digital world you must know how to protect your…

4 years ago

Software Development Life Cycle Model (SDLC)

Software Development Life Cycle Model, also known as SDLC or Software Development Process, is base…

4 years ago

SE Ranking in [2020]. What is SEO in marketing?

Torque published an article on October 18, 2016, about WordPress statistics. According to this article,…

4 years ago

PostgreSQL Version via Command Line & SQL Shell

PostgreSQL, often known simply as Postgres, is an open-source general-purpose object-relational database management system. In…

4 years ago

Google SEO: 15 Best ways about how can I do SEO for Free?

SEO is free as well as paid. To achieve SE ranking, money is not enough.…

5 years ago

How to install and configure PyroCMS on Ubuntu server

PyroCMS is a Laravel PHP Framework based web application. It is available to use free…

5 years ago