Install Latest Go on CentOS 8 / RHEL 8

Published on January 3, 2020 56 sec read

In this article, we are going to install Go on CentOS / RHEL 8. At the time of writing the article, the Go is version 1.13.5. Check their official page to download the latest version.

Table of Contents

  1. Download Go
  2. Set Go Path
  3. Run Hello World Program

1. Download Go

Download the Go binary using wget:

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

Then verify the tarball checksum by typing:

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

The output should look like this:

cde4af177ef9f218f51f5e12041f43004f9fa1b0e45d3b647c252aba04901035 go1.13.5.linux-amd64.tar.gz

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

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

2. Set Go Path

Open /.bash_profile file:

sudo nano ~/.bash_profile

Add the following lines:

export GOPATH=$HOME/golang
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin

Save the file and reload PATH using this command:

source ~/.bash_profile

To verify go installation, run this command:

go version

You’ll see the output like this:

go version go1.13.5 linux/amd64

3. Run Hello World Program

Create the Go workspace:

mkdir $HOME/golang

Inside the workspace make directory src/hello:

mkdir -p $HOME/golang/src/hello

Create hello.go file inside hello folder:

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

Now paste the following code:

package main

import "fmt"

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

Build the program:

# navigate to hello folder
cd ~/golang/src/hello
# build
go build

Run the executable by typing:

./hello

The output should be:

Hello, World

Author

Hey, I'm Md Obydullah. I build open-source projects and write on Laravel, Linux server, modern JavaScript and more on web development. If you enjoy my content, please consider supporting what I do!

Follow Buy me a coffeeBuy me a coffee

Leave a Reply

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