Search code examples
gofedorafedora-21

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


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.


Solution

  • 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