英文:
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.
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
-
确保在 Go 1.16+ 版本中运行以下命令:
go install github.com/golang/mock/mockgen@v1.6.0
-
将 users/[your_login]/go/bin 添加到 .zshrc 的路径中。
英文:
-
Make sure run below for go 1.16+
go install github.com/golang/mock/mockgen@v1.6.0
-
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!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论