How to install go package after downloading?

1.2k Views Asked by At

I ran this:

cd $GOPATH && go get -u github.com/zricethezav/gitleaks

perplexingly, I now have this:

$GOPATH/
     src/
       github.com/
         gitleaks/

but there is not a bin/ folder ... I would have expected to see the bin folder here: $GOPATH/bin

did I do something wrong? How do I install the package so that the binary shows up? I tried running:

go install github.com/zricethezav/gitleaks

but after installing I don't see a bin/ folder...

The output of go env looks like:

GOARCH="amd64"
GOBIN="/Users/alex/go/bin"
GOCACHE="/Users/alex/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/alex/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/st/159q4vsd64b69_x99dtzzt6m0000gn/T/go-build133179815=/tmp/go-build -gno-record-gcc-switches -fno-common"
3

There are 3 best solutions below

1
On

If $GOPATH isn't go's root directory I think you have to create bin folder manually. I've manually created $GOPATH/bin folder and its working fine.

0
On

After go get, the gitleaks executable should be in $GO_PATH\bin directory, not in the $GO_PATH\src...\gitleaks.

See this: https://pocketgophers.com/go-install-vs-go-build/

0
On

I installed golang on MacOS with brew install go, and that apparently didn't put the main binaries in /usr/local/go, which is why my go get command failed.

so instead of using brew, I installed via: https://golang.org/doc/install?download=go1.12.5.darwin-amd64.pkg

and after installing using the .pkg file, there were files in /usr/local/go, so then my go get command worked.

My guess is that homebrew puts the go binaries in a different location than /usr/local/go which kinda sux but I could see why.