Totally stumped - go get failing with "go install: no install location for directory" error

xuanbao · · 675 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I have a build job which git clones my source tree to a directory, sets GOPATH to that directory, and then runs go get.</p> <p>Then I get the above error. I&#39;ve tried cloning to a src directory. No idea what&#39;s wrong. . . also, this worked just fine the other day.</p> <p>I know this is something stupid.</p> <hr/>**评论:**<br/><br/>ChristophBerger: <pre><blockquote> <p>I have a build job which git clones my source tree to a directory, sets GOPATH to that directory, and then runs go get.</p> </blockquote> <p>I don&#39;t understand this part. If you use <code>go get</code>, you do not need to do <code>git clone</code> before, because this is what <code>go get</code> already does underneath. And if you use <code>git clone</code>, you need no <code>go get</code> anymore but can call <code>go install</code> directly.</p> <p>Regarding the error message, the Go project that you try to compile must reside under $GOPATH like so:</p> <pre><code>$GOPATH/ bin/ pkg/ src/ your-go-project/ main.go ... </code></pre> <ul> <li>If you <code>go get</code> from a remote repository, then <code>go get</code> should do the right thing already. </li> <li>If you do <code>git clone</code>, ensure the target dir is beneath <code>$GOPATH/src</code>. </li> </ul></pre>tech_tuna: <pre><p>Sorry, to clarify. My code lives in a private repo, I go a fresh git clone to pull it down. I set GOPATH=&lt;root of repo checkout&gt;. I have files in that root directory as well. So it looks like this:</p> <pre><code>$GOPATH/ main.go + other go files bin/ pkg/ src/ dependencies/ </code></pre></pre>ChristophBerger: <pre><p>You cannot have Go files directly in <code>$GOPATH</code>. All source files have to reside in some subdirectory of <code>$GOPATH/src/</code>. Usually you create a project directory there and put all your Go files into it. (You can use subdirectories.)</p> <p>More details <a href="https://golang.org/doc/code.html#Workspaces" rel="nofollow">here</a>.</p></pre>chmikes: <pre><p>I think you also have to define the GOBIN environment variable to where you want the binaries generated by go install to be stored. It may be in a different place than your go work space. </p></pre>goomba_gibbon: <pre><p>I&#39;m not sure this is true. Isn&#39;t the convention to add the default bin directory to your path?</p> <pre><code>export PATH=$PATH:$(go env GOPATH)/bin </code></pre> <p>EDIT: src <a href="https://golang.org/doc/code.html" rel="nofollow">https://golang.org/doc/code.html</a></p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

675 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传