How To Install Google’s Go Programming Language

July 24th, 2010 by Kevin | Posted under Go Programming.

Introduction

Go is a compiled, garbage-collected, concurrent programming language developed by Google.

According to the Go website,

  • Go is simple.
  • Go is fast as typical builds take a fraction of a second and resulting programs run nearly as quickly as C or C++ code.
  • Go is type safe and memory safe.
  • Go promotes writing systems and servers as sets of lightweight communicating processes, called goroutines.
  • Go feels like a dynamic language but has the speed and safety of a static language.
  • Go is open source.

Google feels that there is a need for another programming language because:

  • Computers are enormously quicker but software development is not faster.
  • Dependency management is a big part of software development today but the “header files” of languages in the C tradition are antithetical to clean dependency analysis—and fast compilation.
  • There is a growing rebellion against cumbersome type systems like those of Java and C++, pushing people towards dynamically typed languages such as Python and JavaScript.
  • Some fundamental concepts such as garbage collection and parallel computation are not well supported by popular systems languages.
  • The emergence of multicore computers has generated worry and confusion.

Installation

There are two Go compiler implementations, 6g and friends, generically called gc, and gccgo. The 6g (and 8g and 5g) compiler is named in the tradition of the Plan 9 C compilers, described in http://plan9.bell-labs.com/sys/doc/compiler.html6 is the architecture letter for amd64 (or x86-64, if you prefer), while g stands for Go. gccgo is a more traditional compiler using the gcc back end.

Go implementations are currently available for the Linux and Mac OS X platforms. For Windows installation, you can try Go under MS Windows.

This article focuses on installing the gc compiler for Ubuntu 10.04. However the steps should be similar for any Linux distribution.

Installing the gc compiler:

1) Set up the environment variables

Set these variables in your shell profile ($HOME/.bashrc)

export GOROOT=$HOME/go #The root of the Go tree
export GOARCH=amd64 #The name of the target operating system (386, amd64, arm)
export GOOS=linux #The name of the compilation architecture (darwin, freebsd, linux, nacl)
export GOBIN=$HOME/go/bin #The location where binaries will be installed
export PATH=$PATH:$GOBIN

2) Install the C tools

To build Go, you need to have GCC, the standard C libraries, the parser generator Bison, makeawk, and the text editor ed installed. On OS X, they can be installed as part of Xcode.

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

3) Fetch the repository

You need Mercurial installed to get the Go repository. On Ubuntu, you can install this as:

$ sudo apt-get install mercurial

Make sure the $GOROOT directory does not exist or is empty. Then check out the repository:

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

4) Install Go

To build the Go distribution, run

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

If all goes well, it will finish by printing

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

where N is a number that varies from release to release.

5) Test the installation

A sample program

package main

import "fmt"

func main()
{
   fmt.Printf("hello, worldn")
}

Compile it using

$ 6g hello.go

To link the file, use

$ 6l hello.6

and to run it

$ ./6.out

Now you should be able to compile and run programs written in the Go Programming language.

6) Keeping up with releases

New releases are announced on the Go Nuts mailing list. To update an existing tree to the latest release, you can run:

$ cd $GOROOT/src
$ hg pull
$ hg update release
$ ./all.bash

You can get more details about installing the Go gc compiler here.

Installing the gccgo compiler:

You can get more details about installing the Go gccgo compiler here.

 

Related Posts:

Tags:

Do you have any comments on How To Install Google’s Go Programming Language ?

Spam protection by WP Captcha-Free