For the last few years the computer I use most at home has been a Dell Chromebook 11. It’s great for browsing the web but not so great at being a developer machine. Although you can install Linux on it if you wish, that comes with an awful lot of baggage. To avoid using my desktop so much (it’s hard to lock myself away upstairs for hours with a family) I often find myself tryingto get new things running on the Chromebook that I can play around with from the sofa.

Previously it was the Dart VM and today it is Go. I actually tried Rust and it hasn’t worked out (yet) so Go was a fallback :D

Note: I’ve never written a line of Go in my life until about 30 minutes ago. This post might not be the best way of doing things and the instructions may become broken in future with Go or ChromeOS changes.

Setting up Go actually turned out to be pretty simple. Easier than Dart in fact!

When I did this for Dart, I ended up editing .bash_profile in vi (or using echo) and it was a bit of a mess. Subsequently I’ve installed Text and created a symlink at ~/Downloads/bash_profile to ~/.bash_profile so it can be edited in Text (ChromeOS file manager can only see files inside ~/Downloads and not hidden files, hence the missing dot).

Enable Developer Mode

Instructions on enabling developer mode can be found here. Every time you boot your device in this mode you will get a scary splash screen and have to press Ctrl+D to avoid resetting your device. WARNING: Enabling developer mode will delete all of your locally stored data (though since it’s a Chromebook, this is really only your Downloads folder).

Download and Extract Go

Download the Linux version of Go to your Downloads folder. I picked the 64 bit AMD version for my Dell Chromebook 11; some Chromebooks might require the 32 bit or ARM version.

Next, open a terminal window by pressing Ctrl+Alt+T then typing shell. Then extract Go somewhere suitable. I put it at ~/Coding/go/ (the archived already has everything inside a folder named go).

mkdir ~/Coding
tar -xzf ~/Downloads/go1.6.2.linux-amd64.tar.gz -C ~/Coding/

Set Execute Permissions for the File System

In order to execute anyting from this drive you’ll need to remount it as executable. You may have already done this if you’ve set other things up (such as the Dart VM). Without this, you’ll get Permission denied trying to execute anything.

echo "sudo mount -i -o remount,exec /home/chronos/user/" >> ~/.bash_profile

Note: In order for go run to work you will also need to remount /tmp as executable. go run compiles into a temp folder then executes from there. There may be security implications in doing this!

echo "sudo mount -i -o remount,exec /tmp/" >> ~/.bash_profile

Set Environment Variables

The easiet way to do this is with Text and a symlink to ~/.bash_profile as mentioned before. Otherwise you can try using vi (or echo)!

export GOROOT=~/Coding/go # This is where you extracted Go
export GOPATH=~/Downloads/go # This is where you will keep your Go projects
PATH=$PATH:$GOROOT/bin:$GOPATH/bin # This adds both Go and your "installed" projects to PATH

Restart and Test

Type exit or close the terminal window then re-open with Ctrl+Alt+T and type shell. Type go version and you should see go version go1.6.2 linux/amd64 or similar.

Hello, World!

Now we have a working Go, we should build Hello World!

There seems to be a convention that you should name your packages after the repo you’ll be hosting them in. They’ll need to hang off $GOPATH/src, eg:

mkdir $GOPATH/src/github.com/{username}/hello -p

Next create a hello.go file in that directory using your favourite editor with a simple Hello World:

package main

import "fmt"

func main() {
	fmt.Printf("Hello, World!\n")
}

Now we want to build and execute it. If we use go install instead of go build it will copy the executable into $GOPATH/bin which we added to our PATH earlier. We can either pass the package path (relative to $GOPATH) to go install or change to the directory and omit it:

cd $GOPATH/src/github.com/{username}/hello
go install
hello

If you chose to remount /tmp as executable then you can also use go run {file}:

cd $GOPATH/src/github.com/{username}/hello
go run hello.go

If you’ve done everything correctly, this will output Hello, World! :)

If you’re interested in a Chromebook; don’t forget to take a look at Chromebook Comparison Chart! :)