Tuesday, November 29, 2022
Google search engine
HomeLinux TutorialsHow to Install Go Golang on CentOS 7 RHEL 7

How to Install Go Golang on CentOS 7 RHEL 7

Go, often referred to as golang is a modern open-source programming language created by Google in 2009. Many popular applications, including Kubernetes, Docker, Hugo, and Caddy are written in Go. It was referred to as a statically-typed programming language with the ease of use, versatility, and reliability.

Currently, Golang has become one of the most popular programming languages due to its efficiency, clean design, expressive, and concise design model. Some of the projects that make use of Golang are:

  • snappy – a package manager
  • Juju – a service orchestration tool by canonical
  • Docker – a set of tools for deploying containers
  • Dropbox moved the critical components to Go lang from python

The features of the Go programming language are:

  • It is Open-Source
  • It has a powerful Standard Library and Tool Set
  • Concurrency Support – it offers easy and trackable concurrency options.
  • Garbage Collection
  • Testing Capabilities
  • Cross-Platform Development Opportunities
  • Hiighly scalable

Prerequisites

Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges or better install as root

How to Install Go / Golang on CentOS 7 RHEL 7

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

Follow the steps below to install Go on CentOS 7:

Step 1 – Update System

First, ensure that your system is up-to-date and packages are to their latest versions. This is achieved using the command below.

sudo yum update -y

and Install the required packages.

sudo yum install wget

Step 2 – Install Go (Golang) on CentOS 7 / RHEL 7

In this guide, I will demonstrate two ways to install Go (Golang) on CentOS 7 / RHEL 7

  1. Using Golang installer.
  2. Manual installation

Install Go (Golang) on CentOS 7 / RHEL 7 using the Golang Installer.

This is yet another method to get Golang installed on your CentOS 7 / RHEL 7 system. It involves downloading the official Golang Installers for Linux systems as below.

wget https://storage.googleapis.com/golang/getgo/installer_linux

With the installer downloaded, make it executable.

chmod +x ./installer_linux

Now run the installer to install the latest Golang version.

./installer_linux 

The installation will proceed as below:

Welcome to the Go installer!
Downloading Go version go1.19 to /home/devninja/.go
This may take a bit of time...
Downloaded!
Setting up GOPATH
GOPATH has been set up!

One more thing! Run `source /home/devninja/.bash_profile` to persist the
new environment variables to your current session, or open a
new shell prompt.

You will then be required to source the ~/.bash_profile

source ~/.bash_profile

Finally, verify the installed version of Golang.

$ go version
go version go1.17.2 linux/amd64

Manual Install Go (Golang) on CentOS 7 / RHEL 7

This installation method requires one to download the latest available Golang package from the official Golang release page.
Alternatively, you can download the tarball using wget as below.

wget https://golang.org/dl/go1.17.2.linux-amd64.tar.gz

With the tarball downloaded, verify the checksum.

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

Sample Output:

f242a9db6a0ad1846de7b6d94d507915d14062660616a61ef7c808a76e4f1676  go1.17.2.linux-amd64.tar.gz

Verify that the output matches the one on the download page.

Next, extract the tarball.

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

Then proceed and adjust your PATH variable. This will tell your system where to find and execute the GO executable binaries. This can be done by adding the below line to $HOME/.profile for installation on the current user or /etc/profile for the system-wide installation.

##For Current user
$ vi $HOME/.profile 

##For system-wide/ global user
$ sudo vi /etc/profile 

In the file, add the below lines.

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

For the changes made to apply, you may be required to log out and log in back to your system or directly execute them from the profile with the command:

source $HOME/.profile
##OR##
source /etc/profile

Thats it! You have installed Golang on your CentOS 7 / RHEL 7 system.

Now, verify your installation by checking the installed Golang version.

$ go version
go version go1.17.2 linux/amd64

Troubleshooting

if you have test run the golang scripts and get error like this below

go: writing go.mod cache: mkdir /usr/local/go/pkg/mod: permission denied

please make sure your GOMODCACHE environtment is right point for current user, with command

go env GOMODCACHE
##OR##
go env|grep CACHE

output:

GOCACHE="/home/devninja/.cache/go-build"   # correct value
GOMODCACHE="/root/go/pkg/mod"              # wrong value

to fix this, put env on /etc/profile and fill like this below

export GOMODCACHE=$HOME/go/pkg/mod  ##For system-wide/ global user

then run

source $HOME/.profile
##OR##
source /etc/profile

and then test your golang scripts again. happy go!

YOU CAN SUPPORT DEVNINJA WITH A CUP OF COFFEE

As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online. to search or browse the published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or more ) as a token of appreciation.

Support Us

DevNinja
DevNinja
System & Network Administrator Ninja
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

7 − 6 =

- Advertisment -
Google search engine

Most Popular

Recent Comments