GOPATH和GOBIN在Fedora中设置并导出,但仍然无法安装程序。

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

GOPATH and GOBIN set and exported in Fedora but still not installing program

问题

我在Fedora 21的笔记本上安装了GO,并设置了GOPATH和GOBIN,但由于某种原因,它不允许我安装我的GO程序。

我应该做什么才能让它工作?

--编辑--

按照下面所述的命令也会出错。

然而,我在尝试安装的go文件开头没有package main。一旦我将其更改为package main,它就可以工作了。不过,我不确定为什么不能使用其他包名。

英文:

I have GO installed on a Fedora 21 laptop and I setup GOPATH and GOBIN, but it for some reason is not letting me install my go Programs.

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"

What else should I be doing to get this to work?

--EDIT--

Issuing the following command as stated below also gave errors.

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)

However, I did not have package main at the beginning of the go file I was trying to install. Once I changed it to package main it worked. I'm not sure why I couldn't use a different package name though.

答案1

得分: 2

go install 命令需要一个包作为参数(详细解释请参见包列表的描述)。在你的情况下,应该是:

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.go 文件以 package main 开头。

以下命令也可以实现相同的效果:

cd $GOPATH/src/github.com/pred3/go_helloworld/helloworld
go intsall
英文:

go install expects a package as argument (see Description of package lists for more detailed explanation). In your case it probably should be

go install github.com/pred3/go_helloworld/helloworld

assuming that $GOPATH/src/github.com/pred3/go_helloworld/helloworld directory exists and $GOPATH/src/github.com/pred3/go_helloworld/helloworld/helloworld.go starts with package main

The following commands will do the same:

cd $GOPATH/src/github.com/pred3/go_helloworld/helloworld
go intsall

huangapple
  • 本文由 发表于 2015年8月5日 09:52:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/31822170.html
匿名

发表评论

匿名网友

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

确定