<p>I just set $GOPATH to be ~/gocode, and now I just used <code>gvm</code> and go path seems to be changed to <code>~/.gvm/pkgsets/go1.6/global</code>. Now I'm confused, shouldn't GOPATH be set to where all the go code is? Why did gvm change it?</p>
<p>More generally, how does GOPATH work in relation to npm or virtualenv? I don't really get it :/</p>
<hr/>**评论:**<br/><br/>SocalNick: <pre><p>Not familiar with gvm, but it sounds a lot like Ruby rvm. It seems to want you to make sets of packages in addition to maintaining several versions of Go. Do you really need several versions of Go?</p>
<p>The brief history of Go package management is the go tool chain could download dependencies for you, but only to your GOPATH, so projects would share the same version. Dependency hell brought all sorts of community solutions. </p>
<p>As of 1.5, Go supports a vendor directory that will be preferred location to resolve imports, falling back to GOPATH. There are several tools that work with the vendor directory:</p>
<p><a href="https://github.com/golang/go/wiki/PackageManagementTools" rel="nofollow">https://github.com/golang/go/wiki/PackageManagementTools</a></p></pre>sjalfurstaralfur: <pre><p>Yeah, I guess you're right, a lot of comments here suggests that having multiple versions of go is not necessary and gvm only adds more complexity.</p></pre>The_Sly_Marbo: <pre><p>There's a load of good info <a href="https://golang.org/cmd/go/#hdr-GOPATH_environment_variable" rel="nofollow">here</a>, which you can also get with <code>go help gopath</code>. My setup is <code>GOPATH=$HOME/dev/go</code> and all my code is then in <code>$GOPATH/src/</code>.</p></pre>sjalfurstaralfur: <pre><p>I'm wondering why did <code>gvm</code> set my gopath to be <code>~/.gvm/pkgsets/go1.6/global</code>?</p></pre>The_Sly_Marbo: <pre><p>I haven't used gvm, but my guess is it's doing magic to handle different Go versions. Personally I would avoid it; you should be fine with just the Go tool.</p></pre>giulioungaretti: <pre><p>GOPATH and virtualenv are to different things, and GVM is trying to make GOPATH to mimic virtualenv.</p>
<p>The go tool chain will search for packages in $GOPATH/ , unless your project is vendoring dependencies and you are using go 1.6. </p>
<p>GVM is actually trying to work like virtualenv IMHO.</p>
<p>Not an horrible solution, probably not the best. But to each its own :D </p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传