Monday, August 19, 2013

Installing Go Lang 1.1 on centos 6.4 *64-bit

UPDATE: 28/Apr/2014 - Golang package is now available on Fedora EPEL Repository. You can just configure EPEL repo and do a "yum install golang".

I have added go-lang package to the current repository. So you can try installing it using the following steps.

1. Install centos 6.x

2. Download and setup Fedora EPEL Repository

sudo yum install http://ftp.riken.jp/Linux/fedora/epel/6/i386/epel-release-6-8.noarch.rpm

(Step-3 not needed, if you are seeing this on Apr/2014)

3. Setup hop5.in repository


cd /etc/yum.repos.d
sudo wget http://www.hop5.in/yum/el6/hop5.repo

4. Install go package

sudo yum install golang

5. Write a simple "hello world" program to get started with go

[nareshv@fallenangel tmp]$ cat hello.go
package main

import "fmt"

func main() {
    fmt.Println("Hello, World.")
}
[nareshv@fallenangel tmp]$ go run hello.go
Hello, World. 

6. Continue exploring go-lang, from here

(Note is not applicable if you are using golang from EPEL Repository)

Note: Please note that, go-lang is compiled without emacs support (to avoid pulling tons of packages) and with gcc-4.6.3.

9 comments:

  1. I'm trying to get go running on centos6.4 (64 bit) and installed the above packages but having issues running go. Any ideas on why 6g can't allocate memory?

    go run hello.go
    go build command-line-arguments: fork/exec /usr/lib64/golang/pkg/tool/linux_amd64/6g: cannot allocate memory

    Thanks!

    ReplyDelete
    Replies
    1. Brendan, have a look at http://code.google.com/p/go/issues/detail?id=1860#c6. Not sure how much memory pressure your system is under. You can try the option mentioned in the above comment.

      Delete
  2. How do I add this so the paths work?

    hello.go:3:8: cannot find package "fmt" in any of:
    /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/rvm/bin:/usr/local/go/bin/src/pkg/fmt (from $GOROOT)
    ($GOPATH not set)
    package runtime: cannot find package "runtime" in any of:
    /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/rvm/bin:/usr/local/go/bin/src/pkg/runtime (from $GOROOT)
    ($GOPATH not set)

    ReplyDelete
    Replies
    1. Hello,

      Installation via YUM shouldn't have gone through any such problems. Could you do rpm -qa golang\* ?

      Here is the environment that i have

      [root@node1 ~]# rpm -qa golang\*
      golang-1.1.2-4.el6.x86_64

      [root@node1 ~]# go env

      GOARCH="amd64"
      GOBIN=""
      GOCHAR="6"
      GOEXE=""
      GOHOSTARCH="amd64"
      GOHOSTOS="linux"
      GOOS="linux"
      GOPATH=""
      GORACE=""
      GOROOT="/usr/lib64/golang"
      GOTOOLDIR="/usr/lib64/golang/pkg/tool/linux_amd64"
      CC="gcc"
      GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
      CGO_ENABLED="1"

      In case you want to add /etc/profile.d/go.sh you can try adding some of the above env variables to it.

      Best.

      Delete
  3. Is there any way to install Go 1.2 on CentOS?

    ReplyDelete
    Replies
    1. on centos 5.x there is no pre-packaged version that exists

      download this sourcerpm http://kojipkgs.fedoraproject.org//packages/golang/1.2/1.el6/src/golang-1.2-1.el6.src.rpm and

      rpmbuild --rebuild golang-1.2-1.el6.src.rpm

      and see if it works.

      If not, the last option is to build it from source :(

      Delete
  4. "package main" line missed.

    [nareshv@fallenangel tmp]$ cat hello.go
    package main
    import "fmt"

    func main() {
    fmt.Println("Hello, World.")
    }

    func main() {
    fmt.Println("Hello, World.")
    }

    [nareshv@fallenangel tmp]$

    ReplyDelete
    Replies
    1. code works without that, but updated by blog anyway. Thanks !

      Delete
  5. No package golang available.
    Error: Nothing to do

    ReplyDelete