Some very light cajoling led me to do some investigation into Google Go (often called golang for ease of internet search). This is a brief recounting of how I got up and running on Ubuntu (first 12.04 and then 13.10). Luckily, this has been made espcially easy for us with the introduction of a golang package in the Ubuntu package repositories. There are also official installation instructions if you don’t like mine.
Open up a terminal and let loose:
The download is pretty heavy, so this step may take some time. Eventually the installer for
golang-go will ask you if you want to “Report installation of public packages to Go Dashboard.” I’ve been choosing “No” to this question and have no complaints.
Now comes the fun part. Serious Go development relies on having a “workspace” setup involving a specific directory structure including
src/ directories. Google’s official set-up page contains more information about these workspaces.
I’m not a big fan of putting a visible directory in
$HOME, so I opted to make a hidden directory called
.go. After creating the directory, the environment variable
$GOPATH needs to be set and
$PATH needs to be adjusted.
1 2 3 4 5
Now I’m going to create a go project and add a link to it in the workspace I just created.
1 2 3
For some actual test code, I’ll add a file in my
hello-go/ directory called
hello.go with the following code:
1 2 3 4 5 6 7
Now I’m going to install the binary created from compiling this code into my
$GOPATH to verify that my workspace is set up correctly, then I’ll run it to behold the fruit of my efforts.
1 2 3
Installing is not necessary every time I want to test that my code compiles; running
go build in the source directory will create a local executable that can be executed for incremental testing.
If you’re interested in learning golang, I would recommend doing the go tour. It goes way beyond a trivial hello world program and gives you some insight into many coplex go concepts (I even posted my solutions as a gist, if you’re interested).