Ready! Steady! Go!

Today I found a new pro­gram­ming lan­guage Go from Google. In closest future I’ll try to do some thing using it, but today I just want to install it. Of course language’s homepage has instruc­tions of install­a­tion pro­cess, but by some reason it was not suited on my Debian GNU/Linux “squeeze”. So here we go…

First of all, you’ll need to add envir­on­ment vari­ables. You can learn about these vari­ables from ori­ginal install­a­tion manual:

$GOROOT
The root of the Go tree. Typ­ic­ally this is $HOME/go but it can be any dir­ect­ory.
$GOOS and $GOARCH
The name of the tar­get oper­at­ing sys­tem and com­pil­a­tion archi­tec­ture. Choices for $GOOS are linux, dar­win (Mac OS X 10.5 or 10.6), and nacl (Nat­ive Cli­ent, an incom­plete port). Choices for $GOARCH are amd64 (64-bit x86, the most mature port), 386 (32-bit x86), and arm (32-bit ARM, an incom­plete port). The valid com­bin­a­tions are linux/amd64, linux/arm, linux/386, darwin/amd64, darwin/386, and nacl/386.

Here are vari­ables that I declared on my laptop. I store sources of Go under my $HOME/wc/go dir­ect­ory. So here’s my vari­ables (as they defined in my $HOME/.profile file):

export GOROOT="$HOME/wc/go"
export GOOS="linux"
export GOARCH="386"

Also I have $HOME/bin dir­ect­ory, which is in my $PATH variable:

$ ls -l $HOME | grep bin
drwxr-xr-x  2 ixti ixti    4096 Nov  1 13:01 bin
$ echo $PATH
/home/ixti/bin:/usr/local/bin:/usr/bin:/bin:/usr/games

To down­load sources of Go you’ll need Mer­cur­ial cli­ent. So if you don’t have it installed yet, install it:

$ sudo apt-get install mercurial

To com­pile it’s sources we’ll need some pack­ages (as described on ori­ginal instruc­tions page), so let’s install them too:

$ sudo apt-get install bison gcc libc6-dev ed

OK. Now we need to down­load sources:

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

Now we have sources of Go. Let’s com­pile them:

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

While com­pil­ing you’ll need an Inter­net con­nec­tion. My ISP is not the best so some­times new con­nec­tions are simply dropped. So I’ve met this error:

...
gopack grc _test/net.a _gotest_.8
make[2]: Leaving directory `/home/ixti/wc/go/src/pkg/net'
--- FAIL: net.TestDialGoogle
	-- 74.125.19.99:80 --
	-- www.google.com:80 --
	-- 74.125.19.99:http --
	-- www.google.com:http --
	-- 074.125.019.099:0080 --
	-- [::ffff:74.125.19.99]:80 --
	Dial("tcp", "", "[::ffff:74.125.19.99]:80") = _, dial tcp 74.125.19.99:80: connection timed out
	-- [::ffff:4a7d:1363]:80 --
	Dial("tcp6", "", "[::ffff:4a7d:1363]:80") = _, dial tcp6 74.125.19.99:80: connection timed out
	-- [0:0:0:0:0000:ffff:74.125.19.99]:80 --
	-- [0:0:0:0:000000:ffff:74.125.19.99]:80 --
	-- [0:0:0:0:0:ffff::74.125.19.99]:80 --
FAIL
make[1]: *** [test] Error 1
make[1]: Leaving directory `/home/ixti/wc/go/src/pkg/net'
make: *** [net.test] Error 2

If your Inter­net con­nec­tion was down, or you have same ISP as I do, don’t scare, simply con­nect (recon­nect) to the Inter­net and all.bash again:

$ ./all.bash

When com­pil­a­tion will fin­ish (it took about 15 minutes on my laptop), you’ll see some­thing like this in the end:

--- cd ../test
0 known bugs; 0 unexpected bugs

Accord­ing to ori­ginal manual num­bers can dif­fer from ver­sion to version.

Now let’s see what we’ve just got. First of all, it cre­ated its bin­ar­ies under my $HOME/bin. So let’s test it with trivial “Hello World”-like example. I’ve cre­ated lets.go with fol­low­ing lines:

// lets.go
package main
import "fmt"
func main()
{
    fmt.Printf("Let's Go!\n");
}

This tutorial is not about how to pro­gram in Go, so you can refer to offi­cial site for details on sim­ilar example but with line by line descrip­tion of code.

So pro­gram above should out­put “Let’s Go!”. Let’s com­pile it:

$ 8g lets.go
$ 8l lets.8

First com­mand 8g lets.go pro­duced com­piled lets.8. Then we linked it with 8l lets.8 which pro­duced 8.out. Let’s run it:

$ ./8.out
Let's Go!

Viola!

  • del.icio.us
  • Google Bookmarks
  • Identi.ca
  • Twitter
  • Technorati
  • Digg
  • Slashdot
  • Facebook
  • MisterWong
  • Reddit
  • StumbleUpon
  • Mixx
  • HelloTxt
  • LinkedIn
  • PDF
  • email
  • Print
This entry was posted in Development and tagged , . Bookmark the permalink.

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>