Bootstrapping: Why do you need to have an old version of Go working on your computer in order to install a new one?

xuanbao · · 207 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Currently, on attempting to install an up-to-date version of Go using the <a href="https://github.com/moovweb/gvm" rel="nofollow">GVM</a>, one is confronted with a bootstrapping problem. </p> <p>The GVM README.md explains it as follows: &#34;Go 1.5+ removed the C compilers from the toolchain and replaced them with one written in Go. Obviously, this creates a bootstrapping problem if you don&#39;t already have a working Go install. In order to compile Go 1.5+, make sure Go 1.4 is installed first.&#34; </p> <p>What&#39;s the reasoning behind this? </p> <p>Don&#39;t get me wrong, I&#39;m sure there is one. But if Mozilla were to announce that installing any post-50.0 version of Firefox required a working installation of a pre-50.0 version they&#39;d just get laughed at. Why doesn&#39;t this apply to Go? What software engineering advantages does it bring with it aside from a sense of recursive philosophical satisfaction that Go is written entirely in itself? Is this typical for other programming languages?</p> <p>EDIT: bootstrapping is only an issue if you want to compile Go 1.5+ from source, which is what GVM does. A pre-compiled version&#39;s available here: <a href="https://golang.org/dl/" rel="nofollow">https://golang.org/dl/</a> and installing it will get around the problem.</p> <hr/>**评论:**<br/><br/>radialrotate: <pre><blockquote> <p>Why do you need to have an old version of Go working on your computer in order to install a new one?</p> </blockquote> <p>You don&#39;t. You can download a pre-compiled version here: <a href="https://golang.org/dl/" rel="nofollow">https://golang.org/dl/</a></p> <p>You will probably be able to install it from your distro&#39;s package manager too, though they may not have the latest version.</p></pre>ambidextrousalpaca: <pre><p>So it&#39;s just a GVM thing then? Fair enough, my mistake.</p></pre>radialrotate: <pre><p>The GVM README is correct in saying that you need another copy of Go in order to <strong>compile</strong> Go 1.5+.</p> <p>But the majority of people are probably better off just downloading pre-compiled binaries.</p></pre>KEANO_: <pre><blockquote> <p>installing any post-50.0 version of Firefox required a working installation of a pre-50.0 version</p> </blockquote> <p>as far as i know firefox isn&#39;t a programming language</p> <p>non-troll part: removing the c parts = removing an external dependency<br/> instead of setting up two language environments you now just have to setup a single one </p> <p>especially on windows the go environment is much simpler to setup than c.<br/> cross compiling got a lot easier, too</p></pre>ambidextrousalpaca: <pre><p>Thanks for the answer. Wasn&#39;t trying to be disrespectful to Go. I just installed it and was a bit puzzled by the fact that I&#39;d never had to install multiple versions of a language to get one working before.</p></pre>KEANO_: <pre><p>No offense taken. Why are you installing Go via GVM in the first place? There is a perfectly fine binary installation available on <a href="https://golang.org/dl" rel="nofollow">https://golang.org/dl</a> You don&#39;t need a previous version of Go for this one.</p></pre>ambidextrousalpaca: <pre><p>I went with GVM because it seemed to offer an easy way of both updating the version on the computer and of running multiple versions of Go on the same machine, should that be necessary. Would you recommend just installing multiple binary versions instead?</p></pre>KEANO_: <pre><p>Actually I&#39;d recommend to just stick to the latest version. You won&#39;t run into problems as a beginner. Corporate projects may have restrictions to a specific version but you sould be fine with any 1.x.y as Go 1 has a <a href="https://golang.org/doc/go1compat" rel="nofollow">compatibility promise</a> </p></pre>ChristophBerger: <pre><p>This, plus the option to run go tools in a container or a VM, if the need for using an old version of Go ever arises.</p></pre>ambidextrousalpaca: <pre><p>That&#39;s awesome. But does it apply / will it always apply to things like 3rd party frameworks? E.g. to work with the Django web Framework version 1.9+ you need to have either Python 2.7+ (if using Python 2.x) or 3.4+ (if using Python 3.x), and there are also a load of Python related software packages that still aren&#39;t updated to work with Python 3.x: which is obviously a hassle. So, with Python most of the version annoyances come not from working with core Python but from using it with third-party software. Do you happen to know how has Go gotten around that problem?</p></pre>KEANO_: <pre><p>There is no Go 2.x yet and might never be, so currently you are good to go (no pun intended). Before thinking anymore about version incompatibilities, read about Donald Knuth&#39;s &#34;premature optimization is the root of all evil&#34; or the YAGNI principle</p></pre>ratatask: <pre><p>You installed it from source code then. There are ready built packages you can install, they do not require you to have an old version already installed.</p> <p>This isn&#39;t that uncommon for programming languages. If the tools for a programming language is written in that same language, you almost always need a previous version of those tools to build a new version.</p></pre>natefinch: <pre><p>This sounds like it&#39;s just a problem with GVM. You can install the binary version of any Go version without needing old versions. GVM must be compiling from source, which is the only time you need an old version of Go (compiling any version of go requires some external compiler, obviously... previously it was gcc, now it&#39;s go 1.4+).</p> <p>I&#39;m not super familiar with GVM, so it likely has a reason for compiling from source, but in general, you shouldn&#39;t need to.</p> <p>I don&#39;t know how new you are to Go, or what your needs are, but you might consider just installing the latest 1.7 version from golang.org directly. It&#39;s a lot simpler and keeps you using the same toolchain as most Go developers.</p></pre>ambidextrousalpaca: <pre><p>Thanks for the answer and advice. Am very new to Go, evidently: but impressed with it so far. I went with GVM on the basis that Googling questions about the best way of setting up Go seemed to indicate that 1. it was easy to do and worked well and 2. it offered a good way of managing different versions of the language on the same machine, should the need to do so arise. I&#39;ve had a load of problems resulting from needing to run different Python versions on the same machine in the past and wanted to nip such concerns in the bud with Go, if possible.</p></pre>alayton: <pre><p>Those concerns don&#39;t really exist with Go. You can run the latest version and everything should work - every Go release since 1.0 has been (and is promised to be in the future) 100% backwards compatible.</p></pre>ambidextrousalpaca: <pre><p>That&#39;s awesome. But does it apply / will it always apply to things like 3rd party frameworks? E.g. to work with the Django web Framework version 1.9+ you need to have either Python 2.7+ (if using Python 2.x) or 3.4+ (if using Python 3.x), and there are also a load of Python related software packages that still aren&#39;t updated to work with Python 3.x: which is obviously a hassle. So, with Python most of the version annoyances come not from working with core Python but from using it with third-party software. Do you happen to know how has Go gotten around that problem?</p></pre>ultra_brite: <pre><p>You don&#39;t need GVM. You&#39;re new to go, why do you need something totally unrelated to the Go toolchain at first place ? This isn&#39;t Ruby. Install the latest version of Go, you don&#39;t need multiple versions of Go. Start from the beginning instead of trying to complicate your life for nothing. Go has a distribution for your platform, then download it, period.</p></pre>natefinch: <pre><p>He&#39;s a newbie, and used to languages that make everything more difficult. A lot of people make the same assumptions coming into the language. </p></pre>ZenSwordArts: <pre><p>As others have answered your main question I want to leave something here for potential GVM users, because I think it is the easiest way to manage Go versions at the moment.</p> <p>You also can install a binary version with GVM. This should work with</p> <blockquote> <p>gvm install go1.7.4 --binary</p> </blockquote> <p>don&#39;t forget to set the version you are using with</p> <blockquote> <p>gvm use go1.7.4 --default</p> </blockquote> <p>Have fun with Go :)</p></pre>ambidextrousalpaca: <pre><p>Thanks. That&#39;s pretty much what I ended up doing. Worked fine.</p></pre>shovelpost: <pre><blockquote> <p>But if Mozilla were to announce that installing any post-50.0 version of Firefox required a working installation of a pre-50.0 version they&#39;d just get laughed at.</p> </blockquote> <p>Joke&#39;s on you.</p> <p><a href="https://groups.google.com/d/msg/mozilla.dev.platform/Gzwh1IbxvHE/tWkIMQWACQAJ" rel="nofollow">https://groups.google.com/d/msg/mozilla.dev.platform/Gzwh1IbxvHE/tWkIMQWACQAJ</a></p> <blockquote> <p>What software engineering advantages does it bring with</p> </blockquote> <p>On a more serious note, this question and probably much more can be answered by this talk: <a href="https://www.youtube.com/watch?v=cF1zJYkBW4A" rel="nofollow">https://www.youtube.com/watch?v=cF1zJYkBW4A</a></p></pre>ambidextrousalpaca: <pre><p>Thanks for the video link. </p></pre>kostix: <pre><p>Bootstrapping is a general problem for any programming language, just the usual environment you&#39;re working in makes you not spot this issue easily.</p> <p>Take your nearby GNU/Linux distro for instance: it most probably does ship a working C compiler (say, as part of GCC) as a package. But that package had to be actually compiled from the source--using a C compiler--to create that package.</p> <p>Where did <em>that</em> C compiler came from? Well, it was installed as a software package on the OS served as the build server. But note that that package itself had to be compiled (earlier) by another C compiler, and most probably its version was older than the version of the compiler it compiled. The progression can go on and on, you see.</p> <p>If we skip the whole progression and arrive at the edge case, the very first C compiler obviously wasn&#39;t written in C; it was written in the assembly language of whatever platform the C devs were using (PDP-7?) That way they have &#34;bootstrapped&#34; the first C compiler.</p> <p>After building a working C compiler and tweaking it so that it could compile itself, they made it self-bootstrapping--breaking out the requirement to have a working assembler for a particular platform.</p> <p>As you can see, Go is no different: at some point you have to have <em>something</em> already working to build <em>something else.</em> You take existence of a working C compiler for granted, but that&#39;s just your common sense getting in the way: C compilers have the same bootstrapping problem -- just less apparent ;-)</p> <p>Note that to have a working assembler for some old platform (I mean those olden days when men were men and wrote their own operating systems and compilers), that assembler&#39;s <em>executable</em> had to be input (whatever <em>that</em> required) directly using the opcodes of the target CPU.</p></pre>ambidextrousalpaca: <pre><p>Thank you. That is an awesome explanation of something that&#39;s mind-numblingly obvious once you&#39;ve had it explained to you.</p></pre>

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

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