1

I am trying to understand the go environment, but I can't seem to go install any package I git cloned locally. go install on the hello world example works fine.

~GOPATH/src/go-github(master ✔) go install -i go-github/github
~GOPATH/src/go-github(master ✔)
~GOPATH/src/go-github(master ✔)
~GOPATH/src/go-github(master ✔) ll ~GOBIN
total 80992
-rwxr-xr-x  1 drez  1896053708   6.2M Sep 21 14:57 basicauth
-rwxr-xr-x  1 drez  1896053708   6.3M Sep 21 14:57 commitpr
-rwxr-xr-x  1 drez  1896053708   6.3M Sep 21 14:57 fields
-rwxr-xr-x  1 drez  1896053708   1.9M Sep 21 14:06 hello
-rwxr-xr-x  1 drez  1896053708   6.2M Sep 21 14:57 migrations
-rwxr-xr-x  1 drez  1896053708   6.3M Sep 21 14:57 newrepo
-rwxr-xr-x  1 drez  1896053708   6.3M Sep 21 14:57 simple

My go env output is as follows:

~GOPATH/src/go-github(master ✔) go env
GOARCH="amd64"
GOBIN="/Users/drez/Dev/golang/bin"
GOCACHE="/Users/drez/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/drez/Dev/golang"
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/f7/zq9bg2ds6671wp4s7v3vkyf5rzyx5d/T/go-build744915712=/tmp/go-build -gno-record-gcc-switches -fno-common"

$PATH with $GOBIN at the end:

~GOPATH/src/go-github(master ✔) echo $PATH /Users/drez/.toolbox/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Users/drez/.toolbox/bin:/Users/drez/Library/Android/sdk/platform-tools:/Library/Frameworks/Python.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/Users/drez/Library/Android/sdk/platform-tools:/Users/drez/Dev/golang/bin
sizzle
  • 2,883
  • 2
  • 13
  • 10
  • What is error message ? – Jérôme Teisseire Sep 28 '18 at 21:35
  • did you add $GOBIN to your $PATH variable – nilsocket Sep 28 '18 at 21:35
  • there is no error message. It just silently does nothing or fails. – sizzle Sep 28 '18 at 21:48
  • yes, here is my $PATH. ```~GOPATH/src/go-github(master ✔) echo $PATH /Users/drez/.toolbox/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Users/drez/.toolbox/bin:/Users/drez/Library/Android/sdk/platform-tools:/Library/Frameworks/Python.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/Users/drez/Library/Android/sdk/platform-tools:/Users/drez/Dev/golang/bin``` – sizzle Sep 28 '18 at 21:48
  • Try `go install github` since you are already in `go-github`. Just wondering if that will work – Husain Sep 29 '18 at 03:03
  • Go install does _not_ do what you think it is for. What you want to do _cannot_ be done by go install as go install does something completely different. – Volker Sep 29 '18 at 05:38

1 Answers1

5

go install command is for installing binary into your workspace's bin directory or go clean -i to remove it.

If you want to download a lib to resolve your imports you need to use go get command.

Also, consider that only the main packages can be installed

charly3pins
  • 389
  • 1
  • 11
  • yes, I want to install the binary locally. I `git clone` the source files to my local environment like I've shown above. My issue is creating a local binary. – sizzle Sep 28 '18 at 21:45
  • The problem here is that the `go-github/github` is not a `main` package, so will not be compiled as a binary and will not be installed to `bin` folder – charly3pins Sep 28 '18 at 21:55
  • My real goal is to make edits to the source code for a project and hopefully contribute it back to the open source community. How do I go about editing this package and testing it locally? – sizzle Sep 28 '18 at 21:57
  • If you want to contribute to that project, you need to fork the project and work with your own repo. For testing it it's not necessary installing to `bin` because you'll need to import the lib to your code, so you can point to your repo (local fork) and change the code as you want. When you're okay, you can push to your repo and then open PR to the original project. – charly3pins Sep 28 '18 at 22:02
  • ok, thanks for the help. I will do that. Let's say I want to just download the src code and compile locally. Is the only way to do that is to put under a `main` package? – sizzle Sep 28 '18 at 22:19
  • yes, if you check the go-github/test/fields/fields.go you'll se the package there is a `main` and you can build it, but not other ones – charly3pins Sep 28 '18 at 22:21
  • @sizzle you can mark as answered please? Or if you have more doubts in can help you. Thanks – charly3pins Oct 01 '18 at 16:58