0

I'm having a look at Go however i'm stuck at the very first hurdle. Whenever I run 'go install' I get the following error:

go install: no install location for directory /Users/jamie/Sites/gocode/src/jd/hello outside GOPATH

In all of the other posts I've seen about this it's usually because the user hasn't set a GOPATH or is trying to run go install outside of the GOPATH. I have set up my GOPATH and my code is in my GOPATH.

Here is my directory structure:

/Users/jamie/Sites/gocode
    /bin
    /src
        /jd
            /hello
                hello.go

I'm trying to run 'go install' from inside /Users/jamie/Sites/gocode/src/jd/hello. Here is my GOPATH:

$ echo $GOPATH
/Users/james/Sites/gocode

And finally here is hello.go:

package main

import "fmt"

func main() {
    fmt.Println("Hello there")
}

What am I doing wrong here?

Edit: go env:

$ go env
GOARCH="386"
GOBIN=""
GOCHAR="8"
GOEXE=""
GOHOSTARCH="386"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/james/Sites/gocode"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_386"
TERM="dumb"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m32 -pthread -fno-common"
CXX="g++"
CGO_ENABLED="1"

Thanks!

jd182
  • 3,180
  • 6
  • 21
  • 30
  • Your GOPATH cannot be the same as the Go installation. That is, if you compile Go and then try to use it's source directory for your source it will complain. – Dmitri Goldring Apr 18 '14 at 11:47
  • I don't think my GOPATH is the same as the installation dir. Go is installed in /usr/local/go - I used to OSX .pkg installer. – jd182 Apr 18 '14 at 12:02
  • `go env` will show you what your Go install think it's various paths are. It might be worth checking that and adding it to your question. – Dmitri Goldring Apr 18 '14 at 12:07
  • Thanks for the tip - I've done this now – jd182 Apr 18 '14 at 12:24
  • http://stackoverflow.com/questions/18149601/go-install-always-fails-no-install-directory-outside-gopath – Dmitri Goldring Apr 18 '14 at 12:29

1 Answers1

3

Your GOPATH="/Users/james/Sites/gocode" wheras your code is in /Users/jamie/Sites/gocode/src/jd/hello

So set GOPATH=/Users/jamie/Sites/gocode and hopefully it will work fine.

Nick Craig-Wood
  • 52,955
  • 12
  • 126
  • 132