How to Install Go in CentOS 7

How to install Go in CentOS 7

Go is an open source programming language developed by Google. It provides easy to build, simple, reliable, and efficient software. This article helps you with the installation of Go language.

Install Go Language

The initial procedure is to download the Go language binary archive file by using following link.

To find and download latest version available or 32 bit version go to official download page.

[root@linuxhelp1 ~]# wget https://storage.googleapis.com/golang/go1.7.4.linux-amd64.tar.gz
--2016-12-31 07:33:01--  https://storage.googleapis.com/golang/go1.7.4.linux-amd64.tar.gz
Resolving storage.googleapis.com (storage.googleapis.com)... 216.58.196.112, 2404:6800:4007:802::2010
Connecting to storage.googleapis.com (storage.googleapis.com)|216.58.196.112|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 84021919 (80M) [application/x-gzip]
Saving to: ‘ go1.7.4.linux-amd64.tar.gz’ 

100%[===========================================================> ] 84,021,919   800KB/s   in 1m 40s 

2016-12-31 07:34:41 (822 KB/s) - ‘ go1.7.4.linux-amd64.tar.gz’  saved [84021919/84021919]

Now extract the downloaded archive and install it to desired location on system.

Here /usr/local directory is used, but you can also use home directory (for shared hosting) or other location.

[root@linuxhelp1 ~]# tar -xvf go1.7.4.linux-amd64.tar.gz 
go/
go/AUTHORS
go/CONTRIBUTING.md
go/CONTRIBUTORS
go/LICENSE
go/PATENTS
go/README.md
go/VERSION
go/api/
go/api/README
go/api/except.txt
go/api/go1.1.txt
go/api/go1.2.txt
.
.
.
go/test/varinit.go
go/test/writebarrier.go
go/test/zerodivide.go

Once it is downloaded, move the directory to local as follows.

[root@linuxhelp1 ~]# mv go /usr/local/

Setup Go Environment
It is required to set up the Go language environment variables for your project.

Generally, 3 environment variables such as GOROOT, GOPATH and PATH are needed. GOROOT is the location where Go package is installed on your system.

[root@linuxhelp1 ~]# export GOROOT=/usr/local/go

Now create the GOROOT directory path with the help of following command.

[root@linuxhelp1 ~]# mkdir -p /root/Projects/Proj1

GOPATH is the location of your work directory. For example, the directory used in this tutorial is ~/Projects/Proj1 .

[root@linuxhelp1 ~]# export GOROOT=$HOME/Projects/Proj1

Now set the PATH variable to access go binary system wide

[root@linuxhelp1 ~]# export PATH=$GOPATH/bin:$GOROOT/bin:$PATH

All above environment will be set for your current session only. To make it permanent add above commands in ~/.bash_profile file

Verify Installation
You have installed and configured Go language on your system, but it is essential to verify the installation. You can use the the following command to check Go version .

[root@linuxhelp1 ~]# go version
go version go1.7.4 linux/amd64

You can also verify all configured environment variables using the following command.

[root@linuxhelp1 ~]# go env
GOARCH=" amd64" 
GOBIN=" " 
GOEXE=" " 
GOHOSTARCH=" amd64" 
GOHOSTOS=" linux" 
GOOS=" linux" 
GOPATH=" " 
GORACE=" " 
GOROOT=" /usr/local/go/bin" 
GOTOOLDIR=" /usr/local/go/bin/pkg/tool/linux_amd64" 
CC=" gcc" 
GOGCCFLAGS=" -fPIC -m64 -pthread -fmessage-length=0" 
CXX=" g++" 
CGO_ENABLED=" 1" 

Tag : CentOS
FAQ
Q
which command to verify all configured environment variables?
A
You can also verify all configured environment variables using the following command.
# go env
Q
How to check the version of GO in centos?
A
You can use the the following command to check Go version
# go version
Q
Provide the link for downloading the GO application in centos?
A
use the following link to download the GO package
https://storage.googleapis.com/golang/ => link used for updating it
Q
Why GOROOT is used in centos?
A
Go is an open source programming language developed by Google. It provides easy to build, simple, reliable, and efficient software. This article helps you with the installation of Go language.
Q
how to export particular path in centos?
A
use the following syntax to export particular path in centos # export PATH=$GOPATH/bin:$GOROOT/bin:$PATH