Installing the Go Programming Language in Ubuntu

Google just released the Go programming language a few days ago (on November 10th 2009).  Go is described as a programming language which "combines the development speed of working in a dynamic language like Python with the performance and safety of a compiled language like C or C++"1.

Intriguing isn't it?

Let's Go and let install it on Ubuntu! :)

At this time there is no Ubuntu package available for the Go language so there is some Linux console work to do.  So, first, open a console: Menu Applications | Accessories | Terminal.

Setting Go environment variables

  • Edit your .bashrc file:
gedit ~/.bashrc
  • Add the following lines at the end of the file:

export GOROOT=$HOME/go
export GOARCH=amd64 #For 32bits architecture, replace 'amd64' by '386'
export GOOS=linux
export GOBIN=$GOROOT/bin

export PATH=$PATH:$GOBIN 

Choices for GOARCH are amd64 (64-bit x86, the most mature port), 386 (32-bit x86)

  • Update your terminal environment variables by reloading .bashrc:
source ~/.bashrc

 

Get GO source code (using Mercurial)

Next step is to fetch a copy of Go source code from Google Repository.

  • If you don't have Mercurial already installed, issue following command in the terminal:
sudo apt-get install python-setuptools python-dev mercurial
  •  Check out the Go repository
hg clone -r release https://go.googlecode.com/hg/ $GOROOT
  • Create Go bin directory
mkdir $GOROOT/bin

Installing Go

  • Go toolchain is written in C, so you need to install the following software to be able to compile it:
sudo apt-get install bison gcc libc6-dev ed make
  • Build Go distribution
cd $GOROOT/src && ./all.bash
  • If everything went well, you should see the following line (or similar) when the compilation is done:
--- cd ../test
0 known bugs; 0 unexpected bugs

 

Hello World!

Now you are ready to learn and experiment with Go.  I invite you to try out the Go Tutorials at the Go Programming Language website.

Happy hacking!


 

[1] Go official announcement on Google Blog: http://google-opensource.blogspot.com/2009/11/hey-ho-lets-go.html