Installing godoc for golang (go 1.2)

I recently read about godoc, but when I went to try it the binary wasn’t installed.

Fortunately, it was a relatively easy fix:

go get golang.org/x/tools/cmd/godoc

As it wants to write to a privileged location (/usr/lib/go/bin/), you might need to run it as root

sudo -E go get golang.org/x/tools/cmd/godoc

The -E flag means “preserve environment variables”, which you’ll need to preserve your $GOPATH.

Next, add /usr/lib/go/bin/ to your path:

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

Then run godoc:

$ godoc fmt Println
func Println(a ...interface{}) (n int, err error)
    Println formats using the default formats for its operands and writes to
    standard output. Spaces are always added between operands and a newline
    is appended. It returns the number of bytes written and any write error
    encountered.

Michael is a polyglot software engineer, committed to reducing complexity in systems and making them more predictable. Working with a variety of languages and tools, he shares his technical expertise to audiences all around the world at user groups and conferences. You can follow @mheap on Twitter

Thoughts on this post

kaskavalci 2016-01-06

Thanks Mıchael. However go get returns with warning;
“`
warning: code.google.com is shutting down; import path code.google.com/p/go.tools/cmd/godoc will stop working
the code.google.com/p/go.tools/cmd/godoc command has moved; use golang.org/x/tools/cmd/godoc instead.
“`

You should use `go get golang.org/x/tools/cmd/godoc`

michael 2016-01-08

Thanks Halil, the post has been updated 🙂

Leave a comment?

Leave a Reply