BinaryWebPark

Setting Up Golang Like a Rubyist

May 16, 2015

Getting into the Go Programming Language

I use Ruby in my day job, but recently I’ve been dabbling with Go. The install docs give you an easy way to setup if you’re on Linux:

export PATH=$PATH:/usr/local/go/bin

But I’m used to RVM and other environment managers – where is the RVM for Go?

Using the Ruby ecosystem can kind of spoil you a bit as a developer as I’ve found while exploring Go. The tooling is easy to use and setup. I’ve gotten used to the workflow of creating gemsets specifically for particular applications (or using bundler if you prefer) and being able to switch from one to the other using a command line tool like rvm. I rarely have to think about exporting PATH variables.

Fortunately, there is GVM

Step 1 – Install GVM

There are some pretty clear instructions the GVM README which will let you install GVM.

Step 2 – Create a pkgset (similar to a gemset in rvm)

$ gvm pkgset create awesomecode
$ gvm pkgset use awesomecode

Step 3 – Edit GOPATH and PATH environment variables

In your terminal type:

$ gvm pkgenv awesomecode

This will open something like the below configuration file in your favorite editor specified by the environment variable: $EDITOR. You can also navigate directly to it where you installed your .gvm folder. In my case, it was at $HOME/.gvm/environments and was called go1.4@awesomecode.

##MY ORIGINAL GOPATH
# export GOPATH="/home/bruce/.gvm/pkgsets/go1.4/awesomecode:$GOPATH"

##EDITED GO

export GOPATH="/home/bruce/.gvm/pkgsets/go1.4/awesomecode:$HOME/Documents/github_code/awesomecode/go:$GOPATH"

##MY ORIGINAL PATH

# export PATH="/home/bruce/.gvm/pkgsets/go1.4/awesomecode/bin:${GVM_OVERLAY_PREFIX}/bin:${PATH}"

##EDITED PATH

export PATH; PATH="/home/bruce/.gvm/pkgsets/go1.4/awesomecode/bin:${GVM_OVERLAY_PREFIX}/bin:$HOME/Documents/github_code/awesomecode/go/bin:${PATH}"

Step 4 – Other Notes

The other thing I’m learning is that running go requires a very specific directory structure. In the /awesomecode/go directory, I had to create pkg, src, and bin directories in addition to the main directory that housed my hello_world.go file.

Sources:

I stole shamelessly from this post by vastbinderj. I’m writing this to document this so I don’t forget. Thanks open source!