我通过解压到 ~/go 并相应地设置 GOROOT 来安装 go 1.7.4。我还创建了 ~/work/src/github.com/user/hello 并相应地设置了 GOPATH。
当尝试来自 https://golang.org/doc/install#testing 的 hello world 示例时我收到以下错误:
$ go install github.com/user/hello
../work/src/github.com/user/hello/hello.go:3:8: cannot find package "fmt" in any of:
/home/user/go/src/pkg/fmt (from $GOROOT)
/home/user/work/src/fmt (from $GOPATH)
package github.com/user/hello
imports runtime: cannot find package "runtime" in any of:
/home/user/go/src/pkg/runtime (from $GOROOT)
/home/user/work/src/runtime (from $GOPATH)
检查 ~/go,我发现 fmt 在 ~/go/src/fmt 而不是 ~/go/src/pkg/fmt
感觉好像遗漏了一些重要的东西。感谢您的帮助。
最佳答案
如果你之前从包管理器安装了 Go,你可能有一个旧版本。检查 go version
并在需要时删除旧版本。
关于go - 'go install' 找不到包 "fmt",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40977283/