Setting Up Go Dev Env for Multiple Projects

agolangf · · 835 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hello friends, I&#39;m the new member of the gang. I have questions. I&#39;ve just started learning golang. As I understand I have to set up stuff for GOPATH and PATH... I&#39;m confused about that. I want to set up these things for just once and ready to code. I like autocomplete and want to use GoSublime plugin for that.</p> <p>I installed golang with Homebrew. &#34;which go&#34; outputs &#34; /usr/local/bin/go &#34; </p> <p>Question 1 : for better working space I created /Developer/goprojects . Do I have to set my path stuff for only this directory even I have multiple projects in that folder ?</p> <p>Question 2: I want to use Sublime&#39;s GoSublime plugin for autocomplete and other stuff. Do i need to install <a href="https://github.com/nsf/gocode" rel="nofollow">https://github.com/nsf/gocode</a> this package in my workspace ?</p> <p>Question 3: How do you manage your workspace for golang projects ?</p> <p>Regards.</p> <hr/>**评论:**<br/><br/>Luett_un_Luett: <pre><blockquote> <p>Question 1 : for better working space I created /Developer/goprojects . Do I have to set my path stuff for only this directory even I have multiple projects in that folder ?</p> </blockquote> <p>Set GOPATH=/Developer/goprojects and PATH=${PATH}:${GOPATH}/bin</p> <blockquote> <p>Question 3: How do you manage your workspace for golang projects ?</p> </blockquote> <p>I have one GOPATH (&#34;/Developer/goprojects&#34; in your case). What is your question exactly? You have your source repositories under &#34;src&#34; (e.g. &#34;${GOPATH}/src/github.com/&lt;user&gt;/&lt;project&gt;/**&#34;). There is nothing more to manage!? </p></pre>TheMerovius: <pre><p>Unless you use packages that have the diamond dependency problem (i.e. A depends of B and C, which both depend on D, but on different API versions), which I never had so far, it is not a problem to have only one gopath for everything. Even if you have this problem, you can use vendoring to resolve it transparently to B and C.</p> <p>So. Just have one gopath for everything. It&#39;s fine.</p> <p>A lot of people btw actually set <code>GOPATH=$HOME</code>. And already have `~/bin~ in their path anyway.</p></pre>jahayhurst: <pre><p>iirc, installing go through homebrew is out of date. I would recommend double checking that - tbh it&#39;s not that hard to install go and I just do it by hand - even when I had homebrew.</p> <p>You should modify your $PATH to include the location for the go system binaries (if they are in <code>/usr/local/bin</code> make sure that&#39;s there) and maybe set <code>$GOROOT</code> if needed?</p> <p>You should probably include <code>$GOPATH/bin</code> - your <code>bin</code> folder within your <code>$PATH</code>, so you can run stuff easier.</p> <p>Since you&#39;re using sublime on OSX, you&#39;re also going to want a package called <code>Fix Mac Path</code> - sublime on a mac is usually launched by launchctl, which doesn&#39;t give you $GOPATH and $GOROOT and $PATH that you just set, so you can set those with that.</p> <p>And, RE #2, you shouldn&#39;t need gocode for Sublime (that&#39;s for vim and emacs?), but the auto completion for sublime is only based on other patterns that appear in your open buffers (from what I can tell).</p></pre>lacion: <pre><p>why is installing go with homebrew out of date? </p> <p>i just did it a few days ago and i got 1.5.1, could you elaborate on why its better to do it by hand?</p></pre>jahayhurst: <pre><p>If you&#39;ve got 1.5.1 from Homebrew, it&#39;s up to date.</p> <p>I remember back when 1.4 released, Homebrew was still installing 1.3 iirc. And I want to say a bit before 1.5 hit (a couple of months?) it was still running 1.3. My experience has been that it&#39;s out of date - possibly not the case.</p> <p>That aside, I install it by hand because it&#39;s as simple as:</p> <pre><code>curl https://storage.googleapis.com/golang/go1.5.1.darwin-amd64.tar.gz|tar xf -C /usr/local </code></pre> <p>And then creating the required directories, and setting env variables - stuff that comes from my dotfiles. Clicking through a pkg install requires me to do stuff, Homebrew requires Homebrew (which I recently moved away from), and I&#39;d rather just automate it independent of everything else.</p></pre>philsturgeon: <pre><p>Take a look at <a href="http://getgb.io" rel="nofollow">http://getgb.io</a></p></pre>

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

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