Archive for September, 2012

In this post I’ll be going over how to install Sublime Text under Ubuntu and add in the plugins for GoSublime and GoToDoc which add in enhancements to Sublime for the Go programming language. First you’ll want to download Sublime itself:

Once that’s done, open up a command line and unpack and install the files. In the below I’ll be assuming Sublime was downloaded into Downloads and I’ll be installing it under /opt/

cd Downloads
tar xvfj Sublime\ Text\ 2.0.1.tar.bz2
sudo mv "Sublime Text 2" /opt/Sublime_Text_2

Next add /opt/Sublime_Text_2 to your PATH in ~/.bashrc

echo "export PATH=\$PATH:/opt/Sublime_Text_2" >> ~/.bashrc

source ~/.bashrc

You’ll now be able to start up the software simply by running the command: sublime_text

The base Sublime install doesn’t include good support for Go. For that you’ll need a couple of external packages. To make these packages easier to install you’ll want to install something called Package Control. Package Control allows you to easily install packages from within Sublime.

Open up Sublime and press the Control key plus the ` key. This will open up the Sublime console. Copy and paste the below into it:

import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler())); open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen(''+pf.replace(' ','%20')).read()); print 'Please restart Sublime Text to finish installation'

Once that’s done you’ll be prompted to restart Sublime. Now that you have Package Control installed you can install GoSublime and GoToDoc. Fire up Sublime again and press Control Shift and P. This will bring up a text prompt at the top of the screen. Start typing in Package and choose the Package Control: Install Package from the drop down list.

Choosing that will prompt you for a package to install. Start typing in GoSublime and choose that.

GoSublime requires two other packages to handle syntax highlighting and other Sublime features. Press Control Shift and P again and start typing in “GoSublime: Install/Update MarGo and Gocode” and choose that.

Once that’s done we can install GoToDoc. Press Control Shift P again, start typing in Package, choose Package Control: Install Package and when prompted for the package to install start typing in GoToDoc.

For an example on how to use these plugins open up a simple “Hello World” hello.go file. Once that’s open in Sublime press and hold the Control key, then press comma and then R. That will run the code.

Most command for GoSublime use Control plus comma plus something else. You can see a list of what you can do by typing Control Shift P and start typing in GoSublime. That’ll give you a list of GoSublime functions and the hot key combinations to run them.

To use GoToDoc simply highlight a package name in the file(like fmt for example) and press Control Alt E. That’ll bring up a window in your web browser that goes to the documentation for that package. GoToDoc also has a Control Alt L function, but that conflicts with Ubuntu’s screen locking. So if you want that functionality(read more on it on the GoToDoc page) you’ll either need to remap it or remap Ubuntu’s screen locking.

In this post I’ll be going over how to setup Google’s Go in Ubuntu 12.04 64bit version. If you follow these steps you’ll have the build tools for Go installed which can compile for 386 or amd64 systems.

First you’ll need to install Subversion, Git and Mercurial which Go uses to download packages. In addition you’ll need some basic C build tools installed which will be used to compile Go itself. From the command line run the following:

sudo apt-get install mercurial git subversion gcc libc6-dev libc6-dev-i386

Next make sure you’re logged in as your normal user account. Add the below to your .bashrc file:

#This line will tell the Go installer where to place the source code before compilation
export GOROOT=$HOME/go

#With this line, you choose the architecture of your machine.
#Those with 64 bit CPUs should enter "amd64" here.
export GOARCH=amd64

#Your operating system
export GOOS=linux

#And now the location where the installer will place the finished files
#Don't forget to create this directory before installing
export GOBIN=$GOROOT/bin

#Include Go binaries in command path

When you do the above either run “source ~/.bashrc” to load the new settings or close and re-open a new terminal window.

Now you can install Go itself:

cd ~
hg clone -u release

cd go/src/

cd ~

This should install the basic Go build tools. Test this by putting the below code into a hello.go file:

package main

import "fmt"

func main() {
fmt.Printf("hello, world\n")

And then compile and run it:

go build hello.go


The above will have created a 64bit binary. But we can also setup Go to be able to compile i386 binaries:

cd ~/go/src/
GOARCH=386 ./all.bash

Once that’s done, go back and re-compile hello as an i386 binary:

cd ~
GOARCH=386 go build hello.go

Note that this binary will still run on your 64bit Ubuntu system since you have 32bit compatibility libraries installed on your system.