blob: f8cda1dc21114092f8eb6c8f29078f28ae65e4fe [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>
Patrice Arruda1cc20d32020-08-03 23:15:52 +000036The Go compilers support the following instruction sets:
Colin Cross7bb052a2015-02-03 12:59:37 -080037
38<dl>
39<dt>
Patrice Arruda7f4776e2020-06-25 11:55:41 -070040 <code>amd64</code>, <code>386</code>
Colin Cross7bb052a2015-02-03 12:59:37 -080041</dt>
42<dd>
Patrice Arruda7f4776e2020-06-25 11:55:41 -070043 The <code>x86</code> instruction set, 64- and 32-bit.
Colin Cross7bb052a2015-02-03 12:59:37 -080044</dd>
45<dt>
Patrice Arruda7f4776e2020-06-25 11:55:41 -070046 <code>arm64</code>, <code>arm</code>
Colin Cross7bb052a2015-02-03 12:59:37 -080047</dt>
48<dd>
Patrice Arruda7f4776e2020-06-25 11:55:41 -070049 The <code>ARM</code> instruction set, 64-bit (<code>AArch64</code>) and 32-bit.
Colin Cross7bb052a2015-02-03 12:59:37 -080050</dd>
51<dt>
Patrice Arruda1cc20d32020-08-03 23:15:52 +000052 <code>mips64</code>, <code>mips64le</code>, <code>mips</code>, <code>mipsle</code>
53</dt>
54<dd>
55 The <code>MIPS</code> instruction set, big- and little-endian, 64- and 32-bit.
56</dd>
57<dt>
Patrice Arruda7f4776e2020-06-25 11:55:41 -070058 <code>ppc64</code>, <code>ppc64le</code>
Colin Cross7bb052a2015-02-03 12:59:37 -080059</dt>
60<dd>
Patrice Arruda7f4776e2020-06-25 11:55:41 -070061 The 64-bit PowerPC instruction set, big- and little-endian.
Dan Willemsen6ff23252015-09-15 13:49:18 -070062</dd>
63<dt>
Patrice Arruda1cc20d32020-08-03 23:15:52 +000064 <code>riscv64</code>
65</dt>
66<dd>
67 The 64-bit RISC-V instruction set.
68</dd>
69<dt>
Patrice Arruda7f4776e2020-06-25 11:55:41 -070070 <code>s390x</code>
Dan Willemsen6ff23252015-09-15 13:49:18 -070071</dt>
72<dd>
Patrice Arruda7f4776e2020-06-25 11:55:41 -070073 The IBM z/Architecture.
Dan Willemsen6ff23252015-09-15 13:49:18 -070074</dd>
75<dt>
Patrice Arruda7f4776e2020-06-25 11:55:41 -070076 <code>wasm</code>
Dan Willemsenbbdf6642017-01-13 22:57:23 -080077</dt>
78<dd>
Patrice Arruda7f4776e2020-06-25 11:55:41 -070079 <a href="https://webassembly.org">WebAssembly</a>.
Colin Crossefed6342019-09-07 08:34:44 -070080</dd>
Colin Cross7bb052a2015-02-03 12:59:37 -080081</dl>
Colin Cross7bb052a2015-02-03 12:59:37 -080082</p>
83
84<p>
Patrice Arruda7f4776e2020-06-25 11:55:41 -070085The compilers can target the AIX, Android, DragonFly BSD, FreeBSD,
86Illumos, Linux, macOS/iOS (Darwin), NetBSD, OpenBSD, Plan 9, Solaris,
87and Windows operating systems (although not all operating systems
88support all architectures).
89</p>
90
91<p>
92A list of ports which are considered "first class" is available at the
93<a href="/wiki/PortingPolicy#first-class-ports">first class ports</a>
94wiki page.
95</p>
96
97<p>
98The full set of supported combinations is listed in the
99discussion of <a href="#environment">environment variables</a> below.
Colin Cross7bb052a2015-02-03 12:59:37 -0800100</p>
101
Dan Willemsen0c157092016-07-08 13:57:52 -0700102<p>
103See the main installation page for the <a href="/doc/install#requirements">overall system requirements</a>.
104The following additional constraints apply to systems that can be built only from source:
105</p>
106
107<ul>
108<li>For Linux on PowerPC 64-bit, the minimum supported kernel version is 2.6.37, meaning that
109Go does not support CentOS 6 on these systems.
110</li>
111</ul>
112
Colin Cross7bb052a2015-02-03 12:59:37 -0800113</div>
114
Patrice Arruda7f4776e2020-06-25 11:55:41 -0700115<h2 id="go14">Install Go compiler binaries for bootstrap</h2>
Colin Cross7bb052a2015-02-03 12:59:37 -0800116
117<p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800118The Go toolchain is written in Go. To build it, you need a Go compiler installed.
Patrice Arruda7f4776e2020-06-25 11:55:41 -0700119The scripts that do the initial build of the tools look for a "go" command
120in <code>$PATH</code>, so as long as you have Go installed in your
121system and configured in your <code>$PATH</code>, you are ready to build Go
122from source.
123Or if you prefer you can set <code>$GOROOT_BOOTSTRAP</code> to the
124root of a Go installation to use to build the new Go toolchain;
125<code>$GOROOT_BOOTSTRAP/bin/go</code> should be the go command to use.</p>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700126
Colin Crossefed6342019-09-07 08:34:44 -0700127<h3 id="bootstrapFromBinaryRelease">Bootstrap toolchain from binary release</h3>
128
Dan Willemsen6ff23252015-09-15 13:49:18 -0700129<p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800130To use a binary release as a bootstrap toolchain, see
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800131<a href="/dl/">the downloads page</a> or use any other
132packaged Go distribution.
Dan Willemsen6ff23252015-09-15 13:49:18 -0700133</p>
134
Colin Crossefed6342019-09-07 08:34:44 -0700135<h3 id="bootstrapFromSource">Bootstrap toolchain from source</h3>
136
Dan Willemsen6ff23252015-09-15 13:49:18 -0700137<p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800138To build a bootstrap toolchain from source, use
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800139either the git branch <code>release-branch.go1.4</code> or
Dan Willemsene1b3b182018-02-27 19:36:27 -0800140<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 -0800141which contains the Go 1.4 source code plus accumulated fixes
142to keep the tools running on newer operating systems.
Dan Willemsene1b3b182018-02-27 19:36:27 -0800143(Go 1.4 was the last distribution in which the toolchain was written in C.)
Dan Willemsena727cd02017-02-21 17:11:40 -0800144After unpacking the Go 1.4 source, <code>cd</code> to
Dan Willemsene1b3b182018-02-27 19:36:27 -0800145the <code>src</code> subdirectory, set <code>CGO_ENABLED=0</code> in
146the environment, and run <code>make.bash</code> (or,
Dan Willemsena727cd02017-02-21 17:11:40 -0800147on Windows, <code>make.bat</code>).
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800148</p>
149
150<p>
Colin Crossefed6342019-09-07 08:34:44 -0700151Once the Go 1.4 source has been unpacked into your GOROOT_BOOTSTRAP directory,
152you must keep this git clone instance checked out to branch
153<code>release-branch.go1.4</code>. Specifically, do not attempt to reuse
154this git clone in the later step named "Fetch the repository." The go1.4
155bootstrap toolchain <b>must be able</b> to properly traverse the go1.4 sources
156that it assumes are present under this repository root.
157</p>
158
159<h3 id="bootstrapFromCrosscompiledSource">Bootstrap toolchain from cross-compiled source</h3>
160
161<p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800162To cross-compile a bootstrap toolchain from source, which is
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800163necessary on systems Go 1.4 did not target (for
164example, <code>linux/ppc64le</code>), install Go on a different system
165and run <a href="/src/bootstrap.bash">bootstrap.bash</a>.
Dan Willemsen6ff23252015-09-15 13:49:18 -0700166</p>
167
168<p>
169When run as (for example)
170</p>
171
172<pre>
173$ GOOS=linux GOARCH=ppc64 ./bootstrap.bash
174</pre>
175
176<p>
177<code>bootstrap.bash</code> cross-compiles a toolchain for that <code>GOOS/GOARCH</code>
178combination, leaving the resulting tree in <code>../../go-${GOOS}-${GOARCH}-bootstrap</code>.
179That tree can be copied to a machine of the given target type
180and used as <code>GOROOT_BOOTSTRAP</code> to bootstrap a local build.
181</p>
182
Colin Crossefed6342019-09-07 08:34:44 -0700183<h3 id="bootstrapFromGccgo">Bootstrap toolchain using gccgo</h3>
184
Dan Willemsen6ff23252015-09-15 13:49:18 -0700185<p>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800186To use gccgo as the bootstrap toolchain, you need to arrange
187for <code>$GOROOT_BOOTSTRAP/bin/go</code> to be the go tool that comes
188as part of gccgo 5. For example on Ubuntu Vivid:
Dan Willemsen6ff23252015-09-15 13:49:18 -0700189</p>
190
191<pre>
192$ sudo apt-get install gccgo-5
193$ sudo update-alternatives --set go /usr/bin/go-5
194$ GOROOT_BOOTSTRAP=/usr ./make.bash
195</pre>
196
Colin Cross7bb052a2015-02-03 12:59:37 -0800197<h2 id="git">Install Git, if needed</h2>
198
199<p>
200To perform the next step you must have Git installed. (Check that you
201have a <code>git</code> command before proceeding.)
202</p>
203
204<p>
205If you do not have a working Git installation,
206follow the instructions on the
Dan Willemsenf3f2eb62018-08-28 11:28:58 -0700207<a href="https://git-scm.com/downloads">Git downloads</a> page.
Colin Cross7bb052a2015-02-03 12:59:37 -0800208</p>
209
Dan Willemsen0c157092016-07-08 13:57:52 -0700210<h2 id="ccompiler">(Optional) Install a C compiler</h2>
211
212<p>
213To build a Go installation
214with <code><a href="/cmd/cgo">cgo</a></code> support, which permits Go
215programs to import C libraries, a C compiler such as <code>gcc</code>
216or <code>clang</code> must be installed first. Do this using whatever
217installation method is standard on the system.
218</p>
219
220<p>
221To build without <code>cgo</code>, set the environment variable
222<code>CGO_ENABLED=0</code> before running <code>all.bash</code> or
223<code>make.bash</code>.
224</p>
Colin Cross7bb052a2015-02-03 12:59:37 -0800225
226<h2 id="fetch">Fetch the repository</h2>
227
Colin Crossefed6342019-09-07 08:34:44 -0700228<p>Change to the directory where you intend to install Go, and make sure
229the <code>goroot</code> directory does not exist. Then clone the repository
230and check out the latest release tag (<code class="versionTag">go1.12</code>,
231for example):</p>
Colin Cross7bb052a2015-02-03 12:59:37 -0800232
233<pre>
Colin Crossefed6342019-09-07 08:34:44 -0700234$ git clone https://go.googlesource.com/go goroot
235$ cd goroot
Dan Willemsen0c157092016-07-08 13:57:52 -0700236$ git checkout <span class="versionTag"><i>&lt;tag&gt;</i></span>
Colin Cross7bb052a2015-02-03 12:59:37 -0800237</pre>
238
Dan Willemsen0c157092016-07-08 13:57:52 -0700239<p class="whereTag">
240Where <code>&lt;tag&gt;</code> is the version string of the release.
241</p>
242
Colin Crossefed6342019-09-07 08:34:44 -0700243<p>Go will be installed in the directory where it is checked out. For example,
244if Go is checked out in <code>$HOME/goroot</code>, executables will be installed
245in <code>$HOME/goroot/bin</code>. The directory may have any name, but note
246that if Go is checked out in <code>$HOME/go</code>, it will conflict with
247the default location of <code>$GOPATH</code>.
248See <a href="#gopath"><code>GOPATH</code></a> below.</p>
249
Patrice Arruda7f4776e2020-06-25 11:55:41 -0700250<p>
Colin Crossefed6342019-09-07 08:34:44 -0700251Reminder: If you opted to also compile the bootstrap binaries from source (in an
252earlier section), you still need to <code>git clone</code> again at this point
253(to checkout the latest <code>&lt;tag&gt;</code>), because you must keep your
254go1.4 repository distinct.
Patrice Arruda7f4776e2020-06-25 11:55:41 -0700255</p>
Colin Crossefed6342019-09-07 08:34:44 -0700256
Colin Cross7bb052a2015-02-03 12:59:37 -0800257<h2 id="head">(Optional) Switch to the master branch</h2>
258
259<p>If you intend to modify the go source code, and
260<a href="/doc/contribute.html">contribute your changes</a>
261to the project, then move your repository
262off the release branch, and onto the master (development) branch.
263Otherwise, skip this step.</p>
264
265<pre>
266$ git checkout master
267</pre>
268
269<h2 id="install">Install Go</h2>
270
271<p>
272To build the Go distribution, run
273</p>
274
275<pre>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700276$ cd src
Colin Cross7bb052a2015-02-03 12:59:37 -0800277$ ./all.bash
278</pre>
279
280<p>
281(To build under Windows use <code>all.bat</code>.)
282</p>
283
284<p>
285If all goes well, it will finish by printing output like:
286</p>
287
288<pre>
289ALL TESTS PASSED
290
291---
292Installed Go for linux/amd64 in /home/you/go.
293Installed commands in /home/you/go/bin.
294*** You need to add /home/you/go/bin to your $PATH. ***
295</pre>
296
297<p>
298where the details on the last few lines reflect the operating system,
299architecture, and root directory used during the install.
300</p>
301
302<div class="detail">
303<p>
304For more information about ways to control the build, see the discussion of
305<a href="#environment">environment variables</a> below.
306<code>all.bash</code> (or <code>all.bat</code>) runs important tests for Go,
307which can take more time than simply building Go. If you do not want to run
308the test suite use <code>make.bash</code> (or <code>make.bat</code>)
309instead.
310</p>
311</div>
312
313
314<h2 id="testing">Testing your installation</h2>
315
316<p>
317Check that Go is installed correctly by building a simple program.
318</p>
319
320<p>
321Create a file named <code>hello.go</code> and put the following program in it:
322</p>
323
324<pre>
325package main
326
327import "fmt"
328
329func main() {
Dan Willemsenf3f2eb62018-08-28 11:28:58 -0700330 fmt.Printf("hello, world\n")
Colin Cross7bb052a2015-02-03 12:59:37 -0800331}
332</pre>
333
334<p>
335Then run it with the <code>go</code> tool:
336</p>
337
338<pre>
339$ go run hello.go
340hello, world
341</pre>
342
343<p>
344If you see the "hello, world" message then Go is installed correctly.
345</p>
346
347<h2 id="gopath">Set up your work environment</h2>
348
349<p>
350You're almost done.
351You just need to do a little more setup.
352</p>
353
354<p>
355<a href="/doc/code.html" class="download" id="start">
356<span class="big">How to Write Go Code</span>
357<span class="desc">Learn how to set up and use the Go tools</span>
358</a>
359</p>
360
361<p>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800362The <a href="/doc/code.html">How to Write Go Code</a> document
Colin Cross7bb052a2015-02-03 12:59:37 -0800363provides <b>essential setup instructions</b> for using the Go tools.
364</p>
365
366
367<h2 id="tools">Install additional tools</h2>
368
369<p>
370The source code for several Go tools (including <a href="/cmd/godoc/">godoc</a>)
371is kept in <a href="https://golang.org/x/tools">the go.tools repository</a>.
Colin Cross1371fe42019-03-19 21:08:48 -0700372To install one of the tools (<code>godoc</code> in this case):
Colin Cross7bb052a2015-02-03 12:59:37 -0800373</p>
374
375<pre>
376$ go get golang.org/x/tools/cmd/godoc
377</pre>
378
379<p>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800380To install these tools, the <code>go</code> <code>get</code> command requires
Colin Cross7bb052a2015-02-03 12:59:37 -0800381that <a href="#git">Git</a> be installed locally.
382</p>
383
384<p>
385You must also have a workspace (<code>GOPATH</code>) set up;
386see <a href="/doc/code.html">How to Write Go Code</a> for the details.
387</p>
388
Colin Cross7bb052a2015-02-03 12:59:37 -0800389<h2 id="community">Community resources</h2>
390
391<p>
392The usual community resources such as
Dan Willemsenf3f2eb62018-08-28 11:28:58 -0700393<code>#go-nuts</code> on the <a href="https://freenode.net/">Freenode</a> IRC server
Colin Cross7bb052a2015-02-03 12:59:37 -0800394and the
395<a href="//groups.google.com/group/golang-nuts">Go Nuts</a>
396mailing list have active developers that can help you with problems
397with your installation or your development work.
398For those who wish to keep up to date,
399there is another mailing list, <a href="//groups.google.com/group/golang-checkins">golang-checkins</a>,
400that receives a message summarizing each checkin to the Go repository.
401</p>
402
403<p>
404Bugs can be reported using the <a href="//golang.org/issue/new">Go issue tracker</a>.
405</p>
406
407
408<h2 id="releases">Keeping up with releases</h2>
409
410<p>
411New releases are announced on the
412<a href="//groups.google.com/group/golang-announce">golang-announce</a>
413mailing list.
414Each announcement mentions the latest release tag, for instance,
Dan Willemsencc0b9f52017-08-25 11:20:05 -0700415<code class="versionTag">go1.9</code>.
Colin Cross7bb052a2015-02-03 12:59:37 -0800416</p>
417
418<p>
419To update an existing tree to the latest release, you can run:
420</p>
421
422<pre>
423$ cd go/src
424$ git fetch
Dan Willemsen0c157092016-07-08 13:57:52 -0700425$ git checkout <span class="versionTag"><i>&lt;tag&gt;</i></psan>
Colin Cross7bb052a2015-02-03 12:59:37 -0800426$ ./all.bash
427</pre>
428
Dan Willemsen0c157092016-07-08 13:57:52 -0700429<p class="whereTag">
Colin Cross7bb052a2015-02-03 12:59:37 -0800430Where <code>&lt;tag&gt;</code> is the version string of the release.
Dan Willemsen0c157092016-07-08 13:57:52 -0700431</p>
Colin Cross7bb052a2015-02-03 12:59:37 -0800432
433
434<h2 id="environment">Optional environment variables</h2>
435
436<p>
437The Go compilation environment can be customized by environment variables.
438<i>None is required by the build</i>, but you may wish to set some
439to override the defaults.
440</p>
441
442<ul>
443<li><code>$GOROOT</code>
444<p>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800445The root of the Go tree, often <code>$HOME/go1.X</code>.
Colin Cross7bb052a2015-02-03 12:59:37 -0800446Its value is built into the tree when it is compiled, and
447defaults to the parent of the directory where <code>all.bash</code> was run.
448There is no need to set this unless you want to switch between multiple
449local copies of the repository.
450</p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800451</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800452
453<li><code>$GOROOT_FINAL</code>
454<p>
455The value assumed by installed binaries and scripts when
456<code>$GOROOT</code> is not set explicitly.
457It defaults to the value of <code>$GOROOT</code>.
458If you want to build the Go tree in one location
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800459but move it elsewhere after the build, set
Colin Cross7bb052a2015-02-03 12:59:37 -0800460<code>$GOROOT_FINAL</code> to the eventual location.
461</p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800462</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800463
Colin Crossefed6342019-09-07 08:34:44 -0700464<li id="gopath"><code>$GOPATH</code>
465<p>
466The directory where Go projects outside the Go distribution are typically
467checked out. For example, <code>golang.org/x/tools</code> might be checked out
468to <code>$GOPATH/src/golang.org/x/tools</code>. Executables outside the
469Go distribution are installed in <code>$GOPATH/bin</code> (or
470<code>$GOBIN</code>, if set). Modules are downloaded and cached in
471<code>$GOPATH/pkg/mod</code>.
472</p>
473
474<p>The default location of <code>$GOPATH</code> is <code>$HOME/go</code>,
475and it's not usually necessary to set <code>GOPATH</code> explicitly. However,
476if you have checked out the Go distribution to <code>$HOME/go</code>,
477you must set <code>GOPATH</code> to another location to avoid conflicts.
478</p>
479</li>
480
481<li><code>$GOBIN</code>
482<p>
483The directory where executables outside the Go distribution are installed
484using the <a href="/cmd/go">go command</a>. For example,
485<code>go get golang.org/x/tools/cmd/godoc</code> downloads, builds, and
486installs <code>$GOBIN/godoc</code>. By default, <code>$GOBIN</code> is
487<code>$GOPATH/bin</code> (or <code>$HOME/go/bin</code> if <code>GOPATH</code>
488is not set). After installing, you will want to add this directory to
489your <code>$PATH</code> so you can use installed tools.
490</p>
491
492<p>
493Note that the Go distribution's executables are installed in
494<code>$GOROOT/bin</code> (for executables invoked by people) or
495<code>$GOTOOLDIR</code> (for executables invoked by the go command;
496defaults to <code>$GOROOT/pkg/$GOOS_GOARCH</code>) instead of
497<code>$GOBIN</code>.
498</p>
499</li>
500
Colin Cross7bb052a2015-02-03 12:59:37 -0800501<li><code>$GOOS</code> and <code>$GOARCH</code>
502<p>
503The name of the target operating system and compilation architecture.
504These default to the values of <code>$GOHOSTOS</code> and
505<code>$GOHOSTARCH</code> respectively (described below).
Dan Willemsene1b3b182018-02-27 19:36:27 -0800506</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800507
508<p>
509Choices for <code>$GOOS</code> are
Patrice Arruda7f4776e2020-06-25 11:55:41 -0700510<code>android</code>, <code>darwin</code> (macOS/iOS),
Colin Crossefed6342019-09-07 08:34:44 -0700511<code>dragonfly</code>, <code>freebsd</code>, <code>illumos</code>, <code>js</code>,
Dan Willemsen6ff23252015-09-15 13:49:18 -0700512<code>linux</code>, <code>netbsd</code>, <code>openbsd</code>,
Colin Cross7bb052a2015-02-03 12:59:37 -0800513<code>plan9</code>, <code>solaris</code> and <code>windows</code>.
Colin Crossefed6342019-09-07 08:34:44 -0700514</p>
515
516<p>
Colin Cross7bb052a2015-02-03 12:59:37 -0800517Choices for <code>$GOARCH</code> are
518<code>amd64</code> (64-bit x86, the most mature port),
Dan Willemsen6ff23252015-09-15 13:49:18 -0700519<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 -0700520<code>ppc64le</code> (PowerPC 64-bit, little-endian), <code>ppc64</code> (PowerPC 64-bit, big-endian),
Dan Willemsene1b3b182018-02-27 19:36:27 -0800521<code>mips64le</code> (MIPS 64-bit, little-endian), <code>mips64</code> (MIPS 64-bit, big-endian),
Colin Crossefed6342019-09-07 08:34:44 -0700522<code>mipsle</code> (MIPS 32-bit, little-endian), <code>mips</code> (MIPS 32-bit, big-endian),
523<code>s390x</code> (IBM System z 64-bit, big-endian), and
524<code>wasm</code> (WebAssembly 32-bit).
525</p>
526
527<p>
Colin Cross7bb052a2015-02-03 12:59:37 -0800528The valid combinations of <code>$GOOS</code> and <code>$GOARCH</code> are:
529<table cellpadding="0">
530<tr>
531<th width="50"></th><th align="left" width="100"><code>$GOOS</code></th> <th align="left" width="100"><code>$GOARCH</code></th>
532</tr>
533<tr>
Colin Crossefed6342019-09-07 08:34:44 -0700534<td></td><td><code>aix</code></td> <td><code>ppc64</code></td>
535</tr>
536<tr>
537<td></td><td><code>android</code></td> <td><code>386</code></td>
538</tr>
539<tr>
540<td></td><td><code>android</code></td> <td><code>amd64</code></td>
541</tr>
542<tr>
Dan Willemsen0c157092016-07-08 13:57:52 -0700543<td></td><td><code>android</code></td> <td><code>arm</code></td>
544</tr>
545<tr>
Colin Crossefed6342019-09-07 08:34:44 -0700546<td></td><td><code>android</code></td> <td><code>arm64</code></td>
547</tr>
548<tr>
Colin Cross7bb052a2015-02-03 12:59:37 -0800549<td></td><td><code>darwin</code></td> <td><code>amd64</code></td>
550</tr>
551<tr>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700552<td></td><td><code>darwin</code></td> <td><code>arm64</code></td>
Colin Cross7bb052a2015-02-03 12:59:37 -0800553</tr>
554<tr>
555<td></td><td><code>dragonfly</code></td> <td><code>amd64</code></td>
556</tr>
557<tr>
558<td></td><td><code>freebsd</code></td> <td><code>386</code></td>
559</tr>
560<tr>
561<td></td><td><code>freebsd</code></td> <td><code>amd64</code></td>
562</tr>
563<tr>
564<td></td><td><code>freebsd</code></td> <td><code>arm</code></td>
565</tr>
566<tr>
Colin Crossefed6342019-09-07 08:34:44 -0700567<td></td><td><code>illumos</code></td> <td><code>amd64</code></td>
568</tr>
569<tr>
570<td></td><td><code>js</code></td> <td><code>wasm</code></td>
571</tr>
572<tr>
Colin Cross7bb052a2015-02-03 12:59:37 -0800573<td></td><td><code>linux</code></td> <td><code>386</code></td>
574</tr>
575<tr>
576<td></td><td><code>linux</code></td> <td><code>amd64</code></td>
577</tr>
578<tr>
579<td></td><td><code>linux</code></td> <td><code>arm</code></td>
580</tr>
581<tr>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700582<td></td><td><code>linux</code></td> <td><code>arm64</code></td>
583</tr>
584<tr>
585<td></td><td><code>linux</code></td> <td><code>ppc64</code></td>
586</tr>
587<tr>
588<td></td><td><code>linux</code></td> <td><code>ppc64le</code></td>
589</tr>
590<tr>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800591<td></td><td><code>linux</code></td> <td><code>mips</code></td>
592</tr>
593<tr>
594<td></td><td><code>linux</code></td> <td><code>mipsle</code></td>
595</tr>
596<tr>
Dan Willemsen0c157092016-07-08 13:57:52 -0700597<td></td><td><code>linux</code></td> <td><code>mips64</code></td>
598</tr>
599<tr>
600<td></td><td><code>linux</code></td> <td><code>mips64le</code></td>
601</tr>
602<tr>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800603<td></td><td><code>linux</code></td> <td><code>s390x</code></td>
604</tr>
605<tr>
Colin Cross7bb052a2015-02-03 12:59:37 -0800606<td></td><td><code>netbsd</code></td> <td><code>386</code></td>
607</tr>
608<tr>
609<td></td><td><code>netbsd</code></td> <td><code>amd64</code></td>
610</tr>
611<tr>
612<td></td><td><code>netbsd</code></td> <td><code>arm</code></td>
613</tr>
614<tr>
615<td></td><td><code>openbsd</code></td> <td><code>386</code></td>
616</tr>
617<tr>
618<td></td><td><code>openbsd</code></td> <td><code>amd64</code></td>
619</tr>
620<tr>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700621<td></td><td><code>openbsd</code></td> <td><code>arm</code></td>
622</tr>
623<tr>
Colin Crossefed6342019-09-07 08:34:44 -0700624<td></td><td><code>openbsd</code></td> <td><code>arm64</code></td>
625</tr>
626<tr>
Colin Cross7bb052a2015-02-03 12:59:37 -0800627<td></td><td><code>plan9</code></td> <td><code>386</code></td>
628</tr>
629<tr>
630<td></td><td><code>plan9</code></td> <td><code>amd64</code></td>
631</tr>
632<tr>
Colin Crossefed6342019-09-07 08:34:44 -0700633<td></td><td><code>plan9</code></td> <td><code>arm</code></td>
634</tr>
635<tr>
Colin Cross7bb052a2015-02-03 12:59:37 -0800636<td></td><td><code>solaris</code></td> <td><code>amd64</code></td>
637</tr>
638<tr>
639<td></td><td><code>windows</code></td> <td><code>386</code></td>
640</tr>
641<tr>
642<td></td><td><code>windows</code></td> <td><code>amd64</code></td>
643</tr>
644</table>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700645<br>
Colin Cross7bb052a2015-02-03 12:59:37 -0800646
647<li><code>$GOHOSTOS</code> and <code>$GOHOSTARCH</code>
648<p>
649The name of the host operating system and compilation architecture.
650These default to the local system's operating system and
651architecture.
652</p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800653</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800654
655<p>
656Valid choices are the same as for <code>$GOOS</code> and
657<code>$GOARCH</code>, listed above.
658The specified values must be compatible with the local system.
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800659For example, you should not set <code>$GOHOSTARCH</code> to
Colin Cross7bb052a2015-02-03 12:59:37 -0800660<code>arm</code> on an x86 system.
661</p>
662
Colin Cross7bb052a2015-02-03 12:59:37 -0800663<li><code>$GO386</code> (for <code>386</code> only, default is auto-detected
664if built on either <code>386</code> or <code>amd64</code>, <code>387</code> otherwise)
665<p>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700666This controls the code generated by gc to use either the 387 floating-point unit
Colin Cross7bb052a2015-02-03 12:59:37 -0800667(set to <code>387</code>) or SSE2 instructions (set to <code>sse2</code>) for
668floating point computations.
669</p>
670<ul>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800671 <li><code>GO386=387</code>: use x87 for floating point operations; should support all x86 chips (Pentium MMX or later).</li>
672 <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 -0800673</ul>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800674</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800675
676<li><code>$GOARM</code> (for <code>arm</code> only; default is auto-detected if building
677on the target processor, 6 if not)
678<p>
679This sets the ARM floating point co-processor architecture version the run-time
680should target. If you are compiling on the target system, its value will be auto-detected.
681</p>
682<ul>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800683 <li><code>GOARM=5</code>: use software floating point; when CPU doesn't have VFP co-processor</li>
684 <li><code>GOARM=6</code>: use VFPv1 only; default if cross compiling; usually ARM11 or better cores (VFPv2 or better is also supported)</li>
685 <li><code>GOARM=7</code>: use VFPv3; usually Cortex-A cores</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800686</ul>
687<p>
688If in doubt, leave this variable unset, and adjust it if required
689when you first run the Go executable.
690The <a href="//golang.org/wiki/GoArm">GoARM</a> page
691on the <a href="//golang.org/wiki">Go community wiki</a>
692contains further details regarding Go's ARM support.
693</p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800694</li>
695
Colin Cross1371fe42019-03-19 21:08:48 -0700696<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 -0800697<p>
Colin Cross1371fe42019-03-19 21:08:48 -0700698 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 -0800699</p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800700</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800701
Colin Crossefed6342019-09-07 08:34:44 -0700702<li><code>$GOPPC64</code> (for <code>ppc64</code> and <code>ppc64le</code> only)
703<p>
704This variable sets the processor level (i.e. Instruction Set Architecture version)
705for which the compiler will target. The default is <code>power8</code>.
706</p>
707<ul>
708 <li><code>GOPPC64=power8</code>: generate ISA v2.07 instructions</li>
709 <li><code>GOPPC64=power9</code>: generate ISA v3.00 instructions</li>
710</ul>
711</li>
712
713
714<li><code>$GOWASM</code> (for <code>wasm</code> only)
715 <p>
716 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.
717 The default is to use no experimental features.
718 </p>
719 <ul>
720 <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>
721 <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>
722 </ul>
723</li>
724
Colin Cross7bb052a2015-02-03 12:59:37 -0800725</ul>
726
727<p>
728Note that <code>$GOARCH</code> and <code>$GOOS</code> identify the
729<em>target</em> environment, not the environment you are running on.
730In effect, you are always cross-compiling.
731By architecture, we mean the kind of binaries
732that the target environment can run:
733an x86-64 system running a 32-bit-only operating system
734must set <code>GOARCH</code> to <code>386</code>,
735not <code>amd64</code>.
736</p>
737
738<p>
739If you choose to override the defaults,
740set these variables in your shell profile (<code>$HOME/.bashrc</code>,
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800741<code>$HOME/.profile</code>, or equivalent). The settings might look
Colin Cross7bb052a2015-02-03 12:59:37 -0800742something like this:
743</p>
744
745<pre>
Colin Cross7bb052a2015-02-03 12:59:37 -0800746export GOARCH=amd64
747export GOOS=linux
748</pre>
749
750<p>
751although, to reiterate, none of these variables needs to be set to build,
752install, and develop the Go tree.
753</p>