golang "go get" command showing "go: missing Git command" error

Viewed 89158

I'm new in go lang. Trying to import a go library using "go get" command but in cmd getting this error:

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

My Go Env:

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

What's wrong with my Go environment?

5 Answers

Locally

Installing git will solve the issue.

  • for mac brew install git
  • for ubuntu sudo apt-get install git
  • for arch linux pacman -S git
  • for windows install git according to the instructions from the git installation page.

In Docker

If you are getting while running in building docker image then you should install git there. [I got this issue while building docker image]

For Example: In my Dockerfile

FROM golang:alpine 
RUN apk add git

Install git.

for Ubuntu, you can use the command

sudo apt-get install git

If you're running this as a Jenkins pipeline script, start your Docker image like:

node('docker') {
  docker.image('golang:1.14rc1-alpine3.11').inside(' -u 0') {
    sh 'apk add curl'
    ...
  }
}
Related