First of all you need to set some Environment variables
$ export GOROOT=$HOME/go
$ export GOARCH=amd64 (replace amd64 with your system architecture eg: arm, 386)
$ export GOOS=linux
$ export GOBIN=$HOME/go/bin
$ export PATH=$PATH:$GOBINAdd the PATH variable to the .bashrc file only if you are planning to use go
regularly.Double-check them by listing your environment.$ env | grep '^GO'
Install Pre-requisites
$ sudo apt-get install bison gcc libc6-dev ed make
$sudo apt-get install python-setuptools python-dev
$ sudo apt-get install mercurial
Fetch the repository
$ hg clone -r release https://go.googlecode.com/hg/ $GOROOTInstall Go
$ cd $GOROOT/src
$ ./all.bash
Now wait for some time. The compilations will proceed and will be
completed with the following message
--- cd ../test
N known bugs; 0 unexpected bugs
Test Go
Create the following program in your favourite editor and save it as hello.go
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}
compile it using
$ 6g hello.go
6g
is the Go compiler foramd64
; it will write the output inhello.6
. The ‘6
’ identifies files for theamd64
architecture. The identifier letters for386
andarm
are ‘8
’ and ‘5
’. That is, if you were compiling for386
, you would use8g
and the output would be namedhello.8
.To link the file, use
$ 6l hello.6
6l
is the Go linker foramd64
; it will write the output in6.out
. The ‘6
’ identifies files for theamd64
architecture. The identifier letters for386
andarm
are ‘8
’ and ‘5
’. That is, if you were linking for386
, you would use8l
and the output would be named8.out
.to run it
$ ./6.out ( or ./8.out )To build more complicated programs, you will probably want to use a
Makefile
. There are examples in places like$GOROOT/src/cmd/godoc/Makefile
and$GOROOT/src/pkg/*/Makefile
.