How to Install Go on CentOS 8

Install Go on CentOS 8

In this article, we will have explained the necessary steps to install and configure Go on CentOS 8. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Go Lang (Golang) is an open-source programming language developed by a team of Google engineers in 2007. 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.

Install Go on CentOS

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

sudo dnf update

Step 2. Install Go on CentOS 8.

Download the Go binary using the wget command:


Once the archive is downloaded, verify the tarball checksum:

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

Now extract the downloaded tarball using following command inside /usr/local directory:

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

Step 3. Set Go Path.

Next, edit the $PATH environment variable so that the system knows where the Go executable binaries are located. You can do this either by appending the following line to the /etc/profile file (for a system-wide installation) or to the $HOME/.profile file:

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

Save the file, and apply the new PATH environment variable to the current shell session by typing:

source ~/.profile

To verify that everything is working, run go version and see if the version is returned:

$ go version
go version go1.13 linux/amd64

Check the Go environment variables we set in previous sections:

$ go env

Step 4. Build a Hello World Program in Go.

First, create a new directory to go workspace by using the following command:

mkdir $HOME/work

Now create src directory inside it typing below command:

mkdir -p $HOME/work/src/hello

Next, create hello.go file inside src/hello directory using below command:

sudo nano ~/work/src/hello/hello.go

Add the following content:

package main

import "fmt"

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

Now go to the:

cd ~/work/src/hello

And build the program using the following command:


The output should look like this:

Hello, World

Congratulation, you have learned how to install and configure Go on CentOS 8. If you have any question, please leave a comment below.