Friday, November 13, 2009

How to install Go (GoLang) compiler on Ubuntu

Now i want to write tutorial how to install GoLang compiler on Ubuntu (no matter what: it can be jaunty jackalope, karmic koala or even hardy heron). So lets start!

So at first step you should go into terminal and write
export GOROOT=/home/your_name/hg

This will write into var $GOROOT your path where Go will be installed. But dont make this dir (/hg) - program will make it.

Then you should define other vars:
export GOOS=linux
export GOARCH=386

NOTE! In var $GOARCH you should write your processor architecture! For example: export GOARCH=amd64 or GOARCH=arm

The next step will be creation of /bin folder and addind 777 permission for it. So in your folder (/home/name) create "bin" directory and in the terminal write
chmod 777 /home/your-name/bin
export GOBIN=/home/your-name/bin
export PATH=$PATH:/home/your-name/bin

If you do all the right way - you will see

when you write
env|grep '^GO'
in the terminal.

Then you shoul fetch Go source files from repo. In this situation helps Mercurial.
sudo apt-get install mercurial
hg clone -r release $GOROOT

The second line will recive source code.

As you know, Go was written on C language, so you need to install C compiler (gcc) to compile Go. So in terminal write:
sudo apt-get install bison gcc libc6-dev ed

Then the last two steps. Just write in terminal
cd $GOROOT/src

and wait. If you all the same way as i describe - you will see something like that:
--- cd ../test
n known bugs; 0 unexpected bugs

In the next post i help you to write your first programm on Go!


  1. Thanks, it really helped me.

  2. Me too! May want to mention this (right after making changes to etc/bash.bashrc):
    Now add $GOBIN to your $PATH. Open .bashrc in your $HOME directory

    sudo vi $HOME/.bashrc

    and add the line

    export PATH=${PATH}:$GOBIN

    Reload the files for the changes to take effect (thanks peter vahlu):
    source /etc/profile
    source ~/.bashrc
    (this is from

  3. Since this is a first hit in Google, I'm going to add comment about packages.

    Debian has packages for golang in unstable (and some time later also in testing) available as:
    apt-get install golang # for release tag
    apt-get install golang-weekly # for weekly tag

    For Ubuntu I also do uploads to CZ.NIC Labs PPA whenever I upload package to Debian, the PPA address is: