2

I am learning how to create packages and documentation with Go and I cannot get godoc to work on my M1 Macbook Pro. I have installed it via go install golang.org/x/tools/cmd/godoc@latest and when I try to run godoc -http=:8080 my terminal says: zsh: command not found: godoc any help would be greatly appreciated.

I have also tried running export PATH="$GOPATH/bin:$PATH" to no avail, based on the answers in another SO thread.

I saw some answers about editing ~./zshrc however I have no such file on my computer and dont know how to edit it anyway. If that is the answer help there is appreciated as well!

results of go version: go version go1.19.4 darwin/arm64

Results of which go: /usr/local/go/bin/go

Results of go env: GO111MODULE="" GOARCH="arm64" GOBIN="" GOCACHE="/Users/ouris/Library/Caches/go-build" GOENV="/Users/ouris/Library/Application Support/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="arm64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/Users/ouris/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="/Users/ouris/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64" GOVCS="" GOVERSION="go1.19.4" GCCGO="gccgo" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="/dev/null" GOWORK="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage- length=0 -fdebug-prefix-map=/var/folders/kl/1xcqlnwx7s142gkt4w245lm00000gn/T/go- build1954240093=/tmp/go-build -gno-record-gcc-switches -fno-common"

  • If you don't already have a `~/.zshrc`, you can run `autoload -U zsh-newuser-install && zsh-newuser-install -f` which will walk you through creating one (see [the docs on that](https://zsh.sourceforge.io/Doc/Release/User-Contributions.html#User-Configuration-Functions)). Then you can add your GOBIN like so: `echo -n 'export PATH=$GOPATH/bin:$PATH' >> ~/.zshrc`, and then `source ~/.zshrc` (or see the other options [here](https://stackoverflow.com/questions/11530090/adding-a-new-entry-to-the-path-variable-in-zsh). Assuming there are no errors with the `go install`, this _should_ get you working. – Zac Anger Jan 17 '23 at 03:07
  • you need to check where the binary file `godoc` is installed, if it is in the path `$GOPATH/bin` then adding it `$PATH` will solve this issue. However, if it is not installed or installed in some other dir(`$GOROOT/bin` for instance), you will have to add that path. – whitespace Jan 17 '23 at 07:35

0 Answers0