1

On fedora 22, I found that all the standard go libraries aren't visible on the path for go.

NOTE I have indeed cleaned my system of golang - so I'm pretty sure it's not a mixed package versioning problem which often can happen when upgrading go.

NOTE The version of go I've installed is 1.4.2

I have been setting GOROOT=/usr/lib/golang, and GOPATH=(anything).

What internal directories in /usr/lib/golang should I look into to troubleshoot the missing libraries?

A simple example of the failures I'm getting are below...

[jay@rhbd gopath]$ go get github.com/golang/example/hello package github.com/golang/example/hello imports fmt: unrecognized import path "fmt" package github.com/golang/example/hello imports runtime: unrecognized import path "runtime"

and the corresponding go env:

GOHOSTOS="linux" GOOS="linux" GOPATH="/home/jay/gopath/" GORACE="" GOROOT="/usr/lib/golang" GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64" CC="gcc" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0" CXX="g++" CGO_ENABLED="1"

UPDATE

As per the comments in this thread... It looks like I don't have ANYTHING under /usr/lib/golang/src. Does this basically imply that my Go distribution is broken? If so maybe the Go binary should fail fast when this is the case... ?

John Weldon
  • 39,849
  • 11
  • 94
  • 127
jayunit100
  • 17,388
  • 22
  • 92
  • 167
  • 3
    Exactly how are you installing Go? If you install from source, don't set `GOROOT`. – JimB Jun 15 '15 at 21:34
  • I've tried this with and without GOROOT. What are some tricks i can use to really inspect the problem? Why would GOROOT hurt the situation? – jayunit100 Jun 15 '15 at 21:36
  • 1
    I don't know what to troubleshoot, since I don't know how you got here. If you used the official binary installation, all you do is unpack the tarball, and set the appropriate variables. *What steps did you use to install Go?* – JimB Jun 15 '15 at 21:41
  • yum install golang (fedora packages). however, shouldn't there generally be a way you can see where go is looking for packages, to confirm/deny their existence ? Typically in the java world, we might do something like use System.getProperties to print all the jars on the classpath, and then look through them one by one for packages. I assume in golang there might be a similar low level way to manually find what packages that are supplied to a program at runtime? – jayunit100 Jun 15 '15 at 21:47
  • 2
    You almost never use `GOROOT`, because it's baked in to the compiled `go` tools, and setting it is [almost always a mistake](http://dave.cheney.net/2013/06/14/you-dont-need-to-set-goroot-really). There's no "low level" way to look up packages -- there's only two places to look `GOROOT` and `GOPATH`. The Go stdlib sources should be in `$GOROOT/src`. – JimB Jun 15 '15 at 21:55
  • Hmmm. okay. So, then your saying if GOROOT=/usr/lib/golang, and there is nothing under src/ then something is seriously broken with my go installation? I guess that resolves the issue ... . – jayunit100 Jun 15 '15 at 23:52

1 Answers1

-1

TLDR

The final solution to my problem was as follows (this maybe overkill).

yum erase golang-src

rm -rf /usr/lib/golang/

yum install golang-src golang

After installing golang-src, you should confirm that indeed under GOROOT/src/ there are several packages for all the standard go libs, i.e. the ones listed below.

THE DETAILS OF HOW TO INVESTIGATE GOLANG INSTALLATIONS

Obviously : go get gets and installs the source code you specify. Most go libraries use the standard libraries, like io or bytes and so on. Hence, a good test that your go distribution is installed correctly, and that your GOPATH is also set - is to run go get. For example go get github.com/golang/example/hello is sufficient to expose a flaw with GOROOT standard libraries.

The first thing to do is to check what GOROOT is out of the box in your isntallation. It is available by running go env, which will give you all go environment variables.

In general GOROOT should have a src/ directory underneath it. However, if you have a broken go package, then some of these libraries might not be (for some reason) under GOROOT/src. That is, you SHOULD see the source directories there for the core go stuff, for example, from a healthy working go installation.

ls /usr/lib/golang/src/ all.bash builtin/ compress/ errors/ html/ libbio/ Make.dist os/ run.bash strings/ time/ all.bat bytes/ ...... net/ regexp/ strconv/ text/

Now, looking back at my broken go installation, it looked very different from what is above ... It looks like I don't have ANYTHING under /usr/lib/golang/src . This basically means that my go package was missing some very important components, and almost any go get ... operation will thus fail, since none of the go standard libraries are in the GOROOT path.

As mentioned above -- the end solution here was simply to yum erase golang-src, rm -rf /usr/lib/golang/ and then and yum install golang-src golang.

jayunit100
  • 17,388
  • 22
  • 92
  • 167
  • Thanks for helping me answer this ! I guess I'll have to go check out the packaging of this distro and see why its excluding the go standard library src/ directory. – jayunit100 Jun 16 '15 at 00:07