What is the purpose of setting GOPATH?

blov · · 731 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>When I go through tutorials the first step is usually to set GOPATH, for example</p> <pre><code>$ export GOPATH=$HOME/project1 </code></pre> <p>however, I have to do this for every new project/tutorial, so I am curious, is this setting necessary? Is there a more easier way of doing this?</p> <hr/>**评论:**<br/><br/>Fwippy: <pre><p>The easiest thing to do is to set <code>GOPATH</code> exactly once; and leave it at that setting forever. All your projects will live under that path (<code>$GOPATH/src/yourfavoritereposite.org/you/project1/</code>), and everything will Just Work.</p></pre>mwholt: <pre><p>Just use one GOPATH for everything, once it&#39;s set you don&#39;t have to worry about it. I added it to my .bashrc file. <a href="http://mwholt.blogspot.com/2014/02/why-i-use-just-one-gopath.html" rel="nofollow">http://mwholt.blogspot.com/2014/02/why-i-use-just-one-gopath.html</a></p></pre>your_time_to_shine: <pre><p>I use this in my ~/.zshrc or ~/.bashrc or system-wide in /etc/profile on a new user, or new computer. I don&#39;t mess with it ever: <code>export GOPATH=$HOME/work # set gopath</code></p> <p><code>export PATH=$PATH:$GOPATH/bin # put go programs in your path</code></p> <p>Now I test with something simple, and useful: sift, a fast grep alternative.</p> <p><code> go get -v -u github.com/svent/sift testing echo $PATH | sift $GOPATH </code></p> <p>New projects are in namespaces, <code>cd $GOPATH/src/github.com</code> and <code>mkdir $USER</code> then and you may create a new folder for a new project. If you were to enter the project directory and type <code>go build</code> you will see a new binary program in the source directory. But if you type <code>go install</code> you will find the new program in your $PATH !</p></pre>upboatact: <pre><p><a href="http://gowithconfidence.tumblr.com/post/118493925546/getting-started-with-go-workspaces" rel="nofollow">http://gowithconfidence.tumblr.com/post/118493925546/getting-started-with-go-workspaces</a> is always a nice read about the whys</p></pre>0x004a: <pre><p>It&#39;s a shame the tutorials don&#39;t say <strong>if not set, then set</strong>. Think of it as home for <strong>Go</strong>.</p></pre>thewhitetulip: <pre><p>Set one global GOPATH and use sub directories for each project rather than setting a new GOPATH for each project</p></pre>lacion: <pre><p>using direnv make having a more granular project organisation a breeze. </p> <p>you can have several gopath and have it autoselected once you cd into the a directory.</p></pre>GoTheFuckToBed: <pre><p>pure evil intention of the developers</p></pre>

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

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