go - 'go install' 找不到包 "fmt"

标签 go

我通过解压到 ~/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/

相关文章:

arrays - GO 中的测试列表

go - 添加/减去两个数字字符串

Golang : why runtime. GOMAXPROCS 限制为256?

html - Go http.Handle() 未按预期工作。 404 找不到文件

通过多台主机进行 SSH

去浪。调用 ".Front()"获取字符串列表。但是返回错误说字符串列表没有 Front 方法

go - 参数和从位置 [1] 传递的参数(不是位置 0)

git - 为团队构建 Go 子包

golang 在两个 uint 值上使用 math.max 的正确方法是什么?

Go语言中带*前缀的字符串