blob: 11c66adb39d656bc50f04c1bc2673771736dfadc [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 Willemsen0c157092016-07-08 13:57:52 -070036The Go compilers support seven 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 Willemsen0c157092016-07-08 13:57:52 -070046 A mature implementation. New in 1.7 is its SSA-based back end
47 that generates compact, efficient code.
Colin Cross7bb052a2015-02-03 12:59:37 -080048</dd>
49<dt>
Dan Willemsen6ff23252015-09-15 13:49:18 -070050 <code>386</code> (<code>x86</code> or <code>x86-32</code>)
Colin Cross7bb052a2015-02-03 12:59:37 -080051</dt>
52<dd>
Dan Willemsen0c157092016-07-08 13:57:52 -070053 Comparable to the <code>amd64</code> port, but does
54 not yet use the SSA-based back end. It has an effective
55 optimizer (registerizer) and generates good code (although
56 <code>gccgo</code> can do noticeably better sometimes).
Colin Cross7bb052a2015-02-03 12:59:37 -080057</dd>
58<dt>
Dan Willemsen6ff23252015-09-15 13:49:18 -070059 <code>arm</code> (<code>ARM</code>)
Colin Cross7bb052a2015-02-03 12:59:37 -080060</dt>
61<dd>
Dan Willemsen6ff23252015-09-15 13:49:18 -070062 Supports Linux, FreeBSD, NetBSD and Darwin binaries. Less widely used than the other ports.
63</dd>
64<dt>
65 <code>arm64</code> (<code>AArch64</code>)
66</dt>
67<dd>
Dan Willemsen0c157092016-07-08 13:57:52 -070068 Supports Linux and Darwin binaries. New in 1.5 and not as well exercised as other ports.
Dan Willemsen6ff23252015-09-15 13:49:18 -070069</dd>
70<dt>
71 <code>ppc64, ppc64le</code> (64-bit PowerPC big- and little-endian)
72</dt>
73<dd>
Dan Willemsen0c157092016-07-08 13:57:52 -070074 Supports Linux binaries. New in 1.5 and not as well exercised as other ports.
75</dd>
76<dt>
77 <code>mips64, mips64le</code> (64-bit MIPS big- and little-endian)
78</dt>
79<dd>
80 Supports Linux binaries. New in 1.6 and not as well exercised as other ports.
81</dd>
82<dt>
83 <code>s390x</code> (IBM System z)
84</dt>
85<dd>
86 Supports Linux binaries. New in 1.7 and not as well exercised as other ports.
Colin Cross7bb052a2015-02-03 12:59:37 -080087</dd>
88</dl>
89
90<p>
91Except for things like low-level operating system interface code, the run-time
92support is the same in all ports and includes a mark-and-sweep garbage
93collector, efficient array and string slicing, and support for efficient
94goroutines, such as stacks that grow and shrink on demand.
95</p>
96
97<p>
98The compilers can target the DragonFly BSD, FreeBSD, Linux, NetBSD, OpenBSD,
99OS X (Darwin), Plan 9, Solaris and Windows operating systems.
100The full set of supported combinations is listed in the discussion of
101<a href="#environment">environment variables</a> below.
102</p>
103
Dan Willemsen0c157092016-07-08 13:57:52 -0700104<p>
105See the main installation page for the <a href="/doc/install#requirements">overall system requirements</a>.
106The following additional constraints apply to systems that can be built only from source:
107</p>
108
109<ul>
110<li>For Linux on PowerPC 64-bit, the minimum supported kernel version is 2.6.37, meaning that
111Go does not support CentOS 6 on these systems.
112</li>
113</ul>
114
Colin Cross7bb052a2015-02-03 12:59:37 -0800115</div>
116
Dan Willemsen6ff23252015-09-15 13:49:18 -0700117<h2 id="go14">Install Go compiler binaries</h2>
Colin Cross7bb052a2015-02-03 12:59:37 -0800118
119<p>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700120The Go tool chain is written in Go. To build it, you need a Go compiler installed.
121The scripts that do the initial build of the tools look for an existing Go tool
122chain in <code>$HOME/go1.4</code>.
123(This path may be overridden by setting the <code>GOROOT_BOOTSTRAP</code>
124environment variable.)
Colin Cross7bb052a2015-02-03 12:59:37 -0800125</p>
126
Dan Willemsen6ff23252015-09-15 13:49:18 -0700127<p>
128Build the tools with Go version 1.4 or a point release (1.4.1, 1.4.2 etc.).
129Go 1.4 binaries can be found at <a href="/dl/">the downloads page</a>.
130</p>
131
132<p>
133Download the zip or tarball of Go 1.4 for your platform and extract it to
134<code>$HOME/go1.4</code> (or your nominated <code>GOROOT_BOOTSTRAP</code>
135location).
136</p>
137
138<p>
139If you want to install Go 1.5 on a system that is not supported by Go 1.4 (such
Dan Willemsen0c157092016-07-08 13:57:52 -0700140as <code>linux/ppc64</code> and <code>linux/mips64le</code>) you can either use
Dan Willemsen6ff23252015-09-15 13:49:18 -0700141<a href="/src/bootstrap.bash">bootstrap.bash</a> on a system that can bootstrap Go
1421.5 normally, or bootstrap with gccgo 5.
143</p>
144
145<p>
146When run as (for example)
147</p>
148
149<pre>
150$ GOOS=linux GOARCH=ppc64 ./bootstrap.bash
151</pre>
152
153<p>
154<code>bootstrap.bash</code> cross-compiles a toolchain for that <code>GOOS/GOARCH</code>
155combination, leaving the resulting tree in <code>../../go-${GOOS}-${GOARCH}-bootstrap</code>.
156That tree can be copied to a machine of the given target type
157and used as <code>GOROOT_BOOTSTRAP</code> to bootstrap a local build.
158</p>
159
160<p>
Dan Willemsen0c157092016-07-08 13:57:52 -0700161To use gccgo, you need to arrange for <code>$GOROOT_BOOTSTRAP/bin/go</code> to be
Dan Willemsen6ff23252015-09-15 13:49:18 -0700162the go tool that comes as part of gccgo 5. For example on Ubuntu Vivid:
163</p>
164
165<pre>
166$ sudo apt-get install gccgo-5
167$ sudo update-alternatives --set go /usr/bin/go-5
168$ GOROOT_BOOTSTRAP=/usr ./make.bash
169</pre>
170
Colin Cross7bb052a2015-02-03 12:59:37 -0800171<h2 id="git">Install Git, if needed</h2>
172
173<p>
174To perform the next step you must have Git installed. (Check that you
175have a <code>git</code> command before proceeding.)
176</p>
177
178<p>
179If you do not have a working Git installation,
180follow the instructions on the
181<a href="http://git-scm.com/downloads">Git downloads</a> page.
182</p>
183
Dan Willemsen0c157092016-07-08 13:57:52 -0700184<h2 id="ccompiler">(Optional) Install a C compiler</h2>
185
186<p>
187To build a Go installation
188with <code><a href="/cmd/cgo">cgo</a></code> support, which permits Go
189programs to import C libraries, a C compiler such as <code>gcc</code>
190or <code>clang</code> must be installed first. Do this using whatever
191installation method is standard on the system.
192</p>
193
194<p>
195To build without <code>cgo</code>, set the environment variable
196<code>CGO_ENABLED=0</code> before running <code>all.bash</code> or
197<code>make.bash</code>.
198</p>
Colin Cross7bb052a2015-02-03 12:59:37 -0800199
200<h2 id="fetch">Fetch the repository</h2>
201
202<p>Go will install to a directory named <code>go</code>.
203Change to the directory that will be its parent
204and make sure the <code>go</code> directory does not exist.
Dan Willemsen0c157092016-07-08 13:57:52 -0700205Then clone the repository and check out the latest release tag
Dan Willemsen4c4fc742016-08-16 14:38:16 -0700206(<code class="versionTag">go1.7</code>, for example):</p>
Colin Cross7bb052a2015-02-03 12:59:37 -0800207
208<pre>
209$ git clone https://go.googlesource.com/go
210$ cd go
Dan Willemsen0c157092016-07-08 13:57:52 -0700211$ git checkout <span class="versionTag"><i>&lt;tag&gt;</i></span>
Colin Cross7bb052a2015-02-03 12:59:37 -0800212</pre>
213
Dan Willemsen0c157092016-07-08 13:57:52 -0700214<p class="whereTag">
215Where <code>&lt;tag&gt;</code> is the version string of the release.
216</p>
217
Colin Cross7bb052a2015-02-03 12:59:37 -0800218<h2 id="head">(Optional) Switch to the master branch</h2>
219
220<p>If you intend to modify the go source code, and
221<a href="/doc/contribute.html">contribute your changes</a>
222to the project, then move your repository
223off the release branch, and onto the master (development) branch.
224Otherwise, skip this step.</p>
225
226<pre>
227$ git checkout master
228</pre>
229
230<h2 id="install">Install Go</h2>
231
232<p>
233To build the Go distribution, run
234</p>
235
236<pre>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700237$ cd src
Colin Cross7bb052a2015-02-03 12:59:37 -0800238$ ./all.bash
239</pre>
240
241<p>
242(To build under Windows use <code>all.bat</code>.)
243</p>
244
245<p>
246If all goes well, it will finish by printing output like:
247</p>
248
249<pre>
250ALL TESTS PASSED
251
252---
253Installed Go for linux/amd64 in /home/you/go.
254Installed commands in /home/you/go/bin.
255*** You need to add /home/you/go/bin to your $PATH. ***
256</pre>
257
258<p>
259where the details on the last few lines reflect the operating system,
260architecture, and root directory used during the install.
261</p>
262
263<div class="detail">
264<p>
265For more information about ways to control the build, see the discussion of
266<a href="#environment">environment variables</a> below.
267<code>all.bash</code> (or <code>all.bat</code>) runs important tests for Go,
268which can take more time than simply building Go. If you do not want to run
269the test suite use <code>make.bash</code> (or <code>make.bat</code>)
270instead.
271</p>
272</div>
273
274
275<h2 id="testing">Testing your installation</h2>
276
277<p>
278Check that Go is installed correctly by building a simple program.
279</p>
280
281<p>
282Create a file named <code>hello.go</code> and put the following program in it:
283</p>
284
285<pre>
286package main
287
288import "fmt"
289
290func main() {
291 fmt.Printf("hello, world\n")
292}
293</pre>
294
295<p>
296Then run it with the <code>go</code> tool:
297</p>
298
299<pre>
300$ go run hello.go
301hello, world
302</pre>
303
304<p>
305If you see the "hello, world" message then Go is installed correctly.
306</p>
307
308<h2 id="gopath">Set up your work environment</h2>
309
310<p>
311You're almost done.
312You just need to do a little more setup.
313</p>
314
315<p>
316<a href="/doc/code.html" class="download" id="start">
317<span class="big">How to Write Go Code</span>
318<span class="desc">Learn how to set up and use the Go tools</span>
319</a>
320</p>
321
322<p>
323The <a href="/doc/code.html">How to Write Go Code</a> document
324provides <b>essential setup instructions</b> for using the Go tools.
325</p>
326
327
328<h2 id="tools">Install additional tools</h2>
329
330<p>
331The source code for several Go tools (including <a href="/cmd/godoc/">godoc</a>)
332is kept in <a href="https://golang.org/x/tools">the go.tools repository</a>.
333To install all of them, run the <code>go</code> <code>get</code> command:
334</p>
335
336<pre>
337$ go get golang.org/x/tools/cmd/...
338</pre>
339
340<p>
341Or if you just want to install a specific command (<code>godoc</code> in this case):
342</p>
343
344<pre>
345$ go get golang.org/x/tools/cmd/godoc
346</pre>
347
348<p>
349To install these tools, the <code>go</code> <code>get</code> command requires
350that <a href="#git">Git</a> be installed locally.
351</p>
352
353<p>
354You must also have a workspace (<code>GOPATH</code>) set up;
355see <a href="/doc/code.html">How to Write Go Code</a> for the details.
356</p>
357
358<p>
359<b>Note</b>: The <code>go</code> command will install the <code>godoc</code>
360binary to <code>$GOROOT/bin</code> (or <code>$GOBIN</code>) and the
361<code>cover</code> and <code>vet</code> binaries to
362<code>$GOROOT/pkg/tool/$GOOS_$GOARCH</code>.
363You can access the latter commands with
364"<code>go</code> <code>tool</code> <code>cover</code>" and
365"<code>go</code> <code>tool</code> <code>vet</code>".
366</p>
367
368<h2 id="community">Community resources</h2>
369
370<p>
371The usual community resources such as
372<code>#go-nuts</code> on the <a href="http://freenode.net/">Freenode</a> IRC server
373and the
374<a href="//groups.google.com/group/golang-nuts">Go Nuts</a>
375mailing list have active developers that can help you with problems
376with your installation or your development work.
377For those who wish to keep up to date,
378there is another mailing list, <a href="//groups.google.com/group/golang-checkins">golang-checkins</a>,
379that receives a message summarizing each checkin to the Go repository.
380</p>
381
382<p>
383Bugs can be reported using the <a href="//golang.org/issue/new">Go issue tracker</a>.
384</p>
385
386
387<h2 id="releases">Keeping up with releases</h2>
388
389<p>
390New releases are announced on the
391<a href="//groups.google.com/group/golang-announce">golang-announce</a>
392mailing list.
393Each announcement mentions the latest release tag, for instance,
Dan Willemsen4c4fc742016-08-16 14:38:16 -0700394<code class="versionTag">go1.7</code>.
Colin Cross7bb052a2015-02-03 12:59:37 -0800395</p>
396
397<p>
398To update an existing tree to the latest release, you can run:
399</p>
400
401<pre>
402$ cd go/src
403$ git fetch
Dan Willemsen0c157092016-07-08 13:57:52 -0700404$ git checkout <span class="versionTag"><i>&lt;tag&gt;</i></psan>
Colin Cross7bb052a2015-02-03 12:59:37 -0800405$ ./all.bash
406</pre>
407
Dan Willemsen0c157092016-07-08 13:57:52 -0700408<p class="whereTag">
Colin Cross7bb052a2015-02-03 12:59:37 -0800409Where <code>&lt;tag&gt;</code> is the version string of the release.
Dan Willemsen0c157092016-07-08 13:57:52 -0700410</p>
Colin Cross7bb052a2015-02-03 12:59:37 -0800411
412
413<h2 id="environment">Optional environment variables</h2>
414
415<p>
416The Go compilation environment can be customized by environment variables.
417<i>None is required by the build</i>, but you may wish to set some
418to override the defaults.
419</p>
420
421<ul>
422<li><code>$GOROOT</code>
423<p>
424The root of the Go tree, often <code>$HOME/go</code>.
425Its value is built into the tree when it is compiled, and
426defaults to the parent of the directory where <code>all.bash</code> was run.
427There is no need to set this unless you want to switch between multiple
428local copies of the repository.
429</p>
430
431<li><code>$GOROOT_FINAL</code>
432<p>
433The value assumed by installed binaries and scripts when
434<code>$GOROOT</code> is not set explicitly.
435It defaults to the value of <code>$GOROOT</code>.
436If you want to build the Go tree in one location
437but move it elsewhere after the build, set
438<code>$GOROOT_FINAL</code> to the eventual location.
439</p>
440
441<li><code>$GOOS</code> and <code>$GOARCH</code>
442<p>
443The name of the target operating system and compilation architecture.
444These default to the values of <code>$GOHOSTOS</code> and
445<code>$GOHOSTARCH</code> respectively (described below).
446
447<p>
448Choices for <code>$GOOS</code> are
Dan Willemsen6ff23252015-09-15 13:49:18 -0700449<code>darwin</code> (Mac OS X 10.7 and above and iOS), <code>dragonfly</code>, <code>freebsd</code>,
450<code>linux</code>, <code>netbsd</code>, <code>openbsd</code>,
Colin Cross7bb052a2015-02-03 12:59:37 -0800451<code>plan9</code>, <code>solaris</code> and <code>windows</code>.
452Choices for <code>$GOARCH</code> are
453<code>amd64</code> (64-bit x86, the most mature port),
Dan Willemsen6ff23252015-09-15 13:49:18 -0700454<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 -0700455<code>ppc64le</code> (PowerPC 64-bit, little-endian), <code>ppc64</code> (PowerPC 64-bit, big-endian),
456<code>mips64le</code> (MIPS 64-bit, little-endian), and <code>mips64</code> (MIPS 64-bit, big-endian).
Colin Cross7bb052a2015-02-03 12:59:37 -0800457The valid combinations of <code>$GOOS</code> and <code>$GOARCH</code> are:
458<table cellpadding="0">
459<tr>
460<th width="50"></th><th align="left" width="100"><code>$GOOS</code></th> <th align="left" width="100"><code>$GOARCH</code></th>
461</tr>
462<tr>
Dan Willemsen0c157092016-07-08 13:57:52 -0700463<td></td><td><code>android</code></td> <td><code>arm</code></td>
464</tr>
465<tr>
Colin Cross7bb052a2015-02-03 12:59:37 -0800466<td></td><td><code>darwin</code></td> <td><code>386</code></td>
467</tr>
468<tr>
469<td></td><td><code>darwin</code></td> <td><code>amd64</code></td>
470</tr>
471<tr>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700472<td></td><td><code>darwin</code></td> <td><code>arm</code></td>
473</tr>
474<tr>
475<td></td><td><code>darwin</code></td> <td><code>arm64</code></td>
Colin Cross7bb052a2015-02-03 12:59:37 -0800476</tr>
477<tr>
478<td></td><td><code>dragonfly</code></td> <td><code>amd64</code></td>
479</tr>
480<tr>
481<td></td><td><code>freebsd</code></td> <td><code>386</code></td>
482</tr>
483<tr>
484<td></td><td><code>freebsd</code></td> <td><code>amd64</code></td>
485</tr>
486<tr>
487<td></td><td><code>freebsd</code></td> <td><code>arm</code></td>
488</tr>
489<tr>
490<td></td><td><code>linux</code></td> <td><code>386</code></td>
491</tr>
492<tr>
493<td></td><td><code>linux</code></td> <td><code>amd64</code></td>
494</tr>
495<tr>
496<td></td><td><code>linux</code></td> <td><code>arm</code></td>
497</tr>
498<tr>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700499<td></td><td><code>linux</code></td> <td><code>arm64</code></td>
500</tr>
501<tr>
502<td></td><td><code>linux</code></td> <td><code>ppc64</code></td>
503</tr>
504<tr>
505<td></td><td><code>linux</code></td> <td><code>ppc64le</code></td>
506</tr>
507<tr>
Dan Willemsen0c157092016-07-08 13:57:52 -0700508<td></td><td><code>linux</code></td> <td><code>mips64</code></td>
509</tr>
510<tr>
511<td></td><td><code>linux</code></td> <td><code>mips64le</code></td>
512</tr>
513<tr>
Colin Cross7bb052a2015-02-03 12:59:37 -0800514<td></td><td><code>netbsd</code></td> <td><code>386</code></td>
515</tr>
516<tr>
517<td></td><td><code>netbsd</code></td> <td><code>amd64</code></td>
518</tr>
519<tr>
520<td></td><td><code>netbsd</code></td> <td><code>arm</code></td>
521</tr>
522<tr>
523<td></td><td><code>openbsd</code></td> <td><code>386</code></td>
524</tr>
525<tr>
526<td></td><td><code>openbsd</code></td> <td><code>amd64</code></td>
527</tr>
528<tr>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700529<td></td><td><code>openbsd</code></td> <td><code>arm</code></td>
530</tr>
531<tr>
Colin Cross7bb052a2015-02-03 12:59:37 -0800532<td></td><td><code>plan9</code></td> <td><code>386</code></td>
533</tr>
534<tr>
535<td></td><td><code>plan9</code></td> <td><code>amd64</code></td>
536</tr>
537<tr>
538<td></td><td><code>solaris</code></td> <td><code>amd64</code></td>
539</tr>
540<tr>
541<td></td><td><code>windows</code></td> <td><code>386</code></td>
542</tr>
543<tr>
544<td></td><td><code>windows</code></td> <td><code>amd64</code></td>
545</tr>
546</table>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700547<br>
Colin Cross7bb052a2015-02-03 12:59:37 -0800548
549<li><code>$GOHOSTOS</code> and <code>$GOHOSTARCH</code>
550<p>
551The name of the host operating system and compilation architecture.
552These default to the local system's operating system and
553architecture.
554</p>
555
556<p>
557Valid choices are the same as for <code>$GOOS</code> and
558<code>$GOARCH</code>, listed above.
559The specified values must be compatible with the local system.
560For example, you should not set <code>$GOHOSTARCH</code> to
561<code>arm</code> on an x86 system.
562</p>
563
564<li><code>$GOBIN</code>
565<p>
566The location where Go binaries will be installed.
567The default is <code>$GOROOT/bin</code>.
568After installing, you will want to arrange to add this
569directory to your <code>$PATH</code>, so you can use the tools.
570If <code>$GOBIN</code> is set, the <a href="/cmd/go">go command</a>
571installs all commands there.
572</p>
573
574<li><code>$GO386</code> (for <code>386</code> only, default is auto-detected
575if built on either <code>386</code> or <code>amd64</code>, <code>387</code> otherwise)
576<p>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700577This controls the code generated by gc to use either the 387 floating-point unit
Colin Cross7bb052a2015-02-03 12:59:37 -0800578(set to <code>387</code>) or SSE2 instructions (set to <code>sse2</code>) for
579floating point computations.
580</p>
581<ul>
582 <li><code>GO386=387</code>: use x87 for floating point operations; should support all x86 chips (Pentium MMX or later).
583 <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.
584</ul>
585
586<li><code>$GOARM</code> (for <code>arm</code> only; default is auto-detected if building
587on the target processor, 6 if not)
588<p>
589This sets the ARM floating point co-processor architecture version the run-time
590should target. If you are compiling on the target system, its value will be auto-detected.
591</p>
592<ul>
593 <li><code>GOARM=5</code>: use software floating point; when CPU doesn't have VFP co-processor
594 <li><code>GOARM=6</code>: use VFPv1 only; default if cross compiling; usually ARM11 or better cores (VFPv2 or better is also supported)
595 <li><code>GOARM=7</code>: use VFPv3; usually Cortex-A cores
596</ul>
597<p>
598If in doubt, leave this variable unset, and adjust it if required
599when you first run the Go executable.
600The <a href="//golang.org/wiki/GoArm">GoARM</a> page
601on the <a href="//golang.org/wiki">Go community wiki</a>
602contains further details regarding Go's ARM support.
603</p>
604
605</ul>
606
607<p>
608Note that <code>$GOARCH</code> and <code>$GOOS</code> identify the
609<em>target</em> environment, not the environment you are running on.
610In effect, you are always cross-compiling.
611By architecture, we mean the kind of binaries
612that the target environment can run:
613an x86-64 system running a 32-bit-only operating system
614must set <code>GOARCH</code> to <code>386</code>,
615not <code>amd64</code>.
616</p>
617
618<p>
619If you choose to override the defaults,
620set these variables in your shell profile (<code>$HOME/.bashrc</code>,
621<code>$HOME/.profile</code>, or equivalent). The settings might look
622something like this:
623</p>
624
625<pre>
626export GOROOT=$HOME/go
627export GOARCH=amd64
628export GOOS=linux
629</pre>
630
631<p>
632although, to reiterate, none of these variables needs to be set to build,
633install, and develop the Go tree.
634</p>