dongsutao8921
2015-08-05 01:52
浏览 11
已采纳

在Fedora中设置并导出了GOPATH和GOBIN,但仍未安装程序

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.

图片转代码服务由CSDN问答提供 功能建议

我在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:命令行上没有列出.go文件的安装位置(未设置GOBIN  )
pred @ computer01 [20:03:32]〜/ Documents / GO 
 $ go env 
GOARCH =“ amd64” 
GOBIN =“ / home / pred / Documents / GO / bin” 
GOCHAR =“ 6” \  nGOEXE = “” 
GOHOSTARCH = “AMD64” 
GOHOSTOS = “LINUX” 
GOOS = “LINUX” 
GOPATH = “/家/预解码/文件/ 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 
 $转到安装src / github.com / pred3 / go_helloworld / helloworld 
无法加载包:包src / github.com / predatorian3 / go_helloworld  / helloworld:在以下任何位置都找不到软件包“ src / github.com / pred3 / go_helloworld / helloworld”:
 /usr/lib/golang/src/src/github.com/pred3/go_helloworld/helloworld(来自$ GOROOT)  
 /home/pred/Documents/GO/src/src/github.com/pred3/go_helloworld/helloworld(来自$ GOPATH)
   
 
 

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

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • draxu26480 2015-08-05 02:58
    已采纳

    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
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题