• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Install GO on CentOS 8 Linux

Written by Admin, Updated On December 23, 2019
centos, go
How to Install GO on CentOS 8 Linux

Go is a modern open source programming language developed by Google. Go, often referred to as golang. Popular applications such as, Grafana, Kubernetes, Terraform, Docker, etc. are written in Go language. In this tutorial explains how to install Go on CentOS 8 Linux.

Download and Install Go on CentOS#

Perform the steps given below to install Go on CentOS 8:

Downloading Go tarball#

Currently, latest stable version of Go is version 1.13.5 at the time of writing this article. You can check latest version of Go Download page.

You can download Go tarball using wget or curl:

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

Now, you should verify the tarball using below command:

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

It should display output as below:

Output
27d356e2a0b30d9983b60a788cf225da5f914066b37a6b4f69d457ba55a626ff go1.13.5.linux-amd64.tar.gz

Make sure the output should exact match with the hash value provided at the Go download page.

After that, extract the downloaded tarball using following command inside /usr/local directory. Ensure that you should run below command as a root or user with sudo privileges:

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

Setting Go Path Variable#

Set path environment variable in order to find Go executable binaries by system. For that we need to open /.bash_profile using below command:

sudo nano ~/.bash_profile

Now add the below lines to it:

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

Save and close the file. After that run below command to reload running profile:

source ~/.bash_profile

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

Verifying the Go Installation#

You can verify the Go installation by Go version command:

go version

Output should look like this:

Output
go version go1.13.5 linux/amd64

Demo Program in Go#

To test GO is properly installed, we will create a simple Hello World program which will print “Hello World” message. Perform the below steps to build simple program.

At first, create a workspace directory for Go. You can get more details about go workspace directory visit this page:

mkdir $HOME/demo

Next, create a src directory inside it using below command:

mkdir -p $HOME/demo/src/hello

In this directory create a file named hello.go and add below content to it:

sudo nano ~/demo/src/hello/hello.go
package main

import "fmt"

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

Now go back /demo/src/hello to build the file and issue go build command:

cd ~/demo/src/hello
go build

The above command will build an executable file with name hello.

You can run the program using executable using following command:

./hello
Output
Hello, World

Conclusion#

You have successfully installed GO on CentOS 8 system, you can write Go code. If you have any queries feel free to comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Install Node.js and npm on Debian 10 Linux
Next Article   How to Uninstall Software Packages on Ubuntu

Related Posts

  • How to Install Go on Debian 11

    How to Install GO on Debian 11

    December 6, 2022
  • How to Install Go on Ubuntu 22.04

    How to Install Go on Ubuntu 22.04

    November 19, 2022
  • How to Install Php 8 on CentOS 8

    How to Install PHP 8 on CentOS 8

    January 27, 2021

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook