6

I'm new to go. Currently I'm using zsh terminal in macOS, just followed the instructions pointed out here https://github.com/golang/mock when installing go mock. However when trying to execute a mockgen command I keep seeing zsh: command not found: mockgen and when navigating in the terminal to my $GOPATH/bin i see mockgen inthere, so I don't know if there's anything else needed.

enter image description here

These are the variables I have configured in my /.zshrc file:

#GO path
export GOPATH="$HOME/Documents/study_projects/go"
export GOBINPATH="$GOPATH/bin"

Idk if GOBINPATH is a proper name for this $GOPATH/bin variable to be exported to the PATH also, aso pointed out in https://github.com/golang/mock (mockgen/gomock) installation instructions. Does anyone of you know what else is needed here, do I need an additional configuration for this mockgen command to work with zsh?

Thank you!

4 Answers4

10
  1. Make sure run below for go 1.16+

    go install github.com/golang/mock/mockgen@v1.6.0

  2. Add users/[your_login]/go/bin to .zshrc path

sth
  • 116
  • 1
  • 4
6

add export PATH=$PATH:$(go env GOPATH)/bin in .zshrc and try again.

0

My mockgen got installed under vim /Users/xxx/go/bin/darwin_amd64/ instead of /Users/xxx/go/bin so I moved it to bin folder and it worked!

cp /Users/xxx/go/bin/darwin_amd64/mockgen /Users/xxx/go/bin/ 
visrahane
  • 327
  • 4
  • 5
0

What version of Golang are you using? For Go version 1.16+, you don't need to use GOPATH In my case, the binary was installed in this path: /Users/USERNAME/go/bin/mockgen so I added it to my $PATH in .zshrc.

HTH!

avp
  • 2,892
  • 28
  • 34