May 24, 2013, Friday, 143

Install Google's GO language in Ubuntu Linux

From ezUnix

Revision as of 00:29, 4 December 2009 by YazzY (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
                                    pdf_icon.png Download this article as a single PDF document 

Contents

Introduction

Go is a new programming language created by Google aiming to be fast, safe, concurrent, fun to code in and open source. Read the Go docs to learn more about the language: http://golang.org/doc/install.html


Install dependencies.

Install gcc package if you do not have build-essential.

# sudo apt-get install bison build-essential libc6-dev ed mercurial


Environment variables

Set environment variables:

# export GOROOT=$HOME/go
# export GOOS="linux"
# echo $(uname -m)| grep -q 86_64  && export GOARCH="amd64" || export GOARCH="386"

Check the variables

# env | grep '^GO'

The GOARCH variable should be either "amd64" or "386".

Just add the lines with export to your .bashrc to make them permanent.


Get the source files of Go

Download the source code for Go. It is saved to $HOME/go/.

# hg clone -r release https://go.googlecode.com/hg/ $GOROOT


Compile Go

Now you can compile it:

#cd $GOROOT/src
# ./all.bash

Notice: Compilation process may report some bugs.


Test Go

Create a $HOME/test/ folder and move there.

# mkdir $HOME/test
# cd $HOME/test
  1. Create a hello.go file using your favourite editor.
# vi hello.go

Add the following go'code to it

package main

import "fmt"

func main() {
   fmt.Printf("Hello all. Let's GO!\n")
}


Compile and link it. This is dependent on your system's architecture.

Read: http://golang.org/doc/install.html#tmp_71 (at the bottom)

If you have 32-bit Linux, use 8g and 8l to compile and link the code. For 64-bit use 6g and 6l.

# 6g hello.go 
# 6l hello.6 

And finally run it (./6.out or ./8.out)

# ./6.out 


And the result should be...

Hello all. Let's GO!


That's all folks!
YazzY



You are not allowed to post comments. Login or register first.


Suffrage said ...
18:40, 16 May 2010 (CEST)
http://golanguage.ru/install - здесь сможете найти русскую инструкцию по установке =)