blob: 4bf0ba35fb8e852c7cb071d15853666143898b83 [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.)
150</p>
151
152<p>
153To cross-compile a bootstrap tool chain from source, which is
154necessary on systems Go 1.4 did not target (for
155example, <code>linux/ppc64le</code>), install Go on a different system
156and run <a href="/src/bootstrap.bash">bootstrap.bash</a>.
Dan Willemsen6ff23252015-09-15 13:49:18 -0700157</p>
158
159<p>
160When run as (for example)
161</p>
162
163<pre>
164$ GOOS=linux GOARCH=ppc64 ./bootstrap.bash
165</pre>
166
167<p>
168<code>bootstrap.bash</code> cross-compiles a toolchain for that <code>GOOS/GOARCH</code>
169combination, leaving the resulting tree in <code>../../go-${GOOS}-${GOARCH}-bootstrap</code>.
170That tree can be copied to a machine of the given target type
171and used as <code>GOROOT_BOOTSTRAP</code> to bootstrap a local build.
172</p>
173
174<p>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800175To use gccgo as the bootstrap toolchain, you need to arrange
176for <code>$GOROOT_BOOTSTRAP/bin/go</code> to be the go tool that comes
177as part of gccgo 5. For example on Ubuntu Vivid:
Dan Willemsen6ff23252015-09-15 13:49:18 -0700178</p>
179
180<pre>
181$ sudo apt-get install gccgo-5
182$ sudo update-alternatives --set go /usr/bin/go-5
183$ GOROOT_BOOTSTRAP=/usr ./make.bash
184</pre>
185
Colin Cross7bb052a2015-02-03 12:59:37 -0800186<h2 id="git">Install Git, if needed</h2>
187
188<p>
189To perform the next step you must have Git installed. (Check that you
190have a <code>git</code> command before proceeding.)
191</p>
192
193<p>
194If you do not have a working Git installation,
195follow the instructions on the
196<a href="http://git-scm.com/downloads">Git downloads</a> page.
197</p>
198
Dan Willemsen0c157092016-07-08 13:57:52 -0700199<h2 id="ccompiler">(Optional) Install a C compiler</h2>
200
201<p>
202To build a Go installation
203with <code><a href="/cmd/cgo">cgo</a></code> support, which permits Go
204programs to import C libraries, a C compiler such as <code>gcc</code>
205or <code>clang</code> must be installed first. Do this using whatever
206installation method is standard on the system.
207</p>
208
209<p>
210To build without <code>cgo</code>, set the environment variable
211<code>CGO_ENABLED=0</code> before running <code>all.bash</code> or
212<code>make.bash</code>.
213</p>
Colin Cross7bb052a2015-02-03 12:59:37 -0800214
215<h2 id="fetch">Fetch the repository</h2>
216
217<p>Go will install to a directory named <code>go</code>.
218Change to the directory that will be its parent
219and make sure the <code>go</code> directory does not exist.
Dan Willemsen0c157092016-07-08 13:57:52 -0700220Then clone the repository and check out the latest release tag
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800221(<code class="versionTag">go1.7.4</code>, for example):</p>
Colin Cross7bb052a2015-02-03 12:59:37 -0800222
223<pre>
224$ git clone https://go.googlesource.com/go
225$ cd go
Dan Willemsen0c157092016-07-08 13:57:52 -0700226$ git checkout <span class="versionTag"><i>&lt;tag&gt;</i></span>
Colin Cross7bb052a2015-02-03 12:59:37 -0800227</pre>
228
Dan Willemsen0c157092016-07-08 13:57:52 -0700229<p class="whereTag">
230Where <code>&lt;tag&gt;</code> is the version string of the release.
231</p>
232
Colin Cross7bb052a2015-02-03 12:59:37 -0800233<h2 id="head">(Optional) Switch to the master branch</h2>
234
235<p>If you intend to modify the go source code, and
236<a href="/doc/contribute.html">contribute your changes</a>
237to the project, then move your repository
238off the release branch, and onto the master (development) branch.
239Otherwise, skip this step.</p>
240
241<pre>
242$ git checkout master
243</pre>
244
245<h2 id="install">Install Go</h2>
246
247<p>
248To build the Go distribution, run
249</p>
250
251<pre>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700252$ cd src
Colin Cross7bb052a2015-02-03 12:59:37 -0800253$ ./all.bash
254</pre>
255
256<p>
257(To build under Windows use <code>all.bat</code>.)
258</p>
259
260<p>
261If all goes well, it will finish by printing output like:
262</p>
263
264<pre>
265ALL TESTS PASSED
266
267---
268Installed Go for linux/amd64 in /home/you/go.
269Installed commands in /home/you/go/bin.
270*** You need to add /home/you/go/bin to your $PATH. ***
271</pre>
272
273<p>
274where the details on the last few lines reflect the operating system,
275architecture, and root directory used during the install.
276</p>
277
278<div class="detail">
279<p>
280For more information about ways to control the build, see the discussion of
281<a href="#environment">environment variables</a> below.
282<code>all.bash</code> (or <code>all.bat</code>) runs important tests for Go,
283which can take more time than simply building Go. If you do not want to run
284the test suite use <code>make.bash</code> (or <code>make.bat</code>)
285instead.
286</p>
287</div>
288
289
290<h2 id="testing">Testing your installation</h2>
291
292<p>
293Check that Go is installed correctly by building a simple program.
294</p>
295
296<p>
297Create a file named <code>hello.go</code> and put the following program in it:
298</p>
299
300<pre>
301package main
302
303import "fmt"
304
305func main() {
306 fmt.Printf("hello, world\n")
307}
308</pre>
309
310<p>
311Then run it with the <code>go</code> tool:
312</p>
313
314<pre>
315$ go run hello.go
316hello, world
317</pre>
318
319<p>
320If you see the "hello, world" message then Go is installed correctly.
321</p>
322
323<h2 id="gopath">Set up your work environment</h2>
324
325<p>
326You're almost done.
327You just need to do a little more setup.
328</p>
329
330<p>
331<a href="/doc/code.html" class="download" id="start">
332<span class="big">How to Write Go Code</span>
333<span class="desc">Learn how to set up and use the Go tools</span>
334</a>
335</p>
336
337<p>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800338The <a href="/doc/code.html">How to Write Go Code</a> document
Colin Cross7bb052a2015-02-03 12:59:37 -0800339provides <b>essential setup instructions</b> for using the Go tools.
340</p>
341
342
343<h2 id="tools">Install additional tools</h2>
344
345<p>
346The source code for several Go tools (including <a href="/cmd/godoc/">godoc</a>)
347is kept in <a href="https://golang.org/x/tools">the go.tools repository</a>.
348To install all of them, run the <code>go</code> <code>get</code> command:
349</p>
350
351<pre>
352$ go get golang.org/x/tools/cmd/...
353</pre>
354
355<p>
356Or if you just want to install a specific command (<code>godoc</code> in this case):
357</p>
358
359<pre>
360$ go get golang.org/x/tools/cmd/godoc
361</pre>
362
363<p>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800364To install these tools, the <code>go</code> <code>get</code> command requires
Colin Cross7bb052a2015-02-03 12:59:37 -0800365that <a href="#git">Git</a> be installed locally.
366</p>
367
368<p>
369You must also have a workspace (<code>GOPATH</code>) set up;
370see <a href="/doc/code.html">How to Write Go Code</a> for the details.
371</p>
372
373<p>
374<b>Note</b>: The <code>go</code> command will install the <code>godoc</code>
375binary to <code>$GOROOT/bin</code> (or <code>$GOBIN</code>) and the
376<code>cover</code> and <code>vet</code> binaries to
377<code>$GOROOT/pkg/tool/$GOOS_$GOARCH</code>.
378You can access the latter commands with
379"<code>go</code> <code>tool</code> <code>cover</code>" and
380"<code>go</code> <code>tool</code> <code>vet</code>".
381</p>
382
383<h2 id="community">Community resources</h2>
384
385<p>
386The usual community resources such as
387<code>#go-nuts</code> on the <a href="http://freenode.net/">Freenode</a> IRC server
388and the
389<a href="//groups.google.com/group/golang-nuts">Go Nuts</a>
390mailing list have active developers that can help you with problems
391with your installation or your development work.
392For those who wish to keep up to date,
393there is another mailing list, <a href="//groups.google.com/group/golang-checkins">golang-checkins</a>,
394that receives a message summarizing each checkin to the Go repository.
395</p>
396
397<p>
398Bugs can be reported using the <a href="//golang.org/issue/new">Go issue tracker</a>.
399</p>
400
401
402<h2 id="releases">Keeping up with releases</h2>
403
404<p>
405New releases are announced on the
406<a href="//groups.google.com/group/golang-announce">golang-announce</a>
407mailing list.
408Each announcement mentions the latest release tag, for instance,
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800409<code class="versionTag">go1.7.4</code>.
Colin Cross7bb052a2015-02-03 12:59:37 -0800410</p>
411
412<p>
413To update an existing tree to the latest release, you can run:
414</p>
415
416<pre>
417$ cd go/src
418$ git fetch
Dan Willemsen0c157092016-07-08 13:57:52 -0700419$ git checkout <span class="versionTag"><i>&lt;tag&gt;</i></psan>
Colin Cross7bb052a2015-02-03 12:59:37 -0800420$ ./all.bash
421</pre>
422
Dan Willemsen0c157092016-07-08 13:57:52 -0700423<p class="whereTag">
Colin Cross7bb052a2015-02-03 12:59:37 -0800424Where <code>&lt;tag&gt;</code> is the version string of the release.
Dan Willemsen0c157092016-07-08 13:57:52 -0700425</p>
Colin Cross7bb052a2015-02-03 12:59:37 -0800426
427
428<h2 id="environment">Optional environment variables</h2>
429
430<p>
431The Go compilation environment can be customized by environment variables.
432<i>None is required by the build</i>, but you may wish to set some
433to override the defaults.
434</p>
435
436<ul>
437<li><code>$GOROOT</code>
438<p>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800439The root of the Go tree, often <code>$HOME/go1.X</code>.
Colin Cross7bb052a2015-02-03 12:59:37 -0800440Its value is built into the tree when it is compiled, and
441defaults to the parent of the directory where <code>all.bash</code> was run.
442There is no need to set this unless you want to switch between multiple
443local copies of the repository.
444</p>
445
446<li><code>$GOROOT_FINAL</code>
447<p>
448The value assumed by installed binaries and scripts when
449<code>$GOROOT</code> is not set explicitly.
450It defaults to the value of <code>$GOROOT</code>.
451If you want to build the Go tree in one location
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800452but move it elsewhere after the build, set
Colin Cross7bb052a2015-02-03 12:59:37 -0800453<code>$GOROOT_FINAL</code> to the eventual location.
454</p>
455
456<li><code>$GOOS</code> and <code>$GOARCH</code>
457<p>
458The name of the target operating system and compilation architecture.
459These default to the values of <code>$GOHOSTOS</code> and
460<code>$GOHOSTARCH</code> respectively (described below).
461
462<p>
463Choices for <code>$GOOS</code> are
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800464<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 -0700465<code>linux</code>, <code>netbsd</code>, <code>openbsd</code>,
Colin Cross7bb052a2015-02-03 12:59:37 -0800466<code>plan9</code>, <code>solaris</code> and <code>windows</code>.
467Choices for <code>$GOARCH</code> are
468<code>amd64</code> (64-bit x86, the most mature port),
Dan Willemsen6ff23252015-09-15 13:49:18 -0700469<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 -0700470<code>ppc64le</code> (PowerPC 64-bit, little-endian), <code>ppc64</code> (PowerPC 64-bit, big-endian),
471<code>mips64le</code> (MIPS 64-bit, little-endian), and <code>mips64</code> (MIPS 64-bit, big-endian).
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800472<code>mipsle</code> (MIPS 32-bit, little-endian), and <code>mips</code> (MIPS 32-bit, big-endian).
Colin Cross7bb052a2015-02-03 12:59:37 -0800473The valid combinations of <code>$GOOS</code> and <code>$GOARCH</code> are:
474<table cellpadding="0">
475<tr>
476<th width="50"></th><th align="left" width="100"><code>$GOOS</code></th> <th align="left" width="100"><code>$GOARCH</code></th>
477</tr>
478<tr>
Dan Willemsen0c157092016-07-08 13:57:52 -0700479<td></td><td><code>android</code></td> <td><code>arm</code></td>
480</tr>
481<tr>
Colin Cross7bb052a2015-02-03 12:59:37 -0800482<td></td><td><code>darwin</code></td> <td><code>386</code></td>
483</tr>
484<tr>
485<td></td><td><code>darwin</code></td> <td><code>amd64</code></td>
486</tr>
487<tr>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700488<td></td><td><code>darwin</code></td> <td><code>arm</code></td>
489</tr>
490<tr>
491<td></td><td><code>darwin</code></td> <td><code>arm64</code></td>
Colin Cross7bb052a2015-02-03 12:59:37 -0800492</tr>
493<tr>
494<td></td><td><code>dragonfly</code></td> <td><code>amd64</code></td>
495</tr>
496<tr>
497<td></td><td><code>freebsd</code></td> <td><code>386</code></td>
498</tr>
499<tr>
500<td></td><td><code>freebsd</code></td> <td><code>amd64</code></td>
501</tr>
502<tr>
503<td></td><td><code>freebsd</code></td> <td><code>arm</code></td>
504</tr>
505<tr>
506<td></td><td><code>linux</code></td> <td><code>386</code></td>
507</tr>
508<tr>
509<td></td><td><code>linux</code></td> <td><code>amd64</code></td>
510</tr>
511<tr>
512<td></td><td><code>linux</code></td> <td><code>arm</code></td>
513</tr>
514<tr>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700515<td></td><td><code>linux</code></td> <td><code>arm64</code></td>
516</tr>
517<tr>
518<td></td><td><code>linux</code></td> <td><code>ppc64</code></td>
519</tr>
520<tr>
521<td></td><td><code>linux</code></td> <td><code>ppc64le</code></td>
522</tr>
523<tr>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800524<td></td><td><code>linux</code></td> <td><code>mips</code></td>
525</tr>
526<tr>
527<td></td><td><code>linux</code></td> <td><code>mipsle</code></td>
528</tr>
529<tr>
Dan Willemsen0c157092016-07-08 13:57:52 -0700530<td></td><td><code>linux</code></td> <td><code>mips64</code></td>
531</tr>
532<tr>
533<td></td><td><code>linux</code></td> <td><code>mips64le</code></td>
534</tr>
535<tr>
Colin Cross7bb052a2015-02-03 12:59:37 -0800536<td></td><td><code>netbsd</code></td> <td><code>386</code></td>
537</tr>
538<tr>
539<td></td><td><code>netbsd</code></td> <td><code>amd64</code></td>
540</tr>
541<tr>
542<td></td><td><code>netbsd</code></td> <td><code>arm</code></td>
543</tr>
544<tr>
545<td></td><td><code>openbsd</code></td> <td><code>386</code></td>
546</tr>
547<tr>
548<td></td><td><code>openbsd</code></td> <td><code>amd64</code></td>
549</tr>
550<tr>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700551<td></td><td><code>openbsd</code></td> <td><code>arm</code></td>
552</tr>
553<tr>
Colin Cross7bb052a2015-02-03 12:59:37 -0800554<td></td><td><code>plan9</code></td> <td><code>386</code></td>
555</tr>
556<tr>
557<td></td><td><code>plan9</code></td> <td><code>amd64</code></td>
558</tr>
559<tr>
560<td></td><td><code>solaris</code></td> <td><code>amd64</code></td>
561</tr>
562<tr>
563<td></td><td><code>windows</code></td> <td><code>386</code></td>
564</tr>
565<tr>
566<td></td><td><code>windows</code></td> <td><code>amd64</code></td>
567</tr>
568</table>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700569<br>
Colin Cross7bb052a2015-02-03 12:59:37 -0800570
571<li><code>$GOHOSTOS</code> and <code>$GOHOSTARCH</code>
572<p>
573The name of the host operating system and compilation architecture.
574These default to the local system's operating system and
575architecture.
576</p>
577
578<p>
579Valid choices are the same as for <code>$GOOS</code> and
580<code>$GOARCH</code>, listed above.
581The specified values must be compatible with the local system.
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800582For example, you should not set <code>$GOHOSTARCH</code> to
Colin Cross7bb052a2015-02-03 12:59:37 -0800583<code>arm</code> on an x86 system.
584</p>
585
586<li><code>$GOBIN</code>
587<p>
588The location where Go binaries will be installed.
589The default is <code>$GOROOT/bin</code>.
590After installing, you will want to arrange to add this
591directory to your <code>$PATH</code>, so you can use the tools.
592If <code>$GOBIN</code> is set, the <a href="/cmd/go">go command</a>
593installs all commands there.
594</p>
595
596<li><code>$GO386</code> (for <code>386</code> only, default is auto-detected
597if built on either <code>386</code> or <code>amd64</code>, <code>387</code> otherwise)
598<p>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700599This controls the code generated by gc to use either the 387 floating-point unit
Colin Cross7bb052a2015-02-03 12:59:37 -0800600(set to <code>387</code>) or SSE2 instructions (set to <code>sse2</code>) for
601floating point computations.
602</p>
603<ul>
604 <li><code>GO386=387</code>: use x87 for floating point operations; should support all x86 chips (Pentium MMX or later).
605 <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.
606</ul>
607
608<li><code>$GOARM</code> (for <code>arm</code> only; default is auto-detected if building
609on the target processor, 6 if not)
610<p>
611This sets the ARM floating point co-processor architecture version the run-time
612should target. If you are compiling on the target system, its value will be auto-detected.
613</p>
614<ul>
615 <li><code>GOARM=5</code>: use software floating point; when CPU doesn't have VFP co-processor
616 <li><code>GOARM=6</code>: use VFPv1 only; default if cross compiling; usually ARM11 or better cores (VFPv2 or better is also supported)
617 <li><code>GOARM=7</code>: use VFPv3; usually Cortex-A cores
618</ul>
619<p>
620If in doubt, leave this variable unset, and adjust it if required
621when you first run the Go executable.
622The <a href="//golang.org/wiki/GoArm">GoARM</a> page
623on the <a href="//golang.org/wiki">Go community wiki</a>
624contains further details regarding Go's ARM support.
625</p>
626
627</ul>
628
629<p>
630Note that <code>$GOARCH</code> and <code>$GOOS</code> identify the
631<em>target</em> environment, not the environment you are running on.
632In effect, you are always cross-compiling.
633By architecture, we mean the kind of binaries
634that the target environment can run:
635an x86-64 system running a 32-bit-only operating system
636must set <code>GOARCH</code> to <code>386</code>,
637not <code>amd64</code>.
638</p>
639
640<p>
641If you choose to override the defaults,
642set these variables in your shell profile (<code>$HOME/.bashrc</code>,
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800643<code>$HOME/.profile</code>, or equivalent). The settings might look
Colin Cross7bb052a2015-02-03 12:59:37 -0800644something like this:
645</p>
646
647<pre>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800648export GOROOT=$HOME/go1.X
Colin Cross7bb052a2015-02-03 12:59:37 -0800649export GOARCH=amd64
650export GOOS=linux
651</pre>
652
653<p>
654although, to reiterate, none of these variables needs to be set to build,
655install, and develop the Go tree.
656</p>