Thursday, August 15, 2013

Installing and Configuring Go


In preparation for a few beginner workshops, I created videos for people to follow to install and configure the Go development tools. Just adding them here.

On Mac OSX:


On Ubuntu Linux:


The steps that I've followed are pretty much this (with my username 'vj'):
  • Download the zip or .tar.gz file for your platform from https://code.google.com/p/go/downloads/list
  • Create a folder called golang wherever you prefer. I prefer to have it in my home folder like so: /home/vj/coding/golang since I want to keep all my programming language folders in a "coding" folder in my home dir.
  • Extract the .zip or .tar.gz file you downloaded earlier. It will contain a single "go" folder. Move this into your golang folder. So you will now have something similar to /home/vj/coding/golang/go
  • Append the path to the go command line tools (/home/vj/coding/golang/go/bin) to your $PATH. On Ubuntu in my bash shell, to ~/.bashrc I added the entry export PATH=$PATH:/home/vj/coding/golang/go/bin
  • I created one new folder in the golang folder called gopath". The Go tools will have use for this path later to download and install external packages.
  • Add two additional entries to your .bashrc, export GOROOT=/home/vj/coding/golang/go and export GOPATH=/home/vj/coding/golang/gopath
  • Source the .bashrc if required so that the environment variables are available in your current shell, or restart the shell.

With that you should now be ready to compile and run your go programs. Note that you don't need any special editors or IDEs to work with Go. All your regular text editors will work.
The process to be followed for Windows is pretty much the same. You can have your golang folder as c:/coding/golang and add your environment variables as you would normally do on windows: right click My Computer -> Click Properties -> Click Advanced System Settings -> Click Environment Variables. Add new GOROOT and GOPATH values, and append the required value to the Path variable.

4 comments:

  1. Kudos!!! for creating such a great education site.

    ReplyDelete
  2. I'm a new mac user. I added the GOROOT and GOPATH environment variables when I started learning Golang few days ago. But now when I echo $GOROOT and $GOPATH it's returning blank. Also tried these steps:

    touch .bash_profile
    open -a TextEdit.app .bash_profile
    export GOROOT=/home/my_coding_dir/coding/golang/go


    So can you explain more about these two points, in the sense that why am I seeing this behaviour?

    1) Add two additional entries to your .bashrc, export GOROOT=/home/my_coding_dir/coding/golang/go and export GOPATH=/home/my_coding_dir/coding/golang/gopath

    2) Source the .bashrc if required so that the environment variables are available in your current shell, or restart the shell.


    What am I doing wrong here?

    ReplyDelete
  3. By the way this did not help either:

    touch .bashrc
    open -a TextEdit.app .bashrc
    export GOROOT=/home/my_coding_dir/coding/golang/go

    ReplyDelete
  4. For ubuntu just use...

    sudo apt-get install golang

    ReplyDelete

If you think others also will find these tutorials useful, kindly "+1" it above and mention the link in your own blogs, responses, and entries on the net so that others also may reach here. Thank you.

Note: Only a member of this blog may post a comment.