6

Though go help is useful, but still it's not as expressive as man pages.

So, any way to get man page for go binaries on unix based systems?

If not, why such a feature hasn't been done since golang is so popular nowadays?

Eric
  • 22,183
  • 20
  • 145
  • 196
  • Man pages on Windows? – Volker Apr 28 '18 at 06:57
  • @Volker The question said `unix` based systems. – Eric Apr 28 '18 at 06:57
  • As man page for `g++` exists why not one for `go`? – Nidhin David Apr 28 '18 at 07:01
  • The `go help` text changes dynamically now for many commands depending on whether or not you're in a module package. It might be cumbersome to have two separate manpages for each command and always have to add a suffix or something in order to look up the one you want. – Rag May 16 '20 at 23:18
  • It is shocking to find that go has no man page. I did `man go` today in FreeBSD to check about the available options for build and I thought that there was something wrong with the man pages in my system. – M.E. Dec 31 '20 at 17:32

2 Answers2

7

You have an alternative with goman, presented here

See the GitHub project christophberger/goman: that is not for Go itself, but could be adapted to generate the man page for Go.

Otherwise... go issue 101 is one of the oldest issues out there (2009), and still opened!
It was supposed to be fixed by an official goman command (see CL 5700081), but that never was completed.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I installed it, by `go get -u github.com/christophberger/goman`, and add the `main () {..}` part into `.bashrc`, but when execute command `goman` it says `No command 'goman' found`. – Eric Apr 28 '18 at 07:13
  • @EricWang Is your $GOPATH/bin part of your PATH? Do you see goman in $GOPATH/bin? – VonC Apr 28 '18 at 07:13
  • It's missing, I just added it, and now could found command `goman`, and seems need to get the source code of those binaries to get result from `goman xxx`? – Eric Apr 28 '18 at 07:22
  • And seems it simple print content of README file, e.g `goman goman`, and `goman go` can't find doc, since there is no README file for it. So, seems it's not a perfect alternate for the typical man page. – Eric Apr 28 '18 at 07:29
  • @EricWang First: has goman been compiled and installed as a result of the go get -u? "could found command goman" means either it was not, or the PATH does not reference GOPATH/bin. Or you did not exported the new PATH. – VonC Apr 28 '18 at 07:30
  • @EricWang That is what I meant with "that is not for Go itself": not an ideal solution, just an idea to be adapted. – VonC Apr 28 '18 at 07:30
  • @EricWang The sources in https://codereview.appspot.com/5700081/ are more fit for Go commands themselves... but was never completed. – VonC Apr 28 '18 at 07:32
  • I see, I found a solution for ubuntu, please check the answer I just added. – Eric Apr 28 '18 at 07:53
2

For Ubuntu, I found this solution: https://github.com/golang/go/wiki/Ubuntu


Example - ubuntu 16.04 & golang 1.10 (2018-04)

sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt-get update
sudo apt-get install golang-go

Then man pages are available.

e.g

man go
man go-get    # man page for `go get` sub command,
man gofmt

Tips:

  • Newest version of golang might can't be installed via the method above (it has some kind of delay I think).
    My solution is to install the newest/desired version of golang via download manually, and make sure in $PATH, the manually installed one is searched first.
    So that when use which go, it will found the manually installed binary, instead of the one installed via apt-get.
    Thus could get the man page, while still able to use any desired version of golang.
Eric
  • 22,183
  • 20
  • 145
  • 196