CentOS golang Installation Instructions – for CentOS 6.x

CentOS golang

CentOS golang Installation Instructions – for CentOS 6.x.
In the following tutorial I’ll show how to install and run “Hello, world!” script with golang on CentOS 6.x

CentOS golang Installation Instructions – for CentOS 6.x

Install EPEL

If you haven’t install EPEL repository yet, you’ll need it now. follow those instructions.
If you want newer versions of golang you might want to try the hop5.in repository but I haven’t tried.

Install golang

Simple as:

yum install golang

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

yum install hg

Hello, World!

create a file named ‘hello.go’ and fill it with:

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

run the script using:

go run hello.go
centos-golang

centos-golang

You can first build to a binary executible with:

<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;width:555px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="text codecolorer">go build hello.go</div></td></tr></tbody></table></div>

and then run with:

<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;width:555px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="text codecolorer">./hello</div></td></tr></tbody></table></div>

$GOPATH

The ‘Hello, World!’ 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 Google OAuth 2.0 library)

go get code.google.com/p/goauth2/oauth

What’s next

Web Applications using Go

  • Writing Web Applications tutorial.
  • Bones – A project template for Go webapps.
  • Gorilla web toolkit.
  • Revel – A high-productivity web framework for the Go language. Deploy Revel.
  • Martini – Classy web framework for Go.
  • sawsij – lightweight, open-source web framework for building high-performance, data-driven web applications.

Template Engines for Go

Web Applications in Production

That’s it!, Cheers!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.