blob: 45c5bbbf48be4c430ddf432920f206a8b0c53b64 [file] [log] [blame]
Colin Cross7bb052a2015-02-03 12:59:37 -08001<!--{
2 "Title": "Installing Go from source",
3 "Path": "/doc/install/source"
4}-->
5
6<h2 id="introduction">Introduction</h2>
7
8<p>
9Go is an open source project, distributed under a
10<a href="/LICENSE">BSD-style license</a>.
11This document explains how to check out the sources,
12build them on your own machine, and run them.
13</p>
14
15<p>
16Most users don't need to do this, and will instead install
17from precompiled binary packages as described in
18<a href="/doc/install">Getting Started</a>,
19a much simpler process.
20If you want to help develop what goes into those precompiled
21packages, though, read on.
22</p>
23
24<div class="detail">
25
26<p>
27There are two official Go compiler tool chains.
28This document focuses on the <code>gc</code> Go
Dan Willemsen6ff23252015-09-15 13:49:18 -070029compiler and tools.
Colin Cross7bb052a2015-02-03 12:59:37 -080030For information on how to work on <code>gccgo</code>, a more traditional
31compiler using the GCC back end, see
32<a href="/doc/install/gccgo">Setting up and using gccgo</a>.
33</p>
34
35<p>
Dan Willemsenbbdf6642017-01-13 22:57:23 -080036The Go compilers support eight instruction sets.
Colin Cross7bb052a2015-02-03 12:59:37 -080037There are important differences in the quality of the compilers for the different
38architectures.
39</p>
40
41<dl>
42<dt>
Dan Willemsen6ff23252015-09-15 13:49:18 -070043 <code>amd64</code> (also known as <code>x86-64</code>)
Colin Cross7bb052a2015-02-03 12:59:37 -080044</dt>
45<dd>
Dan Willemsenbbdf6642017-01-13 22:57:23 -080046 A mature implementation.
Colin Cross7bb052a2015-02-03 12:59:37 -080047</dd>
48<dt>
Dan Willemsen6ff23252015-09-15 13:49:18 -070049 <code>386</code> (<code>x86</code> or <code>x86-32</code>)
Colin Cross7bb052a2015-02-03 12:59:37 -080050</dt>
51<dd>
Dan Willemsenbbdf6642017-01-13 22:57:23 -080052 Comparable to the <code>amd64</code> port.
Colin Cross7bb052a2015-02-03 12:59:37 -080053</dd>
54<dt>
Dan Willemsen6ff23252015-09-15 13:49:18 -070055 <code>arm</code> (<code>ARM</code>)
Colin Cross7bb052a2015-02-03 12:59:37 -080056</dt>
57<dd>
Dan Willemsenbbdf6642017-01-13 22:57:23 -080058 Supports Linux, FreeBSD, NetBSD, OpenBSD and Darwin binaries. Less widely used than the other ports.
Dan Willemsen6ff23252015-09-15 13:49:18 -070059</dd>
60<dt>
61 <code>arm64</code> (<code>AArch64</code>)
62</dt>
63<dd>
Dan Willemsen0c157092016-07-08 13:57:52 -070064 Supports Linux and Darwin binaries. New in 1.5 and not as well exercised as other ports.
Dan Willemsen6ff23252015-09-15 13:49:18 -070065</dd>
66<dt>
67 <code>ppc64, ppc64le</code> (64-bit PowerPC big- and little-endian)
68</dt>
69<dd>
Dan Willemsen0c157092016-07-08 13:57:52 -070070 Supports Linux binaries. New in 1.5 and not as well exercised as other ports.
71</dd>
72<dt>
Dan Willemsenbbdf6642017-01-13 22:57:23 -080073 <code>mips, mipsle</code> (32-bit MIPS big- and little-endian)
74</dt>
75<dd>
76 Supports Linux binaries. New in 1.8 and not as well exercised as other ports.
77</dd>
78<dt>
Dan Willemsen0c157092016-07-08 13:57:52 -070079 <code>mips64, mips64le</code> (64-bit MIPS big- and little-endian)
80</dt>
81<dd>
82 Supports Linux binaries. New in 1.6 and not as well exercised as other ports.
83</dd>
84<dt>
85 <code>s390x</code> (IBM System z)
86</dt>
87<dd>
88 Supports Linux binaries. New in 1.7 and not as well exercised as other ports.
Colin Cross7bb052a2015-02-03 12:59:37 -080089</dd>
90</dl>
91
92<p>
93Except for things like low-level operating system interface code, the run-time
94support is the same in all ports and includes a mark-and-sweep garbage
95collector, efficient array and string slicing, and support for efficient
96goroutines, such as stacks that grow and shrink on demand.
97</p>
98
99<p>
100The compilers can target the DragonFly BSD, FreeBSD, Linux, NetBSD, OpenBSD,
101OS X (Darwin), Plan 9, Solaris and Windows operating systems.
102The full set of supported combinations is listed in the discussion of
103<a href="#environment">environment variables</a> below.
104</p>
105
Dan Willemsen0c157092016-07-08 13:57:52 -0700106<p>
107See the main installation page for the <a href="/doc/install#requirements">overall system requirements</a>.
108The following additional constraints apply to systems that can be built only from source:
109</p>
110
111<ul>
112<li>For Linux on PowerPC 64-bit, the minimum supported kernel version is 2.6.37, meaning that
113Go does not support CentOS 6 on these systems.
114</li>
115</ul>
116
Colin Cross7bb052a2015-02-03 12:59:37 -0800117</div>
118
Dan Willemsen6ff23252015-09-15 13:49:18 -0700119<h2 id="go14">Install Go compiler binaries</h2>
Colin Cross7bb052a2015-02-03 12:59:37 -0800120
121<p>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700122The Go tool chain is written in Go. To build it, you need a Go compiler installed.
123The scripts that do the initial build of the tools look for an existing Go tool
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800124chain in <code>$GOROOT_BOOTSTRAP</code>.
125If unset, the default value of <code>GOROOT_BOOTSTRAP</code>
126is <code>$HOME/go1.4</code>.
Colin Cross7bb052a2015-02-03 12:59:37 -0800127</p>
128
Dan Willemsen6ff23252015-09-15 13:49:18 -0700129<p>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800130There are many options for the bootstrap tool chain.
131After obtaining one, set <code>GOROOT_BOOTSTRAP</code> to the
132directory containing the unpacked tree.
133For example, <code>$GOROOT_BOOTSTRAP/bin/go</code> should be
134the <code>go</code> command binary for the bootstrap tool chain.
Dan Willemsen6ff23252015-09-15 13:49:18 -0700135</p>
136
137<p>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800138To use a binary release as a bootstrap tool chain, see
139<a href="/dl/">the downloads page</a> or use any other
140packaged Go distribution.
Dan Willemsen6ff23252015-09-15 13:49:18 -0700141</p>
142
143<p>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800144To build a bootstrap tool chain from source, use
145either the git branch <code>release-branch.go1.4</code> or
146<a href="https://storage.googleapis.com/golang/go1.4-bootstrap-20161024.tar.gz">go1.4-bootstrap-20161024.tar.gz</a>,
147which contains the Go 1.4 source code plus accumulated fixes
148to keep the tools running on newer operating systems.
149(Go 1.4 was the last distribution in which the tool chain was written in C.)
Dan Willemsena727cd02017-02-21 17:11:40 -0800150After unpacking the Go 1.4 source, <code>cd</code> to
151the <code>src</code> subdirectory and run <code>make.bash</code> (or,
152on Windows, <code>make.bat</code>).
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800153</p>
154
155<p>
156To cross-compile a bootstrap tool chain from source, which is
157necessary on systems Go 1.4 did not target (for
158example, <code>linux/ppc64le</code>), install Go on a different system
159and run <a href="/src/bootstrap.bash">bootstrap.bash</a>.
Dan Willemsen6ff23252015-09-15 13:49:18 -0700160</p>
161
162<p>
163When run as (for example)
164</p>
165
166<pre>
167$ GOOS=linux GOARCH=ppc64 ./bootstrap.bash
168</pre>
169
170<p>
171<code>bootstrap.bash</code> cross-compiles a toolchain for that <code>GOOS/GOARCH</code>
172combination, leaving the resulting tree in <code>../../go-${GOOS}-${GOARCH}-bootstrap</code>.
173That tree can be copied to a machine of the given target type
174and used as <code>GOROOT_BOOTSTRAP</code> to bootstrap a local build.
175</p>
176
177<p>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800178To use gccgo as the bootstrap toolchain, you need to arrange
179for <code>$GOROOT_BOOTSTRAP/bin/go</code> to be the go tool that comes
180as part of gccgo 5. For example on Ubuntu Vivid:
Dan Willemsen6ff23252015-09-15 13:49:18 -0700181</p>
182
183<pre>
184$ sudo apt-get install gccgo-5
185$ sudo update-alternatives --set go /usr/bin/go-5
186$ GOROOT_BOOTSTRAP=/usr ./make.bash
187</pre>
188
Colin Cross7bb052a2015-02-03 12:59:37 -0800189<h2 id="git">Install Git, if needed</h2>
190
191<p>
192To perform the next step you must have Git installed. (Check that you
193have a <code>git</code> command before proceeding.)
194</p>
195
196<p>
197If you do not have a working Git installation,
198follow the instructions on the
199<a href="http://git-scm.com/downloads">Git downloads</a> page.
200</p>
201
Dan Willemsen0c157092016-07-08 13:57:52 -0700202<h2 id="ccompiler">(Optional) Install a C compiler</h2>
203
204<p>
205To build a Go installation
206with <code><a href="/cmd/cgo">cgo</a></code> support, which permits Go
207programs to import C libraries, a C compiler such as <code>gcc</code>
208or <code>clang</code> must be installed first. Do this using whatever
209installation method is standard on the system.
210</p>
211
212<p>
213To build without <code>cgo</code>, set the environment variable
214<code>CGO_ENABLED=0</code> before running <code>all.bash</code> or
215<code>make.bash</code>.
216</p>
Colin Cross7bb052a2015-02-03 12:59:37 -0800217
218<h2 id="fetch">Fetch the repository</h2>
219
220<p>Go will install to a directory named <code>go</code>.
221Change to the directory that will be its parent
222and make sure the <code>go</code> directory does not exist.
Dan Willemsen0c157092016-07-08 13:57:52 -0700223Then clone the repository and check out the latest release tag
Dan Willemsena727cd02017-02-21 17:11:40 -0800224(<code class="versionTag">go1.8</code>, for example):</p>
Colin Cross7bb052a2015-02-03 12:59:37 -0800225
226<pre>
227$ git clone https://go.googlesource.com/go
228$ cd go
Dan Willemsen0c157092016-07-08 13:57:52 -0700229$ git checkout <span class="versionTag"><i>&lt;tag&gt;</i></span>
Colin Cross7bb052a2015-02-03 12:59:37 -0800230</pre>
231
Dan Willemsen0c157092016-07-08 13:57:52 -0700232<p class="whereTag">
233Where <code>&lt;tag&gt;</code> is the version string of the release.
234</p>
235
Colin Cross7bb052a2015-02-03 12:59:37 -0800236<h2 id="head">(Optional) Switch to the master branch</h2>
237
238<p>If you intend to modify the go source code, and
239<a href="/doc/contribute.html">contribute your changes</a>
240to the project, then move your repository
241off the release branch, and onto the master (development) branch.
242Otherwise, skip this step.</p>
243
244<pre>
245$ git checkout master
246</pre>
247
248<h2 id="install">Install Go</h2>
249
250<p>
251To build the Go distribution, run
252</p>
253
254<pre>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700255$ cd src
Colin Cross7bb052a2015-02-03 12:59:37 -0800256$ ./all.bash
257</pre>
258
259<p>
260(To build under Windows use <code>all.bat</code>.)
261</p>
262
263<p>
264If all goes well, it will finish by printing output like:
265</p>
266
267<pre>
268ALL TESTS PASSED
269
270---
271Installed Go for linux/amd64 in /home/you/go.
272Installed commands in /home/you/go/bin.
273*** You need to add /home/you/go/bin to your $PATH. ***
274</pre>
275
276<p>
277where the details on the last few lines reflect the operating system,
278architecture, and root directory used during the install.
279</p>
280
281<div class="detail">
282<p>
283For more information about ways to control the build, see the discussion of
284<a href="#environment">environment variables</a> below.
285<code>all.bash</code> (or <code>all.bat</code>) runs important tests for Go,
286which can take more time than simply building Go. If you do not want to run
287the test suite use <code>make.bash</code> (or <code>make.bat</code>)
288instead.
289</p>
290</div>
291
292
293<h2 id="testing">Testing your installation</h2>
294
295<p>
296Check that Go is installed correctly by building a simple program.
297</p>
298
299<p>
300Create a file named <code>hello.go</code> and put the following program in it:
301</p>
302
303<pre>
304package main
305
306import "fmt"
307
308func main() {
309 fmt.Printf("hello, world\n")
310}
311</pre>
312
313<p>
314Then run it with the <code>go</code> tool:
315</p>
316
317<pre>
318$ go run hello.go
319hello, world
320</pre>
321
322<p>
323If you see the "hello, world" message then Go is installed correctly.
324</p>
325
326<h2 id="gopath">Set up your work environment</h2>
327
328<p>
329You're almost done.
330You just need to do a little more setup.
331</p>
332
333<p>
334<a href="/doc/code.html" class="download" id="start">
335<span class="big">How to Write Go Code</span>
336<span class="desc">Learn how to set up and use the Go tools</span>
337</a>
338</p>
339
340<p>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800341The <a href="/doc/code.html">How to Write Go Code</a> document
Colin Cross7bb052a2015-02-03 12:59:37 -0800342provides <b>essential setup instructions</b> for using the Go tools.
343</p>
344
345
346<h2 id="tools">Install additional tools</h2>
347
348<p>
349The source code for several Go tools (including <a href="/cmd/godoc/">godoc</a>)
350is kept in <a href="https://golang.org/x/tools">the go.tools repository</a>.
351To install all of them, run the <code>go</code> <code>get</code> command:
352</p>
353
354<pre>
355$ go get golang.org/x/tools/cmd/...
356</pre>
357
358<p>
359Or if you just want to install a specific command (<code>godoc</code> in this case):
360</p>
361
362<pre>
363$ go get golang.org/x/tools/cmd/godoc
364</pre>
365
366<p>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800367To install these tools, the <code>go</code> <code>get</code> command requires
Colin Cross7bb052a2015-02-03 12:59:37 -0800368that <a href="#git">Git</a> be installed locally.
369</p>
370
371<p>
372You must also have a workspace (<code>GOPATH</code>) set up;
373see <a href="/doc/code.html">How to Write Go Code</a> for the details.
374</p>
375
376<p>
377<b>Note</b>: The <code>go</code> command will install the <code>godoc</code>
378binary to <code>$GOROOT/bin</code> (or <code>$GOBIN</code>) and the
379<code>cover</code> and <code>vet</code> binaries to
380<code>$GOROOT/pkg/tool/$GOOS_$GOARCH</code>.
381You can access the latter commands with
382"<code>go</code> <code>tool</code> <code>cover</code>" and
383"<code>go</code> <code>tool</code> <code>vet</code>".
384</p>
385
386<h2 id="community">Community resources</h2>
387
388<p>
389The usual community resources such as
390<code>#go-nuts</code> on the <a href="http://freenode.net/">Freenode</a> IRC server
391and the
392<a href="//groups.google.com/group/golang-nuts">Go Nuts</a>
393mailing list have active developers that can help you with problems
394with your installation or your development work.
395For those who wish to keep up to date,
396there is another mailing list, <a href="//groups.google.com/group/golang-checkins">golang-checkins</a>,
397that receives a message summarizing each checkin to the Go repository.
398</p>
399
400<p>
401Bugs can be reported using the <a href="//golang.org/issue/new">Go issue tracker</a>.
402</p>
403
404
405<h2 id="releases">Keeping up with releases</h2>
406
407<p>
408New releases are announced on the
409<a href="//groups.google.com/group/golang-announce">golang-announce</a>
410mailing list.
411Each announcement mentions the latest release tag, for instance,
Dan Willemsena727cd02017-02-21 17:11:40 -0800412<code class="versionTag">go1.8</code>.
Colin Cross7bb052a2015-02-03 12:59:37 -0800413</p>
414
415<p>
416To update an existing tree to the latest release, you can run:
417</p>
418
419<pre>
420$ cd go/src
421$ git fetch
Dan Willemsen0c157092016-07-08 13:57:52 -0700422$ git checkout <span class="versionTag"><i>&lt;tag&gt;</i></psan>
Colin Cross7bb052a2015-02-03 12:59:37 -0800423$ ./all.bash
424</pre>
425
Dan Willemsen0c157092016-07-08 13:57:52 -0700426<p class="whereTag">
Colin Cross7bb052a2015-02-03 12:59:37 -0800427Where <code>&lt;tag&gt;</code> is the version string of the release.
Dan Willemsen0c157092016-07-08 13:57:52 -0700428</p>
Colin Cross7bb052a2015-02-03 12:59:37 -0800429
430
431<h2 id="environment">Optional environment variables</h2>
432
433<p>
434The Go compilation environment can be customized by environment variables.
435<i>None is required by the build</i>, but you may wish to set some
436to override the defaults.
437</p>
438
439<ul>
440<li><code>$GOROOT</code>
441<p>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800442The root of the Go tree, often <code>$HOME/go1.X</code>.
Colin Cross7bb052a2015-02-03 12:59:37 -0800443Its value is built into the tree when it is compiled, and
444defaults to the parent of the directory where <code>all.bash</code> was run.
445There is no need to set this unless you want to switch between multiple
446local copies of the repository.
447</p>
448
449<li><code>$GOROOT_FINAL</code>
450<p>
451The value assumed by installed binaries and scripts when
452<code>$GOROOT</code> is not set explicitly.
453It defaults to the value of <code>$GOROOT</code>.
454If you want to build the Go tree in one location
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800455but move it elsewhere after the build, set
Colin Cross7bb052a2015-02-03 12:59:37 -0800456<code>$GOROOT_FINAL</code> to the eventual location.
457</p>
458
459<li><code>$GOOS</code> and <code>$GOARCH</code>
460<p>
461The name of the target operating system and compilation architecture.
462These default to the values of <code>$GOHOSTOS</code> and
463<code>$GOHOSTARCH</code> respectively (described below).
464
465<p>
466Choices for <code>$GOOS</code> are
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800467<code>darwin</code> (Mac OS X 10.8 and above and iOS), <code>dragonfly</code>, <code>freebsd</code>,
Dan Willemsen6ff23252015-09-15 13:49:18 -0700468<code>linux</code>, <code>netbsd</code>, <code>openbsd</code>,
Colin Cross7bb052a2015-02-03 12:59:37 -0800469<code>plan9</code>, <code>solaris</code> and <code>windows</code>.
470Choices for <code>$GOARCH</code> are
471<code>amd64</code> (64-bit x86, the most mature port),
Dan Willemsen6ff23252015-09-15 13:49:18 -0700472<code>386</code> (32-bit x86), <code>arm</code> (32-bit ARM), <code>arm64</code> (64-bit ARM),
Dan Willemsen0c157092016-07-08 13:57:52 -0700473<code>ppc64le</code> (PowerPC 64-bit, little-endian), <code>ppc64</code> (PowerPC 64-bit, big-endian),
474<code>mips64le</code> (MIPS 64-bit, little-endian), and <code>mips64</code> (MIPS 64-bit, big-endian).
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800475<code>mipsle</code> (MIPS 32-bit, little-endian), and <code>mips</code> (MIPS 32-bit, big-endian).
Colin Cross7bb052a2015-02-03 12:59:37 -0800476The valid combinations of <code>$GOOS</code> and <code>$GOARCH</code> are:
477<table cellpadding="0">
478<tr>
479<th width="50"></th><th align="left" width="100"><code>$GOOS</code></th> <th align="left" width="100"><code>$GOARCH</code></th>
480</tr>
481<tr>
Dan Willemsen0c157092016-07-08 13:57:52 -0700482<td></td><td><code>android</code></td> <td><code>arm</code></td>
483</tr>
484<tr>
Colin Cross7bb052a2015-02-03 12:59:37 -0800485<td></td><td><code>darwin</code></td> <td><code>386</code></td>
486</tr>
487<tr>
488<td></td><td><code>darwin</code></td> <td><code>amd64</code></td>
489</tr>
490<tr>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700491<td></td><td><code>darwin</code></td> <td><code>arm</code></td>
492</tr>
493<tr>
494<td></td><td><code>darwin</code></td> <td><code>arm64</code></td>
Colin Cross7bb052a2015-02-03 12:59:37 -0800495</tr>
496<tr>
497<td></td><td><code>dragonfly</code></td> <td><code>amd64</code></td>
498</tr>
499<tr>
500<td></td><td><code>freebsd</code></td> <td><code>386</code></td>
501</tr>
502<tr>
503<td></td><td><code>freebsd</code></td> <td><code>amd64</code></td>
504</tr>
505<tr>
506<td></td><td><code>freebsd</code></td> <td><code>arm</code></td>
507</tr>
508<tr>
509<td></td><td><code>linux</code></td> <td><code>386</code></td>
510</tr>
511<tr>
512<td></td><td><code>linux</code></td> <td><code>amd64</code></td>
513</tr>
514<tr>
515<td></td><td><code>linux</code></td> <td><code>arm</code></td>
516</tr>
517<tr>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700518<td></td><td><code>linux</code></td> <td><code>arm64</code></td>
519</tr>
520<tr>
521<td></td><td><code>linux</code></td> <td><code>ppc64</code></td>
522</tr>
523<tr>
524<td></td><td><code>linux</code></td> <td><code>ppc64le</code></td>
525</tr>
526<tr>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800527<td></td><td><code>linux</code></td> <td><code>mips</code></td>
528</tr>
529<tr>
530<td></td><td><code>linux</code></td> <td><code>mipsle</code></td>
531</tr>
532<tr>
Dan Willemsen0c157092016-07-08 13:57:52 -0700533<td></td><td><code>linux</code></td> <td><code>mips64</code></td>
534</tr>
535<tr>
536<td></td><td><code>linux</code></td> <td><code>mips64le</code></td>
537</tr>
538<tr>
Colin Cross7bb052a2015-02-03 12:59:37 -0800539<td></td><td><code>netbsd</code></td> <td><code>386</code></td>
540</tr>
541<tr>
542<td></td><td><code>netbsd</code></td> <td><code>amd64</code></td>
543</tr>
544<tr>
545<td></td><td><code>netbsd</code></td> <td><code>arm</code></td>
546</tr>
547<tr>
548<td></td><td><code>openbsd</code></td> <td><code>386</code></td>
549</tr>
550<tr>
551<td></td><td><code>openbsd</code></td> <td><code>amd64</code></td>
552</tr>
553<tr>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700554<td></td><td><code>openbsd</code></td> <td><code>arm</code></td>
555</tr>
556<tr>
Colin Cross7bb052a2015-02-03 12:59:37 -0800557<td></td><td><code>plan9</code></td> <td><code>386</code></td>
558</tr>
559<tr>
560<td></td><td><code>plan9</code></td> <td><code>amd64</code></td>
561</tr>
562<tr>
563<td></td><td><code>solaris</code></td> <td><code>amd64</code></td>
564</tr>
565<tr>
566<td></td><td><code>windows</code></td> <td><code>386</code></td>
567</tr>
568<tr>
569<td></td><td><code>windows</code></td> <td><code>amd64</code></td>
570</tr>
571</table>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700572<br>
Colin Cross7bb052a2015-02-03 12:59:37 -0800573
574<li><code>$GOHOSTOS</code> and <code>$GOHOSTARCH</code>
575<p>
576The name of the host operating system and compilation architecture.
577These default to the local system's operating system and
578architecture.
579</p>
580
581<p>
582Valid choices are the same as for <code>$GOOS</code> and
583<code>$GOARCH</code>, listed above.
584The specified values must be compatible with the local system.
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800585For example, you should not set <code>$GOHOSTARCH</code> to
Colin Cross7bb052a2015-02-03 12:59:37 -0800586<code>arm</code> on an x86 system.
587</p>
588
589<li><code>$GOBIN</code>
590<p>
591The location where Go binaries will be installed.
592The default is <code>$GOROOT/bin</code>.
593After installing, you will want to arrange to add this
594directory to your <code>$PATH</code>, so you can use the tools.
595If <code>$GOBIN</code> is set, the <a href="/cmd/go">go command</a>
596installs all commands there.
597</p>
598
599<li><code>$GO386</code> (for <code>386</code> only, default is auto-detected
600if built on either <code>386</code> or <code>amd64</code>, <code>387</code> otherwise)
601<p>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700602This controls the code generated by gc to use either the 387 floating-point unit
Colin Cross7bb052a2015-02-03 12:59:37 -0800603(set to <code>387</code>) or SSE2 instructions (set to <code>sse2</code>) for
604floating point computations.
605</p>
606<ul>
607 <li><code>GO386=387</code>: use x87 for floating point operations; should support all x86 chips (Pentium MMX or later).
608 <li><code>GO386=sse2</code>: use SSE2 for floating point operations; has better performance than 387, but only available on Pentium 4/Opteron/Athlon 64 or later.
609</ul>
610
611<li><code>$GOARM</code> (for <code>arm</code> only; default is auto-detected if building
612on the target processor, 6 if not)
613<p>
614This sets the ARM floating point co-processor architecture version the run-time
615should target. If you are compiling on the target system, its value will be auto-detected.
616</p>
617<ul>
618 <li><code>GOARM=5</code>: use software floating point; when CPU doesn't have VFP co-processor
619 <li><code>GOARM=6</code>: use VFPv1 only; default if cross compiling; usually ARM11 or better cores (VFPv2 or better is also supported)
620 <li><code>GOARM=7</code>: use VFPv3; usually Cortex-A cores
621</ul>
622<p>
623If in doubt, leave this variable unset, and adjust it if required
624when you first run the Go executable.
625The <a href="//golang.org/wiki/GoArm">GoARM</a> page
626on the <a href="//golang.org/wiki">Go community wiki</a>
627contains further details regarding Go's ARM support.
628</p>
629
630</ul>
631
632<p>
633Note that <code>$GOARCH</code> and <code>$GOOS</code> identify the
634<em>target</em> environment, not the environment you are running on.
635In effect, you are always cross-compiling.
636By architecture, we mean the kind of binaries
637that the target environment can run:
638an x86-64 system running a 32-bit-only operating system
639must set <code>GOARCH</code> to <code>386</code>,
640not <code>amd64</code>.
641</p>
642
643<p>
644If you choose to override the defaults,
645set these variables in your shell profile (<code>$HOME/.bashrc</code>,
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800646<code>$HOME/.profile</code>, or equivalent). The settings might look
Colin Cross7bb052a2015-02-03 12:59:37 -0800647something like this:
648</p>
649
650<pre>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800651export GOROOT=$HOME/go1.X
Colin Cross7bb052a2015-02-03 12:59:37 -0800652export GOARCH=amd64
653export GOOS=linux
654</pre>
655
656<p>
657although, to reiterate, none of these variables needs to be set to build,
658install, and develop the Go tree.
659</p>