Does golang need to be installed on the server?

polaris · · 388 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>This might be somewhat of a noobish question, but I&#39;m just starting to learn about Go, and I&#39;m somewhat confused as to how Go apps are deployed on the server. Do I just put the executable on the server and run it? Or do I need something installed on the server?</p> <hr/>**评论:**<br/><br/>allhatenocattle: <pre><p>No, you only need Go installed where you will compile your application, then you can copy the resulting executable up to your server.</p></pre>fortytw2: <pre><p>Here&#39;s a really great talk about deploying Go, but short answer, no, you don&#39;t - <a href="https://www.youtube.com/watch?v=I-8PfC6dZe4">https://www.youtube.com/watch?v=I-8PfC6dZe4</a></p></pre>DanChm: <pre><p>Nice talk, thanks.</p></pre>gigatropolis: <pre><p>You don&#39;t need anything installed on the server to run the executable file.</p></pre>DanChm: <pre><p>Great, thanks for the answers! That clears things up a lot.</p></pre>kavehmz: <pre><p>You build </p> <pre><code>GOOS=linux GOARCH=amd64 go build myapp.go </code></pre> <p>Then you copy the result that is just one file to your server.</p> <p>Required libraries are statically linked.</p></pre>simplycycling: <pre><p>This is...this is absolutely incredible. This is a borderline gamechanger for me.</p></pre>Justinsaccount: <pre><blockquote> <p>Required libraries are statically linked.</p> </blockquote> <p>unless you are using something that uses cgo. Then you need</p> <pre><code>go build --ldflags &#39;-extldflags &#34;-static&#34;&#39; </code></pre></pre>0x4445565A: <pre><p>No you don&#39;t need to install Go on the server you deploy to, even if you use a bunch of 3rd party packages. This is because go compiles everything with static libraries.</p> <p>Normally when using dynamic binaries you might have to include a .so file for libraries but Go includes this with the build (Since it is static).</p> <p>This is the same reason why the binary for a simple hello world program is so huge(Roughly 2.2MB when I just built it).</p></pre>: <pre><p>[deleted]</p></pre>DanChm: <pre><p>Doesn&#39;t help much.</p></pre>: <pre><p>[deleted]</p></pre>xrstf: <pre><p>100s of answers that tell you how to manage Heroku, AWS, App Engine, Docker, Clouds, Swarms and whatnot, most of which hide the actual process of compiling and just seeing and &#34;playing&#34; with your resulting binary.</p></pre>dmikalova: <pre><p>If you don&#39;t want to help then don&#39;t try. All you have to say is &#34;the binary that go build produces is all that&#39;s needed to run.&#34;</p></pre>

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

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