zsh: command not found: mockgen - golang 1.18 - macOS Monterrey

23.5k Views Asked by At

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!

5

There are 5 best solutions below

0
On BEST ANSWER
  1. Make sure run below for go 1.16+

    go install github.com/golang/mock/[email protected]

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

0
On

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/ 
0
On

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!

0
On

Had the same problem. Tried to add mockgen to the $PATH, didn't help.

Just added the path directly in command line:

/Users/{username}/go/bin/mockgen -source={source_path}.go -destination={destination_path}.go -package=mock {interfaces}

Worked for me

2
On

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