无法在OSX上使用’go install’命令。

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

Can't get 'go install' to work on OSX

问题

我正在查看Go,但是我在第一个障碍上遇到了困难。每当我运行'go install'时,我都会收到以下错误信息:

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

在我看到的所有其他帖子中,通常是因为用户没有设置GOPATH或者尝试在GOPATH之外运行go install。我已经设置了我的GOPATH,并且我的代码在GOPATH中。

这是我的目录结构:

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

我正在尝试从/Users/jamie/Sites/gocode/src/jd/hello内部运行'go install'。这是我的GOPATH:

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

最后,这是hello.go的内容:

package main

import "fmt"

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

我在这里做错了什么?

编辑: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"

谢谢!

英文:

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!

答案1

得分: 3

你的GOPATH是"/Users/james/Sites/gocode",而你的代码在"/Users/jamie/Sites/gocode/src/jd/hello"目录下。

所以将GOPATH设置为"/Users/jamie/Sites/gocode",希望能够正常工作。

英文:

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.

huangapple
  • 本文由 发表于 2014年4月18日 19:31:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/23153249.html
匿名

发表评论

匿名网友

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

确定