go install: GOPATH之外的目录没有安装位置

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

go install: no install location for directory outside GOPATH

问题

我安装了Go,并将路径要求添加到了我的.bash_profile文件中:

  • export PATH=$PATH:/usr/local/go/bin
  • export GOPATH=$HOME/go

然后我设置了正确的文件夹:

go install: GOPATH之外的目录没有安装位置

我还创建了一个名为tire的项目。
main.go的内容非常简单:

package main

import "fmt"

func main() {
  fmt.Println("Hello, world!")
}

当我尝试运行go install时,总是会出现以下错误:

go install: no install location for directory /Users/Daryl/go/src/tire outside GOPATH

当我运行go env时,我得到以下结果:

GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/daryl/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
TERM="dumb"
CC="clang"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fno-common"
CXX="clang++"
CGO_ENABLED="1"

希望能得到帮助。

英文:

I installed the Go, then added path requirements to my .bash_profile:

  • export PATH=$PATH:/usr/local/go/bin
  • export GOPATH=$HOME/go

I then setup the correct folders:

go install: GOPATH之外的目录没有安装位置

I also created a projected called tire.
The contents for main.go are simply:

package main

import "fmt"

func main() {
  fmt.Println("Hello, world!")
}

I always get the following error when I try to run go install:

go install: no install location for directory /Users/Daryl/go/src/tire outside GOPATH

Here's what I get when I run go env:

GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/daryl/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
TERM="dumb"
CC="clang"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fno-common"
CXX="clang++"
CGO_ENABLED="1"

Any help would be appreciated.

答案1

得分: 73

当你运行go install命令时,Go会查找$GOBIN环境变量的路径。你需要将$GOBIN设置为$GOPATH/bin

$ export GOBIN=$GOPATH/bin

并且将$GOBIN添加到你的操作系统搜索路径中:

$ export PATH=$PATH:$GOBIN

这样就可以在不出现错误的情况下使用该命令。

英文:

When you run go install Go looks for $GOBIN env variable path. Either you need to set your $GOBIN to $GOPATH/bin

$ export GOBIN=$GOPATH/bin

and/or add $GOBIN to your OS search path

$ export PATH=$PATH:$GOBIN

To use the command without getting the error.

答案2

得分: 1

问题是正如James Henstridge所评论的那样,由于某种原因,我的用户目录名称大小写有问题。尽管目录本身是小写的,但我不得不将其改为大写。

这个命令有效:

GOPATH=/Users/Daryl/go

这个命令无效:

GOPATH=$HOME/go

然而,自从我从iMac迁移到rMBP后,设置Go时就没有任何问题,所以直到今天,我仍然不确定当时发生了什么,但是大写化解决了问题。

英文:

The problem was as James Henstridge commented, for some reason there was an issue with my user directory name case. Even though the directory is lowercase, I had to make it capitalized.

This worked:

GOPATH=/Users/Daryl/go

This didn't:

GOPATH=$HOME/go

However, since moving to a rMBP from my iMac, I had no problems whatsoever setting up Go, so, to this day, I'm not sure what was going on, but in that instance the capitalization fixed it.

答案3

得分: 0

我在Windows 10上遇到了同样的问题,
所以我设置了一个名为GOBIN的系统变量,
绝对值为F:\go\bin

然后运行go install main.go,一切都正常工作!

英文:

I had the same problem in Windows 10,

So I set a system variable named GOBIN
with absolute value F:\go\bin.

Then ran go install main.go and everything worked perfectly fine!

huangapple
  • 本文由 发表于 2014年10月1日 13:57:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/26134975.html
匿名

发表评论

匿名网友

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

确定