Thursday, August 14, 2014

[ Level 1 ] Go installation and "Hello World" sample.

A friend of mine told me, if you could choose the programming language, choose the fashion one. I tried to use Go becuase it's "Go fashion"(Chinglish, means, fashion enough). The following script is the way to install Go in CentOS, you could refer to it if you also used CentOS.
# install Go, gcc for Go
rpm -q golang >/dev/null 2>&1 || sudo yum -y install golang libgo gcc-go

# Hello World
[ -e ./HelloWorld.go ] || cat > ./HelloWorld.go <<EOF
package main
import "fmt"
func main() {
  fmt.Println("Hellow World!")

# run as interpreter script
go run ./HelloWorld.go

# compile script and run it.
gccgo -g -o ./HelloWorld.out ./HelloWorld.go && ./HelloWorld.out

Wish this helps.

Stanley Huang