Import path does not begin with hostname

I hope someone can help. My first every experience of ‘go’ and its ‘bad’ :frowning:

I have installed go-lang from here:

I did exactly what was described for my OS centos7.

I then tried to write my first program (as shown on the page).

But when I try this:

go build hello.go

It fails:
hello.go:3:8: cannot find package “fmt” in any of:
/usr/local/go/src/fmt (from $GOROOT)
/root/go/src/fmt (from $GOPATH)
package main
imports runtime: cannot find package “runtime” in any of:
/usr/local/go/src/runtime (from $GOROOT)
/root/go/src/runtime (from $GOPATH)

Btw, I did google this issue, I found lots of answers, none made any sense.

Thanks in advance.

It is possible that the $GOPATH variable is not setup. Enter “echo $GOPATH”

I do not use centos, but I once installed GO from a distributions repos and all appeared fine. However things failed and I realised that $GOPATH had not been set.

My $GOPATH is currently set as “/home/bjc/go:/home/bjc/myApp” where myApp is the directory where my GO program is stored and “go” is where I have installed GO. “bjc” is my username.

Hope this helps


It could be that you have installed go in /root which may not be a good idea. However you know how your system is setup and it could be a centos thing

I just now upgraded to GO version 14.1 and checked a few things

GO was installed in /usr/lib64/golang

/usr/bin/go was linked to /usr/lib64/golang/bin/go

/home/bjc/go contains a src directory with my packages

/home/bjc/go also contains a pkg directory with packages that I have downloaded.

The first time I used go 14.1 it downloaded updated packages that were on my machine and this took several minutes. It appeared to be hanging. However once I allowed the first compile to run to completion, subsequent compiles were fast as expected.

On earlier versions of GO I do not remember this delay occurring.

I hope you continue with GO; I find it to be a very good product produced by people who know what they are doing. Not a statement I would make about many packages.

After thinking more about your problem I think it likely that your install went wrong for some reason.

Rgds Bill

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.