How to install and Setup GO on CentOS 6.X

How to install and Setup GO

Here will see golang installation on CentOS and setting up go environment details..


Install EPEL

You can install EPEL package using yum also;

# yum install epel-release

Install golang

Just run following command to install golang using yum,

# yum install golang

you may want to install hg too; you’ll probably will need it later for the ‘go get’ command:

# yum install hg

Say, Hello!!

create a file named ‘hello.go’ using vim/vi/nano editor: below is sample hello go code.

package main
import "fmt"
func main() {
     fmt.Println("Say, Hello!!")

To run the script use “go run”

# go run hello.go


The ‘Say, Hello!!’ is a very basic example, but in real-world you may need to install packages and libraries for more complex applications.

The $GOPATH environment variable specifies the location of your workspace. It is likely the only environment variable you’ll need to set when developing Go code.

If your project for example is located at $HOME/go, you should create a variable like:

# export GOPATH=$HOME/go

For convenience, add the workspace’s bin subdirectory to your path:

# export PATH=$PATH:$GOPATH/bin

Now, your project environment variables are set and you can download packages with the simple command: (for example – the mysql)

# go get