zsh: 找不到命令: mockgen – golang 1.18 – macOS Monterrey

huangapple go评论93阅读模式
英文:

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

问题

我是你的中文翻译助手,以下是翻译的内容:

我是Go的新手。目前我在macOS上使用zsh终端,按照这里指出的说明https://github.com/golang/mock安装go mock。然而,当我尝试执行mockgen命令时,我不断看到zsh: command not found: mockgen,当我在终端中导航到我的$GOPATH/bin时,我看到mockgen在其中,所以我不知道是否还需要其他东西。

这是我在/.zshrc文件中配置的变量:

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

我不知道GOBINPATH是否是将$GOPATH/bin变量导出到PATH中的正确名称,正如https://github.com/golang/mock(mockgen/gomock)安装说明中所指出的那样。你们中的任何人知道这里还需要什么,我是否需要额外配置才能让mockgen命令在zsh中工作?

谢谢!

英文:

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.

zsh: 找不到命令: mockgen – golang 1.18 – macOS Monterrey

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!

答案1

得分: 10

  1. 确保在 Go 1.16+ 版本中运行以下命令:

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

  2. users/[your_login]/go/bin 添加到 .zshrc 的路径中。

英文:
  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

答案2

得分: 6

在.zshrc文件中添加export PATH=$PATH:$(go env GOPATH)/bin,然后再试一次。

英文:

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

答案3

得分: 0

我的 mockgen 安装在 vim /Users/xxx/go/bin/darwin_amd64/ 下,而不是 /Users/xxx/go/bin,所以我将其移动到 bin 文件夹中,然后它就可以工作了!

cp /Users/xxx/go/bin/darwin_amd64/mockgen /Users/xxx/go/bin/

<details>
<summary>英文:</summary>

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/

答案4

得分: 0

你使用的是哪个版本的Golang?对于Go版本1.16+,你不需要使用GOPATH。在我的情况下,二进制文件安装在这个路径下:/Users/USERNAME/go/bin/mockgen,所以我在.zshrc中将其添加到了我的$PATH中。

希望对你有帮助!

英文:

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!

huangapple
  • 本文由 发表于 2022年5月30日 13:21:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/72429463.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定