golang“go get”命令显示“go: missing Git command”错误

新手上路,请多包涵

我是 go lang 的新手。尝试使用“go get”命令导入 go 库,但在 cmd 中出现此错误:

 go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/ttacon/chalk: exec: "git": executable file not found in  %PATH%

我的去环境:

 set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=F:\Works\Go
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GO15VENDOREXPERIMENT=1
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1

我的 Go 环境有什么问题?

原文由 Yeahia2508 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.7k
2 个回答

go get 如果有任何包存在于(并且正在获取)来自 git 存储库,则需要 git。对于 Windows,您可以从 git 网站 安装 git。

原文由 T0xicCode 发布,翻译遵循 CC BY-SA 3.0 许可协议

在本地

安装 git 将解决问题。

  • 对于 mac brew install git
  • 对于 ubuntu sudo apt-get install git
  • 对于 arch linux pacman -S git
  • 对于 Windows,根据 git installation page 中的说明安装 git。

在 Docker 中

如果您在构建 docker 镜像时正在运行,那么您应该在那里安装 git。 [我在构建 docker 镜像时遇到了这个问题]

例如:在我的 Dockerfile 中

FROM golang:alpine
RUN apk add git

原文由 alamin 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题