Right now I’m working on learning Go by writing a small app that will, eventually, take a Markdown file and convert it to an HTML presentation. When I started working on my program today, my code wouldn’t compile. It was referring to missing packages/etc. I thought, well this can’t be good.
First step, check
$GOROOT. In my case,
$GOROOT was null and
$GOPATH was returning its old value. (Now that I’ve figured out what’s going on, I’m pretty sure that those more experienced than I already know where this is going…) I fixed
$GOPATH to include the new path and
$GOROOT to, IIRC,
/usr/local/go. Then I checked my
$PATH variable and thankfully that was still fine.
I tried running my program again, only to encounter this lovely gem*:
/usr/local/go/pkg/tool/darwin_amd64/6g: unknown flag -trimpath
I had NO idea what this error meant, so I googled for it. It took a little time for me to find something useful, but thankfully Stack Overflow came to my rescue (…again). I learned that I needed to reinstall Go after first making sure I removed the current version. Lovely.
I head over to the Go project page and check how to uninstall Go. Short and sweet, everything seemed fine. Then I download the current installer for Mac OS X, which as of this writing is for 1.3.1, and off I go.
I re-open terminal and try to run my little app. Unfortunately, I still have import problems (I wish I had saved those errors to paste in here, sorry guys). I try to reinstall blackfriday, which is a Markdown processor in Go:
$ go get github.com/russross/blackfriday
../../russross/blackfriday/sanitize.go:6: import /Users/qanx/Development/Go/pkg/darwin_amd64/code.google.com/p/go.net/html.a: object is [darwin amd64 go1.3 X:precisestack] expected [darwin amd64 go1.3.1 X:precisestack]
Great. I have NO idea what this means as it appears that the expected and fond objects are the same. So I "phone a friend".
His first question? "Are you running more than one version of Go?"
So I tell him: No. Well, I hope not. Maybe. I’m not trying to. So I tell him the story: when I first downloaded Go I just wanted to put it somewhere, so I had it on my Desktop. Then I decided that was a bad idea. So I moved it to
~/Development which is where I have all my other code projects. Then I tried updating the various environmental variables and it all seemed fine. Until I reopened terminal. So I removed the old, I think, to install the new.
He had me check the version using the explicit path to the command. I then tried running it without the path, to see if the output differed:
$ go version
go version go1.3 darwin/amd64
$ /usr/local/go/bin/go version
go version go1.3.1 darwin/amd64
Yeah. Two versions of Go. To see where the other version of Go was installed, I ran "which go":
$ which go
Ah. See. There it is then. Great.
Before removing the "old" version of Go I updated my
~/.bash_profile to the current path I am using for Go:
~/Development/Go/. Then I closed and re-opened Terminal and everything was fine:
$ go run main.go -inputFile=~/Development/temp/myfile.md -log=info
2014-09-18 20:33:23.509 INFO Starting gopress
2014-09-18 20:33:23.511 WARNING Output directory unspecified or does not exist, creating new directory: /Users/qanx/Development/temp/myfile/
2014-09-18 20:33:23.514 INFO Successfully created new directory.
2014-09-18 20:33:23.517 INFO Successfully copied files.
2014-09-18 20:33:23.517 INFO Exited with no errors.
I even ran "go get" successfully, which after all this was a relief.
Then the magic happened, removing the old version:
$ rm /usr/local/bin/go
And everything was right again in my world. Good grief.
*I suppose I should use the term "gem" with caution since I may run into Ruby again. Don’t want to give it any ideas.