在执行`go install`时出现错误。

huangapple go评论113阅读模式
英文:

Error When Issuing `go install`

问题

当我执行go install命令时,我在我的go根路径下遇到了以下错误:

main.go:4:2: 无法在以下任何位置找到包"fmt":
    /usr/lib/go-1.6/bin/src/fmt(来自$GOROOT)
    /home/rbtlong/go/src/fmt(来自$GOPATH)
main.go:6:2: 无法在以下任何位置找到包"io/ioutil":
    /usr/lib/go-1.6/bin/src/io/ioutil(来自$GOROOT)
    /home/rbtlong/go/src/io/ioutil(来自$GOPATH)
main.go:5:2: 无法在以下任何位置找到包"net/http":
    /usr/lib/go-1.6/bin/src/net/http(来自$GOROOT)
    /home/rbtlong/go/src/net/http(来自$GOPATH)
包rbtlong.com导入runtime时出错:无法在以下任何位置找到包"runtime":
    /usr/lib/go-1.6/bin/src/runtime(来自$GOROOT)
    /home/rbtlong/go/src/runtime(来自$GOPATH)

我尝试取消设置GOROOT,但似乎没有起作用。

英文:

I'm in my go root path and I get error the following errors when I perform the go install command...

main.go:4:2: cannot find package "fmt" in any of:
	/usr/lib/go-1.6/bin/src/fmt (from $GOROOT)
	/home/rbtlong/go/src/fmt (from $GOPATH)
main.go:6:2: cannot find package "io/ioutil" in any of:
	/usr/lib/go-1.6/bin/src/io/ioutil (from $GOROOT)
	/home/rbtlong/go/src/io/ioutil (from $GOPATH)
main.go:5:2: cannot find package "net/http" in any of:
	/usr/lib/go-1.6/bin/src/net/http (from $GOROOT)
	/home/rbtlong/go/src/net/http (from $GOPATH)
package rbtlong.com
	imports runtime: cannot find package "runtime" in any of:
	/usr/lib/go-1.6/bin/src/runtime (from $GOROOT)
	/home/rbtlong/go/src/runtime (from $GOPATH)

I have tried unsetting the GOROOT, but it doesn't seem to work.

答案1

得分: 2

根据讨论,听起来你的安装有些混乱。重新安装Go似乎是最好的选择。

对于其他人来说,如果遇到GOROOT的问题,第一步几乎总是要取消设置GOROOT。在大多数情况下,不需要设置GOROOT,而且往往会导致问题。

另一个更容易管理Go安装的选项(并且在很大程度上自动化),还提供类似于Python的virtualenv或Ruby的rvm的版本切换功能和容器化功能,是使用GVM

英文:

Per discussion, it sounds like your install is a bit mucked up. Reinstalling Go seems to be the best option.

For others investigating GOROOT issues, the first step is almost always going to be to unset GOROOT. In most cases, GOROOT is not needed, and tends to muck up the works.

Another option for managing your Go installs more easily (and largely automagically), which also gives a homebrew-like version swapping capability and a containerization similar to virtualenv for Python or rvm for Ruby, is to use GVM.

答案2

得分: 0

显然,在删除了GOPATH和GOROOT的定义之后,该定义是在$HOME/.bashrc中定义的,然后手动删除了/usr/lib/go-1.6文件夹,然后按照这里的说明重新安装它https://golang.org/doc/install#install,然后通过编辑$HOME/.profile来设置PATH和GOPATH:

PATH="[...]:/usr/local/go/bin[...]"

export GOPATH="$HOME/go"

现在看起来它正在工作...

英文:

apparently, the definition was defined in $HOME/.bashrc after removing the definition for GOPATH and GOROOT, then manually removing the folder at /usr/lib/go-1.6 then reinstalling it using the instructions here https://golang.org/doc/install#install then setting the PATH and GOPATH by editing $HOME/.profile:

> PATH="[...]:/usr/local/go/bin[...]"
>
> export GOPATH="$HOME/go"

it appears to be working now...

答案3

得分: 0

在执行go install之前,请检查Go版本和Go路径,如果这些都正确,就不会出现任何错误。

请从官方网站安装最新版本的Go,并重新尝试一次。

英文:

Before doing go install check for the Go version and Go path, if these are correct you won't get any error.

Please, install Go latest version from the official website and re-try once.

huangapple
  • 本文由 发表于 2016年12月16日 06:34:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/41174440.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定