blob: 12b10d56211324253ad2b2f7b954d30d3ba44a94 [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>
Dan Willemsene1b3b182018-02-27 19:36:27 -080027There are two official Go compiler toolchains.
Colin Cross7bb052a2015-02-03 12:59:37 -080028This 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>
Colin Crossefed6342019-09-07 08:34:44 -070036The Go compilers support nine 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>
Colin Crossefed6342019-09-07 08:34:44 -070090<dt>
91 <code>wasm</code> (WebAssembly)
92</dt>
93<dd>
94 Targets the WebAssembly platform. New in 1.11 and not as well exercised as other ports.
95</dd>
Colin Cross7bb052a2015-02-03 12:59:37 -080096</dl>
97
98<p>
99Except for things like low-level operating system interface code, the run-time
100support is the same in all ports and includes a mark-and-sweep garbage
101collector, efficient array and string slicing, and support for efficient
102goroutines, such as stacks that grow and shrink on demand.
103</p>
104
105<p>
106The compilers can target the DragonFly BSD, FreeBSD, Linux, NetBSD, OpenBSD,
Dan Willemsenf3f2eb62018-08-28 11:28:58 -0700107macOS (Darwin), Plan 9, Solaris and Windows operating systems.
Colin Cross7bb052a2015-02-03 12:59:37 -0800108The full set of supported combinations is listed in the discussion of
109<a href="#environment">environment variables</a> below.
110</p>
111
Dan Willemsen0c157092016-07-08 13:57:52 -0700112<p>
113See the main installation page for the <a href="/doc/install#requirements">overall system requirements</a>.
114The following additional constraints apply to systems that can be built only from source:
115</p>
116
117<ul>
118<li>For Linux on PowerPC 64-bit, the minimum supported kernel version is 2.6.37, meaning that
119Go does not support CentOS 6 on these systems.
120</li>
121</ul>
122
Colin Cross7bb052a2015-02-03 12:59:37 -0800123</div>
124
Dan Willemsen6ff23252015-09-15 13:49:18 -0700125<h2 id="go14">Install Go compiler binaries</h2>
Colin Cross7bb052a2015-02-03 12:59:37 -0800126
127<p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800128The Go toolchain is written in Go. To build it, you need a Go compiler installed.
Dan Willemsen6ff23252015-09-15 13:49:18 -0700129The scripts that do the initial build of the tools look for an existing Go tool
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800130chain in <code>$GOROOT_BOOTSTRAP</code>.
131If unset, the default value of <code>GOROOT_BOOTSTRAP</code>
132is <code>$HOME/go1.4</code>.
Colin Cross7bb052a2015-02-03 12:59:37 -0800133</p>
134
Dan Willemsen6ff23252015-09-15 13:49:18 -0700135<p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800136There are many options for the bootstrap toolchain.
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800137After obtaining one, set <code>GOROOT_BOOTSTRAP</code> to the
138directory containing the unpacked tree.
139For example, <code>$GOROOT_BOOTSTRAP/bin/go</code> should be
Dan Willemsene1b3b182018-02-27 19:36:27 -0800140the <code>go</code> command binary for the bootstrap toolchain.
Dan Willemsen6ff23252015-09-15 13:49:18 -0700141</p>
142
Colin Crossefed6342019-09-07 08:34:44 -0700143<h3 id="bootstrapFromBinaryRelease">Bootstrap toolchain from binary release</h3>
144
Dan Willemsen6ff23252015-09-15 13:49:18 -0700145<p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800146To use a binary release as a bootstrap toolchain, see
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800147<a href="/dl/">the downloads page</a> or use any other
148packaged Go distribution.
Dan Willemsen6ff23252015-09-15 13:49:18 -0700149</p>
150
Colin Crossefed6342019-09-07 08:34:44 -0700151<h3 id="bootstrapFromSource">Bootstrap toolchain from source</h3>
152
Dan Willemsen6ff23252015-09-15 13:49:18 -0700153<p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800154To build a bootstrap toolchain from source, use
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800155either the git branch <code>release-branch.go1.4</code> or
Dan Willemsene1b3b182018-02-27 19:36:27 -0800156<a href="https://dl.google.com/go/go1.4-bootstrap-20171003.tar.gz">go1.4-bootstrap-20171003.tar.gz</a>,
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800157which contains the Go 1.4 source code plus accumulated fixes
158to keep the tools running on newer operating systems.
Dan Willemsene1b3b182018-02-27 19:36:27 -0800159(Go 1.4 was the last distribution in which the toolchain was written in C.)
Dan Willemsena727cd02017-02-21 17:11:40 -0800160After unpacking the Go 1.4 source, <code>cd</code> to
Dan Willemsene1b3b182018-02-27 19:36:27 -0800161the <code>src</code> subdirectory, set <code>CGO_ENABLED=0</code> in
162the environment, and run <code>make.bash</code> (or,
Dan Willemsena727cd02017-02-21 17:11:40 -0800163on Windows, <code>make.bat</code>).
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800164</p>
165
166<p>
Colin Crossefed6342019-09-07 08:34:44 -0700167Once the Go 1.4 source has been unpacked into your GOROOT_BOOTSTRAP directory,
168you must keep this git clone instance checked out to branch
169<code>release-branch.go1.4</code>. Specifically, do not attempt to reuse
170this git clone in the later step named "Fetch the repository." The go1.4
171bootstrap toolchain <b>must be able</b> to properly traverse the go1.4 sources
172that it assumes are present under this repository root.
173</p>
174
175<h3 id="bootstrapFromCrosscompiledSource">Bootstrap toolchain from cross-compiled source</h3>
176
177<p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800178To cross-compile a bootstrap toolchain from source, which is
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800179necessary on systems Go 1.4 did not target (for
180example, <code>linux/ppc64le</code>), install Go on a different system
181and run <a href="/src/bootstrap.bash">bootstrap.bash</a>.
Dan Willemsen6ff23252015-09-15 13:49:18 -0700182</p>
183
184<p>
185When run as (for example)
186</p>
187
188<pre>
189$ GOOS=linux GOARCH=ppc64 ./bootstrap.bash
190</pre>
191
192<p>
193<code>bootstrap.bash</code> cross-compiles a toolchain for that <code>GOOS/GOARCH</code>
194combination, leaving the resulting tree in <code>../../go-${GOOS}-${GOARCH}-bootstrap</code>.
195That tree can be copied to a machine of the given target type
196and used as <code>GOROOT_BOOTSTRAP</code> to bootstrap a local build.
197</p>
198
Colin Crossefed6342019-09-07 08:34:44 -0700199<h3 id="bootstrapFromGccgo">Bootstrap toolchain using gccgo</h3>
200
Dan Willemsen6ff23252015-09-15 13:49:18 -0700201<p>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800202To use gccgo as the bootstrap toolchain, you need to arrange
203for <code>$GOROOT_BOOTSTRAP/bin/go</code> to be the go tool that comes
204as part of gccgo 5. For example on Ubuntu Vivid:
Dan Willemsen6ff23252015-09-15 13:49:18 -0700205</p>
206
207<pre>
208$ sudo apt-get install gccgo-5
209$ sudo update-alternatives --set go /usr/bin/go-5
210$ GOROOT_BOOTSTRAP=/usr ./make.bash
211</pre>
212
Colin Cross7bb052a2015-02-03 12:59:37 -0800213<h2 id="git">Install Git, if needed</h2>
214
215<p>
216To perform the next step you must have Git installed. (Check that you
217have a <code>git</code> command before proceeding.)
218</p>
219
220<p>
221If you do not have a working Git installation,
222follow the instructions on the
Dan Willemsenf3f2eb62018-08-28 11:28:58 -0700223<a href="https://git-scm.com/downloads">Git downloads</a> page.
Colin Cross7bb052a2015-02-03 12:59:37 -0800224</p>
225
Dan Willemsen0c157092016-07-08 13:57:52 -0700226<h2 id="ccompiler">(Optional) Install a C compiler</h2>
227
228<p>
229To build a Go installation
230with <code><a href="/cmd/cgo">cgo</a></code> support, which permits Go
231programs to import C libraries, a C compiler such as <code>gcc</code>
232or <code>clang</code> must be installed first. Do this using whatever
233installation method is standard on the system.
234</p>
235
236<p>
237To build without <code>cgo</code>, set the environment variable
238<code>CGO_ENABLED=0</code> before running <code>all.bash</code> or
239<code>make.bash</code>.
240</p>
Colin Cross7bb052a2015-02-03 12:59:37 -0800241
242<h2 id="fetch">Fetch the repository</h2>
243
Colin Crossefed6342019-09-07 08:34:44 -0700244<p>Change to the directory where you intend to install Go, and make sure
245the <code>goroot</code> directory does not exist. Then clone the repository
246and check out the latest release tag (<code class="versionTag">go1.12</code>,
247for example):</p>
Colin Cross7bb052a2015-02-03 12:59:37 -0800248
249<pre>
Colin Crossefed6342019-09-07 08:34:44 -0700250$ git clone https://go.googlesource.com/go goroot
251$ cd goroot
Dan Willemsen0c157092016-07-08 13:57:52 -0700252$ git checkout <span class="versionTag"><i>&lt;tag&gt;</i></span>
Colin Cross7bb052a2015-02-03 12:59:37 -0800253</pre>
254
Dan Willemsen0c157092016-07-08 13:57:52 -0700255<p class="whereTag">
256Where <code>&lt;tag&gt;</code> is the version string of the release.
257</p>
258
Colin Crossefed6342019-09-07 08:34:44 -0700259<p>Go will be installed in the directory where it is checked out. For example,
260if Go is checked out in <code>$HOME/goroot</code>, executables will be installed
261in <code>$HOME/goroot/bin</code>. The directory may have any name, but note
262that if Go is checked out in <code>$HOME/go</code>, it will conflict with
263the default location of <code>$GOPATH</code>.
264See <a href="#gopath"><code>GOPATH</code></a> below.</p>
265
266Reminder: If you opted to also compile the bootstrap binaries from source (in an
267earlier section), you still need to <code>git clone</code> again at this point
268(to checkout the latest <code>&lt;tag&gt;</code>), because you must keep your
269go1.4 repository distinct.
270
Colin Cross7bb052a2015-02-03 12:59:37 -0800271<h2 id="head">(Optional) Switch to the master branch</h2>
272
273<p>If you intend to modify the go source code, and
274<a href="/doc/contribute.html">contribute your changes</a>
275to the project, then move your repository
276off the release branch, and onto the master (development) branch.
277Otherwise, skip this step.</p>
278
279<pre>
280$ git checkout master
281</pre>
282
283<h2 id="install">Install Go</h2>
284
285<p>
286To build the Go distribution, run
287</p>
288
289<pre>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700290$ cd src
Colin Cross7bb052a2015-02-03 12:59:37 -0800291$ ./all.bash
292</pre>
293
294<p>
295(To build under Windows use <code>all.bat</code>.)
296</p>
297
298<p>
299If all goes well, it will finish by printing output like:
300</p>
301
302<pre>
303ALL TESTS PASSED
304
305---
306Installed Go for linux/amd64 in /home/you/go.
307Installed commands in /home/you/go/bin.
308*** You need to add /home/you/go/bin to your $PATH. ***
309</pre>
310
311<p>
312where the details on the last few lines reflect the operating system,
313architecture, and root directory used during the install.
314</p>
315
316<div class="detail">
317<p>
318For more information about ways to control the build, see the discussion of
319<a href="#environment">environment variables</a> below.
320<code>all.bash</code> (or <code>all.bat</code>) runs important tests for Go,
321which can take more time than simply building Go. If you do not want to run
322the test suite use <code>make.bash</code> (or <code>make.bat</code>)
323instead.
324</p>
325</div>
326
327
328<h2 id="testing">Testing your installation</h2>
329
330<p>
331Check that Go is installed correctly by building a simple program.
332</p>
333
334<p>
335Create a file named <code>hello.go</code> and put the following program in it:
336</p>
337
338<pre>
339package main
340
341import "fmt"
342
343func main() {
Dan Willemsenf3f2eb62018-08-28 11:28:58 -0700344 fmt.Printf("hello, world\n")
Colin Cross7bb052a2015-02-03 12:59:37 -0800345}
346</pre>
347
348<p>
349Then run it with the <code>go</code> tool:
350</p>
351
352<pre>
353$ go run hello.go
354hello, world
355</pre>
356
357<p>
358If you see the "hello, world" message then Go is installed correctly.
359</p>
360
361<h2 id="gopath">Set up your work environment</h2>
362
363<p>
364You're almost done.
365You just need to do a little more setup.
366</p>
367
368<p>
369<a href="/doc/code.html" class="download" id="start">
370<span class="big">How to Write Go Code</span>
371<span class="desc">Learn how to set up and use the Go tools</span>
372</a>
373</p>
374
375<p>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800376The <a href="/doc/code.html">How to Write Go Code</a> document
Colin Cross7bb052a2015-02-03 12:59:37 -0800377provides <b>essential setup instructions</b> for using the Go tools.
378</p>
379
380
381<h2 id="tools">Install additional tools</h2>
382
383<p>
384The source code for several Go tools (including <a href="/cmd/godoc/">godoc</a>)
385is kept in <a href="https://golang.org/x/tools">the go.tools repository</a>.
Colin Cross1371fe42019-03-19 21:08:48 -0700386To install one of the tools (<code>godoc</code> in this case):
Colin Cross7bb052a2015-02-03 12:59:37 -0800387</p>
388
389<pre>
390$ go get golang.org/x/tools/cmd/godoc
391</pre>
392
393<p>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800394To install these tools, the <code>go</code> <code>get</code> command requires
Colin Cross7bb052a2015-02-03 12:59:37 -0800395that <a href="#git">Git</a> be installed locally.
396</p>
397
398<p>
399You must also have a workspace (<code>GOPATH</code>) set up;
400see <a href="/doc/code.html">How to Write Go Code</a> for the details.
401</p>
402
Colin Cross7bb052a2015-02-03 12:59:37 -0800403<h2 id="community">Community resources</h2>
404
405<p>
406The usual community resources such as
Dan Willemsenf3f2eb62018-08-28 11:28:58 -0700407<code>#go-nuts</code> on the <a href="https://freenode.net/">Freenode</a> IRC server
Colin Cross7bb052a2015-02-03 12:59:37 -0800408and the
409<a href="//groups.google.com/group/golang-nuts">Go Nuts</a>
410mailing list have active developers that can help you with problems
411with your installation or your development work.
412For those who wish to keep up to date,
413there is another mailing list, <a href="//groups.google.com/group/golang-checkins">golang-checkins</a>,
414that receives a message summarizing each checkin to the Go repository.
415</p>
416
417<p>
418Bugs can be reported using the <a href="//golang.org/issue/new">Go issue tracker</a>.
419</p>
420
421
422<h2 id="releases">Keeping up with releases</h2>
423
424<p>
425New releases are announced on the
426<a href="//groups.google.com/group/golang-announce">golang-announce</a>
427mailing list.
428Each announcement mentions the latest release tag, for instance,
Dan Willemsencc0b9f52017-08-25 11:20:05 -0700429<code class="versionTag">go1.9</code>.
Colin Cross7bb052a2015-02-03 12:59:37 -0800430</p>
431
432<p>
433To update an existing tree to the latest release, you can run:
434</p>
435
436<pre>
437$ cd go/src
438$ git fetch
Dan Willemsen0c157092016-07-08 13:57:52 -0700439$ git checkout <span class="versionTag"><i>&lt;tag&gt;</i></psan>
Colin Cross7bb052a2015-02-03 12:59:37 -0800440$ ./all.bash
441</pre>
442
Dan Willemsen0c157092016-07-08 13:57:52 -0700443<p class="whereTag">
Colin Cross7bb052a2015-02-03 12:59:37 -0800444Where <code>&lt;tag&gt;</code> is the version string of the release.
Dan Willemsen0c157092016-07-08 13:57:52 -0700445</p>
Colin Cross7bb052a2015-02-03 12:59:37 -0800446
447
448<h2 id="environment">Optional environment variables</h2>
449
450<p>
451The Go compilation environment can be customized by environment variables.
452<i>None is required by the build</i>, but you may wish to set some
453to override the defaults.
454</p>
455
456<ul>
457<li><code>$GOROOT</code>
458<p>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800459The root of the Go tree, often <code>$HOME/go1.X</code>.
Colin Cross7bb052a2015-02-03 12:59:37 -0800460Its value is built into the tree when it is compiled, and
461defaults to the parent of the directory where <code>all.bash</code> was run.
462There is no need to set this unless you want to switch between multiple
463local copies of the repository.
464</p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800465</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800466
467<li><code>$GOROOT_FINAL</code>
468<p>
469The value assumed by installed binaries and scripts when
470<code>$GOROOT</code> is not set explicitly.
471It defaults to the value of <code>$GOROOT</code>.
472If you want to build the Go tree in one location
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800473but move it elsewhere after the build, set
Colin Cross7bb052a2015-02-03 12:59:37 -0800474<code>$GOROOT_FINAL</code> to the eventual location.
475</p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800476</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800477
Colin Crossefed6342019-09-07 08:34:44 -0700478<li id="gopath"><code>$GOPATH</code>
479<p>
480The directory where Go projects outside the Go distribution are typically
481checked out. For example, <code>golang.org/x/tools</code> might be checked out
482to <code>$GOPATH/src/golang.org/x/tools</code>. Executables outside the
483Go distribution are installed in <code>$GOPATH/bin</code> (or
484<code>$GOBIN</code>, if set). Modules are downloaded and cached in
485<code>$GOPATH/pkg/mod</code>.
486</p>
487
488<p>The default location of <code>$GOPATH</code> is <code>$HOME/go</code>,
489and it's not usually necessary to set <code>GOPATH</code> explicitly. However,
490if you have checked out the Go distribution to <code>$HOME/go</code>,
491you must set <code>GOPATH</code> to another location to avoid conflicts.
492</p>
493</li>
494
495<li><code>$GOBIN</code>
496<p>
497The directory where executables outside the Go distribution are installed
498using the <a href="/cmd/go">go command</a>. For example,
499<code>go get golang.org/x/tools/cmd/godoc</code> downloads, builds, and
500installs <code>$GOBIN/godoc</code>. By default, <code>$GOBIN</code> is
501<code>$GOPATH/bin</code> (or <code>$HOME/go/bin</code> if <code>GOPATH</code>
502is not set). After installing, you will want to add this directory to
503your <code>$PATH</code> so you can use installed tools.
504</p>
505
506<p>
507Note that the Go distribution's executables are installed in
508<code>$GOROOT/bin</code> (for executables invoked by people) or
509<code>$GOTOOLDIR</code> (for executables invoked by the go command;
510defaults to <code>$GOROOT/pkg/$GOOS_GOARCH</code>) instead of
511<code>$GOBIN</code>.
512</p>
513</li>
514
Colin Cross7bb052a2015-02-03 12:59:37 -0800515<li><code>$GOOS</code> and <code>$GOARCH</code>
516<p>
517The name of the target operating system and compilation architecture.
518These default to the values of <code>$GOHOSTOS</code> and
519<code>$GOHOSTARCH</code> respectively (described below).
Dan Willemsene1b3b182018-02-27 19:36:27 -0800520</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800521
522<p>
523Choices for <code>$GOOS</code> are
Colin Crossefed6342019-09-07 08:34:44 -0700524<code>android</code>, <code>darwin</code> (macOS 10.11 and above and iOS),
525<code>dragonfly</code>, <code>freebsd</code>, <code>illumos</code>, <code>js</code>,
Dan Willemsen6ff23252015-09-15 13:49:18 -0700526<code>linux</code>, <code>netbsd</code>, <code>openbsd</code>,
Colin Cross7bb052a2015-02-03 12:59:37 -0800527<code>plan9</code>, <code>solaris</code> and <code>windows</code>.
Colin Crossefed6342019-09-07 08:34:44 -0700528</p>
529
530<p>
Colin Cross7bb052a2015-02-03 12:59:37 -0800531Choices for <code>$GOARCH</code> are
532<code>amd64</code> (64-bit x86, the most mature port),
Dan Willemsen6ff23252015-09-15 13:49:18 -0700533<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 -0700534<code>ppc64le</code> (PowerPC 64-bit, little-endian), <code>ppc64</code> (PowerPC 64-bit, big-endian),
Dan Willemsene1b3b182018-02-27 19:36:27 -0800535<code>mips64le</code> (MIPS 64-bit, little-endian), <code>mips64</code> (MIPS 64-bit, big-endian),
Colin Crossefed6342019-09-07 08:34:44 -0700536<code>mipsle</code> (MIPS 32-bit, little-endian), <code>mips</code> (MIPS 32-bit, big-endian),
537<code>s390x</code> (IBM System z 64-bit, big-endian), and
538<code>wasm</code> (WebAssembly 32-bit).
539</p>
540
541<p>
Colin Cross7bb052a2015-02-03 12:59:37 -0800542The valid combinations of <code>$GOOS</code> and <code>$GOARCH</code> are:
543<table cellpadding="0">
544<tr>
545<th width="50"></th><th align="left" width="100"><code>$GOOS</code></th> <th align="left" width="100"><code>$GOARCH</code></th>
546</tr>
547<tr>
Colin Crossefed6342019-09-07 08:34:44 -0700548<td></td><td><code>aix</code></td> <td><code>ppc64</code></td>
549</tr>
550<tr>
551<td></td><td><code>android</code></td> <td><code>386</code></td>
552</tr>
553<tr>
554<td></td><td><code>android</code></td> <td><code>amd64</code></td>
555</tr>
556<tr>
Dan Willemsen0c157092016-07-08 13:57:52 -0700557<td></td><td><code>android</code></td> <td><code>arm</code></td>
558</tr>
559<tr>
Colin Crossefed6342019-09-07 08:34:44 -0700560<td></td><td><code>android</code></td> <td><code>arm64</code></td>
561</tr>
562<tr>
Colin Cross7bb052a2015-02-03 12:59:37 -0800563<td></td><td><code>darwin</code></td> <td><code>386</code></td>
564</tr>
565<tr>
566<td></td><td><code>darwin</code></td> <td><code>amd64</code></td>
567</tr>
568<tr>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700569<td></td><td><code>darwin</code></td> <td><code>arm</code></td>
570</tr>
571<tr>
572<td></td><td><code>darwin</code></td> <td><code>arm64</code></td>
Colin Cross7bb052a2015-02-03 12:59:37 -0800573</tr>
574<tr>
575<td></td><td><code>dragonfly</code></td> <td><code>amd64</code></td>
576</tr>
577<tr>
578<td></td><td><code>freebsd</code></td> <td><code>386</code></td>
579</tr>
580<tr>
581<td></td><td><code>freebsd</code></td> <td><code>amd64</code></td>
582</tr>
583<tr>
584<td></td><td><code>freebsd</code></td> <td><code>arm</code></td>
585</tr>
586<tr>
Colin Crossefed6342019-09-07 08:34:44 -0700587<td></td><td><code>illumos</code></td> <td><code>amd64</code></td>
588</tr>
589<tr>
590<td></td><td><code>js</code></td> <td><code>wasm</code></td>
591</tr>
592<tr>
Colin Cross7bb052a2015-02-03 12:59:37 -0800593<td></td><td><code>linux</code></td> <td><code>386</code></td>
594</tr>
595<tr>
596<td></td><td><code>linux</code></td> <td><code>amd64</code></td>
597</tr>
598<tr>
599<td></td><td><code>linux</code></td> <td><code>arm</code></td>
600</tr>
601<tr>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700602<td></td><td><code>linux</code></td> <td><code>arm64</code></td>
603</tr>
604<tr>
605<td></td><td><code>linux</code></td> <td><code>ppc64</code></td>
606</tr>
607<tr>
608<td></td><td><code>linux</code></td> <td><code>ppc64le</code></td>
609</tr>
610<tr>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800611<td></td><td><code>linux</code></td> <td><code>mips</code></td>
612</tr>
613<tr>
614<td></td><td><code>linux</code></td> <td><code>mipsle</code></td>
615</tr>
616<tr>
Dan Willemsen0c157092016-07-08 13:57:52 -0700617<td></td><td><code>linux</code></td> <td><code>mips64</code></td>
618</tr>
619<tr>
620<td></td><td><code>linux</code></td> <td><code>mips64le</code></td>
621</tr>
622<tr>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800623<td></td><td><code>linux</code></td> <td><code>s390x</code></td>
624</tr>
625<tr>
Colin Cross7bb052a2015-02-03 12:59:37 -0800626<td></td><td><code>netbsd</code></td> <td><code>386</code></td>
627</tr>
628<tr>
629<td></td><td><code>netbsd</code></td> <td><code>amd64</code></td>
630</tr>
631<tr>
632<td></td><td><code>netbsd</code></td> <td><code>arm</code></td>
633</tr>
634<tr>
635<td></td><td><code>openbsd</code></td> <td><code>386</code></td>
636</tr>
637<tr>
638<td></td><td><code>openbsd</code></td> <td><code>amd64</code></td>
639</tr>
640<tr>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700641<td></td><td><code>openbsd</code></td> <td><code>arm</code></td>
642</tr>
643<tr>
Colin Crossefed6342019-09-07 08:34:44 -0700644<td></td><td><code>openbsd</code></td> <td><code>arm64</code></td>
645</tr>
646<tr>
Colin Cross7bb052a2015-02-03 12:59:37 -0800647<td></td><td><code>plan9</code></td> <td><code>386</code></td>
648</tr>
649<tr>
650<td></td><td><code>plan9</code></td> <td><code>amd64</code></td>
651</tr>
652<tr>
Colin Crossefed6342019-09-07 08:34:44 -0700653<td></td><td><code>plan9</code></td> <td><code>arm</code></td>
654</tr>
655<tr>
Colin Cross7bb052a2015-02-03 12:59:37 -0800656<td></td><td><code>solaris</code></td> <td><code>amd64</code></td>
657</tr>
658<tr>
659<td></td><td><code>windows</code></td> <td><code>386</code></td>
660</tr>
661<tr>
662<td></td><td><code>windows</code></td> <td><code>amd64</code></td>
663</tr>
664</table>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700665<br>
Colin Cross7bb052a2015-02-03 12:59:37 -0800666
667<li><code>$GOHOSTOS</code> and <code>$GOHOSTARCH</code>
668<p>
669The name of the host operating system and compilation architecture.
670These default to the local system's operating system and
671architecture.
672</p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800673</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800674
675<p>
676Valid choices are the same as for <code>$GOOS</code> and
677<code>$GOARCH</code>, listed above.
678The specified values must be compatible with the local system.
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800679For example, you should not set <code>$GOHOSTARCH</code> to
Colin Cross7bb052a2015-02-03 12:59:37 -0800680<code>arm</code> on an x86 system.
681</p>
682
Colin Cross7bb052a2015-02-03 12:59:37 -0800683<li><code>$GO386</code> (for <code>386</code> only, default is auto-detected
684if built on either <code>386</code> or <code>amd64</code>, <code>387</code> otherwise)
685<p>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700686This controls the code generated by gc to use either the 387 floating-point unit
Colin Cross7bb052a2015-02-03 12:59:37 -0800687(set to <code>387</code>) or SSE2 instructions (set to <code>sse2</code>) for
688floating point computations.
689</p>
690<ul>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800691 <li><code>GO386=387</code>: use x87 for floating point operations; should support all x86 chips (Pentium MMX or later).</li>
692 <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.</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800693</ul>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800694</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800695
696<li><code>$GOARM</code> (for <code>arm</code> only; default is auto-detected if building
697on the target processor, 6 if not)
698<p>
699This sets the ARM floating point co-processor architecture version the run-time
700should target. If you are compiling on the target system, its value will be auto-detected.
701</p>
702<ul>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800703 <li><code>GOARM=5</code>: use software floating point; when CPU doesn't have VFP co-processor</li>
704 <li><code>GOARM=6</code>: use VFPv1 only; default if cross compiling; usually ARM11 or better cores (VFPv2 or better is also supported)</li>
705 <li><code>GOARM=7</code>: use VFPv3; usually Cortex-A cores</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800706</ul>
707<p>
708If in doubt, leave this variable unset, and adjust it if required
709when you first run the Go executable.
710The <a href="//golang.org/wiki/GoArm">GoARM</a> page
711on the <a href="//golang.org/wiki">Go community wiki</a>
712contains further details regarding Go's ARM support.
713</p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800714</li>
715
Colin Cross1371fe42019-03-19 21:08:48 -0700716<li><code>$GOMIPS</code> (for <code>mips</code> and <code>mipsle</code> only) <br> <code>$GOMIPS64</code> (for <code>mips64</code> and <code>mips64le</code> only)
Dan Willemsene1b3b182018-02-27 19:36:27 -0800717<p>
Colin Cross1371fe42019-03-19 21:08:48 -0700718 These variables set whether to use floating point instructions. Set to "<code>hardfloat</code>" to use floating point instructions; this is the default. Set to "<code>softfloat</code>" to use soft floating point.
Dan Willemsene1b3b182018-02-27 19:36:27 -0800719</p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800720</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800721
Colin Crossefed6342019-09-07 08:34:44 -0700722<li><code>$GOPPC64</code> (for <code>ppc64</code> and <code>ppc64le</code> only)
723<p>
724This variable sets the processor level (i.e. Instruction Set Architecture version)
725for which the compiler will target. The default is <code>power8</code>.
726</p>
727<ul>
728 <li><code>GOPPC64=power8</code>: generate ISA v2.07 instructions</li>
729 <li><code>GOPPC64=power9</code>: generate ISA v3.00 instructions</li>
730</ul>
731</li>
732
733
734<li><code>$GOWASM</code> (for <code>wasm</code> only)
735 <p>
736 This variable is a comma separated list of <a href="https://github.com/WebAssembly/proposals">experimental WebAssembly features</a> that the compiled WebAssembly binary is allowed to use.
737 The default is to use no experimental features.
738 </p>
739 <ul>
740 <li><code>GOWASM=satconv</code>: generate <a href="https://github.com/WebAssembly/nontrapping-float-to-int-conversions/blob/master/proposals/nontrapping-float-to-int-conversion/Overview.md">saturating (non-trapping) float-to-int conversions</a></li>
741 <li><code>GOWASM=signext</code>: generate <a href="https://github.com/WebAssembly/sign-extension-ops/blob/master/proposals/sign-extension-ops/Overview.md">sign-extension operators</a></li>
742 </ul>
743</li>
744
Colin Cross7bb052a2015-02-03 12:59:37 -0800745</ul>
746
747<p>
748Note that <code>$GOARCH</code> and <code>$GOOS</code> identify the
749<em>target</em> environment, not the environment you are running on.
750In effect, you are always cross-compiling.
751By architecture, we mean the kind of binaries
752that the target environment can run:
753an x86-64 system running a 32-bit-only operating system
754must set <code>GOARCH</code> to <code>386</code>,
755not <code>amd64</code>.
756</p>
757
758<p>
759If you choose to override the defaults,
760set these variables in your shell profile (<code>$HOME/.bashrc</code>,
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800761<code>$HOME/.profile</code>, or equivalent). The settings might look
Colin Cross7bb052a2015-02-03 12:59:37 -0800762something like this:
763</p>
764
765<pre>
Colin Cross7bb052a2015-02-03 12:59:37 -0800766export GOARCH=amd64
767export GOOS=linux
768</pre>
769
770<p>
771although, to reiterate, none of these variables needs to be set to build,
772install, and develop the Go tree.
773</p>