Go "unrecognized imports"

1.6k Views Asked by At

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... ?

1

There are 1 best solutions below

1
On

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.