我已经在Fedora 21笔记本电脑上安装了GO,并且安装了GOPATH和GOBIN,但是由于某种原因,它不允许我安装go程序。

pred@computer01 [20:03:02] ~
$ echo $GOPATH
/home/pred/Documents/GO
pred@computer01 [20:03:11] ~
$ echo $GOBIN
/home/pred/Documents/GO/bin
pred@computer01 [20:03:15] ~
$ cd $GOPATH
pred@computer01 [20:03:21] ~/Documents/GO
$ go install src/github.com/pred3/go_helloworld/helloworld/helloworld.go
go install: no install location for .go files listed on command line (GOBIN not set)
pred@computer01 [20:03:32] ~/Documents/GO
$ go env
GOARCH="amd64"
GOBIN="/home/pred/Documents/GO/bin"
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/pred/Documents/GO"
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"

为了使它正常工作,我还应该做什么?

- 编辑 -

如下所述,发出以下命令也会产生错误。
pred@computer1 [21:22:51] ~/Documents/GO
$ go install src/github.com/pred3/go_helloworld/helloworld
can't load package: package src/github.com/predatorian3/go_helloworld/helloworld: cannot find package "src/github.com/pred3/go_helloworld/helloworld" in any of:
    /usr/lib/golang/src/src/github.com/pred3/go_helloworld/helloworld (from $GOROOT)
    /home/pred/Documents/GO/src/src/github.com/pred3/go_helloworld/helloworld (from $GOPATH)

但是,我尝试安装的go文件的开头没有package main。一旦将其更改为package main,它就会起作用。我不确定为什么我不能使用其他软件包名称。

最佳答案

go install希望将软件包作为参数(有关详细说明,请参见Description of package lists)。在您的情况下,可能应该是

go install github.com/pred3/go_helloworld/helloworld

假设存在$GOPATH/src/github.com/pred3/go_helloworld/helloworld目录,并且$GOPATH/src/github.com/pred3/go_helloworld/helloworld/helloworld.gopackage main开头

以下命令将执行相同的操作:
cd $GOPATH/src/github.com/pred3/go_helloworld/helloworld
go intsall

10-07 19:19
查看更多