godep: exec: “go”: 在 $PATH 中找不到可执行文件

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

godep: exec: "go": executable file not found in $PATH

问题

我正在尝试在Heroku上部署我的服务器,但在使用godep的步骤上遇到了问题。我在GO方面花了一些时间,过去两天我一直在寻找解决这个问题的方法,实际上这是一个常见的问题,但我无法找出解决办法,也许我做错了一些基本的事情。

我使用的操作系统是OS X 10.11.2。
我的GOPATH是/Users/denis/Programming/Golang。
我的PATH是$GOPATH/bin。
我试图在$GOPATH/src/backend中使用godep来管理我的项目。

在我的PATH中,我有一个可执行的godep文件(不是.go文件)。

我的工作目录的整体结构如下:

/Golang/
.bin/
godep //可执行文件
.pkg/
.darwin-amd64/
//其他文件夹
.src/
.github.com/
.backend/
//其他文件夹

英文:

I trying to deploy my server on heroku and I stuck on step where I should use godep, I spent little time with GO, last two days I had looking how to solve this issue, actually it's a popular issue, but I can't figure out, maybe I did something fundamentally wrong.

I have OS X 10.11.2<br>
My GOPATH - Users/denis/Programming/Golang<br>
My PATH - $GOPATH/bin<br>
I trying to use godep to my project which is placed in $GOPATH/src/backend

in my PATH I have an executable godep file(not .go).

Whole structure of my workplace.

/Golang/
     .bin/
        godep //executable file
     .pkg/
        .darwin-amd64/
             .//other folders/
     .src/
         .github.com/
         .backend/
         .//other folders// 

答案1

得分: 16

首先,这是输出的结果:

$ echo $PATH

它应该至少包含两个目录,用于运行Go项目:

  • /path/to/go/installation/bin(例如/usr/local/go/bin
  • /path/to/your/GOPATH/bin(例如/Users/denis/Programming/Golang/bin

如果你按照Go的安装设置进行安装,你的Go安装应该已经在PATH中。

https://golang.org/doc/install

由于你提到了/Users/denis/Programming/Golang,其中U是大写的,我假设你使用的是OS X。

在OS X上,如果你使用默认安装,你可以用一个简单的命令测试Go是否在你的PATH中:

$ echo $PATH | grep --color=auto "/usr/local/go/bin"

它应该打印出你的整个$PATH并突出显示你已经正确设置了。这是因为上面URL中的OS X GoLang安装程序应该已经修改了你的PATH,包括:

  • /usr/local/go/bin
  • 或者更具体地说,可能是export PATH="$PATH:/usr/local/go/bin"

如果你有一些自定义的.bashrc和/或.profile文件,那么很可能你的PATH没有正确设置。你可以通过执行以下操作来测试:

$ export PATH="$PATH:/usr/local/go/bin"
$ export PATH="$PATH:/Users/denis/Programming/Golang/bin"
$ godep go build

如果现在可以工作了,那么你的PATH在.bashrc/.profile文件中没有正确设置。这是一个不同类型的问题,可以有1000种不同的设置方式,你可能需要自己解决(或者提一个新的SO问题)。

如果这解决了你的问题,那么你需要按照godep的说明从项目的根目录运行godep

$ cd $GOPATH/src/backend/
$ godep save
$ git add Godeps/

godep会在Go项目的根目录创建一个Godeps目录。如果你有多个Go项目/多个可执行文件,那么你需要在每个运行时的根目录上运行godep save

换句话说,对于每个你运行go build的可执行文件,你需要在每个目录中运行godep save

此外,一旦你转向godep,你还希望在构建和测试中使用它:

$ godep go build
$ godep go test
...等等

如果这不是问题(你按照上述说明运行它),那么请在问题中提供更多具体信息,例如你正在运行的godep命令是什么,以及该目录结构是什么样的(包括带有package mainfunc main()函数的文件名)

英文:

First, what is the output of this:

$ echo $PATH

It should, at a minimal to run Go projects, have TWO directories in it for:

  • /path/to/go/installation/bin (e.g. /usr/local/go/bin)
  • /path/to/your/GOPATH/bin (e.g. /Users/denis/Programming/Golang/bin)

Your go's installation should be in your PATH already if you followed the Go installation setup.

https://golang.org/doc/install

Since you posted /Users/denis/Programming/Golang, with the capital U, I am going to assume that you are on OS X going forward...

In OS X, and if you used the default install, you can test for Go in your PATH with a simple command:

$ echo $PATH | grep --color=auto &quot;/usr/local/go/bin&quot;

It should print our your entire $PATH and highlight that you have things setup properly. This is because the OS X GoLang installer in the URL above should have modified your PATH to include:

  • /usr/local/go/bin
  • or more specifically, it may be export PATH=&quot;$PATH:/usr/local/go/bin&quot;

If you have some custom .bashrc and/or .profile files, then most likely your PATH isn't being setup correctly. You can test this by doing this:

$ export PATH=&quot;$PATH:/usr/local/go/bin&quot;
$ export PATH=&quot;$PATH:/Users/denis/Programming/Golang/bin&quot;
$ godep go build

If it works now, then your PATH isn't setup properly in your .bashrc/.profile files. That's a different kind of question and can be setup a 1000 different ways and you may need to figure it out (or another SO question).

If that resolves your issue, then you need to follow the godep directions to run godep from your project's root:

$ cd $GOPATH/src/backend/
$ godep save
$ git add Godeps/

godep creates a Godeps directory in the root of the Go project. If you have multiple Go projects/multiple executables, then you need to run godep save on each root of the runtime.

IOW, for each executable you run go build for, you need to run godep save in each directory.

Also, once you move to godep, you want to use it for your build and testing as well:

$ godep go build
$ godep go test
...etc

If that's not the problem (you are running it as stated above), then please update your question with more specifics such as what godep command you are running, where, and what that directorys structure looks like for the root of that project (including the filename with package main and your func main() function).

huangapple
  • 本文由 发表于 2016年4月1日 02:59:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/36341505.html
匿名

发表评论

匿名网友

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

确定