Go: how to install on Centos 6.5

Go is a quite new programming language. It was developed  in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson. Although it’s not as mature as C, Python or Java, it has already gained significant popularity in developers community. For instance, Docker is written in Go. It’s also in active use in Dropbox, Canonical and definitely in Google. CoreOS uses Go as well. If you would like to give it a shoot, first thing you need to do is to install it.  The easiest way to install is to use standard package manager, as apt-get for Ubuntu / Debian or yum (Fedora).  But if you need it on Centos, it’s not that easy.  Although Go developers provide binary packages, we’d like to install RPM package. It make everything much easier later when you need to update it or uninstall. You can write your own spec file, but it’s much easier to user the SPEC file  prepared by Jehiah Czebotar. The only thing we need is to modify current version. At the time of writing it’s go1.3.3.linux-amd64.tar.gz. We assume you have your environment prepared for RPM building.

Go to your SPEC directory and download the SPEC file.

wget https://gist.githubusercontent.com/jehiah/3867005/raw/f5190c21a40ffedcbbcd020405c0f50e57287e0e/go.spec

Modify the version to match the current one:

Source0: go1.3.3.linux-amd64.tar.gz

cd to your ~/SOURCES and download the sources codes:

wget https://storage.googleapis.com/golang/go1.3.3.linux-amd64.tar.gz

We are ready to build Go:

rpmbuild -bb ~/rpmbuild/SPECS/go.spec

Let’s check if everything is ok:

[root@dev ~]# rpm -ivh --test rpmbuild/RPMS/x86_64/go-devel-go1.3.3-1.x86_64.rpm
Preparing...                ########################################### [100%]
[root@dev ~]#

If it is install Go rpm:

rpm -ivh rpmbuild/RPMS/x86_64/go-devel-go1.3.3-1.x86_64.rpm

Update your bash env variable to make sure it knows where go is:

[root@dev ~]# bash
[root@dev ~]# which go
//usr/local/go/bin/go
[root@dev ~]#
[root@dev ~]# go version
go version go1.3.3 linux/amd64
[root@dev ~]#

So far so good. Create an example:

[root@dev ~]# cat hi.go
package main
import "fmt"
func main() {
    fmt.Println("hello world")
}
[root@dev ~]#

To build and launch run:

[root@dev ~]# go run hi.go
hello world
[root@dev ~]#

Now we can dive in Go world. Good start point can be found at gobyexample.com.

Leave a Reply

Your email address will not be published.