34

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?

0

5 Answers 5

44

go get requires git if any of the packages lives (and is being fetched) from a git repository. For Windows, you can install git from the git website.

Sign up to request clarification or add additional context in comments.

6 Comments

And then restart VS Code once git installed.
After you installed it, go to System Properties (sysdm.cpl from Run) -> Environment Variables -> edit Path from the System variables and add the path (..\Git\bin) of the installation folder of git.exe. See @Variety_Davids answer.
Why one should install complete git just to fetch repositories?
@Nilesh go downloads the source code of the dependencies through their declared version control system. If all your dependencies and your code were version controlled using mercurial instead, you wouldn't need git at all, just mercurial.
Yes I understand, go uses VCS to download source code. My question was Why go-get cannot download source code without installation of git. To develop simple project go enforces users to install VCS, this looks so opinionated to me!
|
39

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

1 Comment

OP is using windows.
6

The go get fetching of source code is done by using one of the following tools expected to be found on your system either git, svn, hg.

Install git from this link https://git-scm.com/downloads

After installing git you should navigate to the environment variables setting and add the path of git.exe(executable file) which is found in the bin. So the path should look like this "C:\Program Files\Git\bin". Restart your IDE and the command should be working.

Comments

3

Install git.

for Ubuntu, you can use the command

sudo apt-get install git

1 Comment

OP is using windows.
1

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'
    ...
  }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.