blob: b5b422ea111901fa1cf7580cb5d90a93a2a74779 [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 Arruda7f4776e2020-06-25 11:55:41 -070036The Go compilers support twelve 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 Arruda7f4776e2020-06-25 11:55:41 -070052 <code>ppc64</code>, <code>ppc64le</code>
Colin Cross7bb052a2015-02-03 12:59:37 -080053</dt>
54<dd>
Patrice Arruda7f4776e2020-06-25 11:55:41 -070055 The 64-bit PowerPC instruction set, big- and little-endian.
Dan Willemsen6ff23252015-09-15 13:49:18 -070056</dd>
57<dt>
Patrice Arruda7f4776e2020-06-25 11:55:41 -070058 <code>s390x</code>
Dan Willemsen6ff23252015-09-15 13:49:18 -070059</dt>
60<dd>
Patrice Arruda7f4776e2020-06-25 11:55:41 -070061 The IBM z/Architecture.
Dan Willemsen6ff23252015-09-15 13:49:18 -070062</dd>
63<dt>
Patrice Arruda7f4776e2020-06-25 11:55:41 -070064 <code>mips64</code>, <code>mips64le</code>, <code>mips</code>, <code>mipsle</code>
Dan Willemsen6ff23252015-09-15 13:49:18 -070065</dt>
66<dd>
Patrice Arruda7f4776e2020-06-25 11:55:41 -070067 The <code>MIPS</code> instruction set, big- and little-endian, 64- and 32-bit.
Dan Willemsen0c157092016-07-08 13:57:52 -070068</dd>
69<dt>
Patrice Arruda7f4776e2020-06-25 11:55:41 -070070 <code>wasm</code>
Dan Willemsenbbdf6642017-01-13 22:57:23 -080071</dt>
72<dd>
Patrice Arruda7f4776e2020-06-25 11:55:41 -070073 <a href="https://webassembly.org">WebAssembly</a>.
Colin Crossefed6342019-09-07 08:34:44 -070074</dd>
Colin Cross7bb052a2015-02-03 12:59:37 -080075</dl>
Colin Cross7bb052a2015-02-03 12:59:37 -080076</p>
77
78<p>
Patrice Arruda7f4776e2020-06-25 11:55:41 -070079The compilers can target the AIX, Android, DragonFly BSD, FreeBSD,
80Illumos, Linux, macOS/iOS (Darwin), NetBSD, OpenBSD, Plan 9, Solaris,
81and Windows operating systems (although not all operating systems
82support all architectures).
83</p>
84
85<p>
86A list of ports which are considered "first class" is available at the
87<a href="/wiki/PortingPolicy#first-class-ports">first class ports</a>
88wiki page.
89</p>
90
91<p>
92The full set of supported combinations is listed in the
93discussion of <a href="#environment">environment variables</a> below.
Colin Cross7bb052a2015-02-03 12:59:37 -080094</p>
95
Dan Willemsen0c157092016-07-08 13:57:52 -070096<p>
97See the main installation page for the <a href="/doc/install#requirements">overall system requirements</a>.
98The following additional constraints apply to systems that can be built only from source:
99</p>
100
101<ul>
102<li>For Linux on PowerPC 64-bit, the minimum supported kernel version is 2.6.37, meaning that
103Go does not support CentOS 6 on these systems.
104</li>
105</ul>
106
Colin Cross7bb052a2015-02-03 12:59:37 -0800107</div>
108
Patrice Arruda7f4776e2020-06-25 11:55:41 -0700109<h2 id="go14">Install Go compiler binaries for bootstrap</h2>
Colin Cross7bb052a2015-02-03 12:59:37 -0800110
111<p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800112The Go toolchain is written in Go. To build it, you need a Go compiler installed.
Patrice Arruda7f4776e2020-06-25 11:55:41 -0700113The scripts that do the initial build of the tools look for a "go" command
114in <code>$PATH</code>, so as long as you have Go installed in your
115system and configured in your <code>$PATH</code>, you are ready to build Go
116from source.
117Or if you prefer you can set <code>$GOROOT_BOOTSTRAP</code> to the
118root of a Go installation to use to build the new Go toolchain;
119<code>$GOROOT_BOOTSTRAP/bin/go</code> should be the go command to use.</p>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700120
Colin Crossefed6342019-09-07 08:34:44 -0700121<h3 id="bootstrapFromBinaryRelease">Bootstrap toolchain from binary release</h3>
122
Dan Willemsen6ff23252015-09-15 13:49:18 -0700123<p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800124To use a binary release as a bootstrap toolchain, see
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800125<a href="/dl/">the downloads page</a> or use any other
126packaged Go distribution.
Dan Willemsen6ff23252015-09-15 13:49:18 -0700127</p>
128
Colin Crossefed6342019-09-07 08:34:44 -0700129<h3 id="bootstrapFromSource">Bootstrap toolchain from source</h3>
130
Dan Willemsen6ff23252015-09-15 13:49:18 -0700131<p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800132To build a bootstrap toolchain from source, use
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800133either the git branch <code>release-branch.go1.4</code> or
Dan Willemsene1b3b182018-02-27 19:36:27 -0800134<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 -0800135which contains the Go 1.4 source code plus accumulated fixes
136to keep the tools running on newer operating systems.
Dan Willemsene1b3b182018-02-27 19:36:27 -0800137(Go 1.4 was the last distribution in which the toolchain was written in C.)
Dan Willemsena727cd02017-02-21 17:11:40 -0800138After unpacking the Go 1.4 source, <code>cd</code> to
Dan Willemsene1b3b182018-02-27 19:36:27 -0800139the <code>src</code> subdirectory, set <code>CGO_ENABLED=0</code> in
140the environment, and run <code>make.bash</code> (or,
Dan Willemsena727cd02017-02-21 17:11:40 -0800141on Windows, <code>make.bat</code>).
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800142</p>
143
144<p>
Colin Crossefed6342019-09-07 08:34:44 -0700145Once the Go 1.4 source has been unpacked into your GOROOT_BOOTSTRAP directory,
146you must keep this git clone instance checked out to branch
147<code>release-branch.go1.4</code>. Specifically, do not attempt to reuse
148this git clone in the later step named "Fetch the repository." The go1.4
149bootstrap toolchain <b>must be able</b> to properly traverse the go1.4 sources
150that it assumes are present under this repository root.
151</p>
152
153<h3 id="bootstrapFromCrosscompiledSource">Bootstrap toolchain from cross-compiled source</h3>
154
155<p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800156To cross-compile a bootstrap toolchain from source, which is
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800157necessary on systems Go 1.4 did not target (for
158example, <code>linux/ppc64le</code>), install Go on a different system
159and run <a href="/src/bootstrap.bash">bootstrap.bash</a>.
Dan Willemsen6ff23252015-09-15 13:49:18 -0700160</p>
161
162<p>
163When run as (for example)
164</p>
165
166<pre>
167$ GOOS=linux GOARCH=ppc64 ./bootstrap.bash
168</pre>
169
170<p>
171<code>bootstrap.bash</code> cross-compiles a toolchain for that <code>GOOS/GOARCH</code>
172combination, leaving the resulting tree in <code>../../go-${GOOS}-${GOARCH}-bootstrap</code>.
173That tree can be copied to a machine of the given target type
174and used as <code>GOROOT_BOOTSTRAP</code> to bootstrap a local build.
175</p>
176
Colin Crossefed6342019-09-07 08:34:44 -0700177<h3 id="bootstrapFromGccgo">Bootstrap toolchain using gccgo</h3>
178
Dan Willemsen6ff23252015-09-15 13:49:18 -0700179<p>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800180To use gccgo as the bootstrap toolchain, you need to arrange
181for <code>$GOROOT_BOOTSTRAP/bin/go</code> to be the go tool that comes
182as part of gccgo 5. For example on Ubuntu Vivid:
Dan Willemsen6ff23252015-09-15 13:49:18 -0700183</p>
184
185<pre>
186$ sudo apt-get install gccgo-5
187$ sudo update-alternatives --set go /usr/bin/go-5
188$ GOROOT_BOOTSTRAP=/usr ./make.bash
189</pre>
190
Colin Cross7bb052a2015-02-03 12:59:37 -0800191<h2 id="git">Install Git, if needed</h2>
192
193<p>
194To perform the next step you must have Git installed. (Check that you
195have a <code>git</code> command before proceeding.)
196</p>
197
198<p>
199If you do not have a working Git installation,
200follow the instructions on the
Dan Willemsenf3f2eb62018-08-28 11:28:58 -0700201<a href="https://git-scm.com/downloads">Git downloads</a> page.
Colin Cross7bb052a2015-02-03 12:59:37 -0800202</p>
203
Dan Willemsen0c157092016-07-08 13:57:52 -0700204<h2 id="ccompiler">(Optional) Install a C compiler</h2>
205
206<p>
207To build a Go installation
208with <code><a href="/cmd/cgo">cgo</a></code> support, which permits Go
209programs to import C libraries, a C compiler such as <code>gcc</code>
210or <code>clang</code> must be installed first. Do this using whatever
211installation method is standard on the system.
212</p>
213
214<p>
215To build without <code>cgo</code>, set the environment variable
216<code>CGO_ENABLED=0</code> before running <code>all.bash</code> or
217<code>make.bash</code>.
218</p>
Colin Cross7bb052a2015-02-03 12:59:37 -0800219
220<h2 id="fetch">Fetch the repository</h2>
221
Colin Crossefed6342019-09-07 08:34:44 -0700222<p>Change to the directory where you intend to install Go, and make sure
223the <code>goroot</code> directory does not exist. Then clone the repository
224and check out the latest release tag (<code class="versionTag">go1.12</code>,
225for example):</p>
Colin Cross7bb052a2015-02-03 12:59:37 -0800226
227<pre>
Colin Crossefed6342019-09-07 08:34:44 -0700228$ git clone https://go.googlesource.com/go goroot
229$ cd goroot
Dan Willemsen0c157092016-07-08 13:57:52 -0700230$ git checkout <span class="versionTag"><i>&lt;tag&gt;</i></span>
Colin Cross7bb052a2015-02-03 12:59:37 -0800231</pre>
232
Dan Willemsen0c157092016-07-08 13:57:52 -0700233<p class="whereTag">
234Where <code>&lt;tag&gt;</code> is the version string of the release.
235</p>
236
Colin Crossefed6342019-09-07 08:34:44 -0700237<p>Go will be installed in the directory where it is checked out. For example,
238if Go is checked out in <code>$HOME/goroot</code>, executables will be installed
239in <code>$HOME/goroot/bin</code>. The directory may have any name, but note
240that if Go is checked out in <code>$HOME/go</code>, it will conflict with
241the default location of <code>$GOPATH</code>.
242See <a href="#gopath"><code>GOPATH</code></a> below.</p>
243
Patrice Arruda7f4776e2020-06-25 11:55:41 -0700244<p>
Colin Crossefed6342019-09-07 08:34:44 -0700245Reminder: If you opted to also compile the bootstrap binaries from source (in an
246earlier section), you still need to <code>git clone</code> again at this point
247(to checkout the latest <code>&lt;tag&gt;</code>), because you must keep your
248go1.4 repository distinct.
Patrice Arruda7f4776e2020-06-25 11:55:41 -0700249</p>
Colin Crossefed6342019-09-07 08:34:44 -0700250
Colin Cross7bb052a2015-02-03 12:59:37 -0800251<h2 id="head">(Optional) Switch to the master branch</h2>
252
253<p>If you intend to modify the go source code, and
254<a href="/doc/contribute.html">contribute your changes</a>
255to the project, then move your repository
256off the release branch, and onto the master (development) branch.
257Otherwise, skip this step.</p>
258
259<pre>
260$ git checkout master
261</pre>
262
263<h2 id="install">Install Go</h2>
264
265<p>
266To build the Go distribution, run
267</p>
268
269<pre>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700270$ cd src
Colin Cross7bb052a2015-02-03 12:59:37 -0800271$ ./all.bash
272</pre>
273
274<p>
275(To build under Windows use <code>all.bat</code>.)
276</p>
277
278<p>
279If all goes well, it will finish by printing output like:
280</p>
281
282<pre>
283ALL TESTS PASSED
284
285---
286Installed Go for linux/amd64 in /home/you/go.
287Installed commands in /home/you/go/bin.
288*** You need to add /home/you/go/bin to your $PATH. ***
289</pre>
290
291<p>
292where the details on the last few lines reflect the operating system,
293architecture, and root directory used during the install.
294</p>
295
296<div class="detail">
297<p>
298For more information about ways to control the build, see the discussion of
299<a href="#environment">environment variables</a> below.
300<code>all.bash</code> (or <code>all.bat</code>) runs important tests for Go,
301which can take more time than simply building Go. If you do not want to run
302the test suite use <code>make.bash</code> (or <code>make.bat</code>)
303instead.
304</p>
305</div>
306
307
308<h2 id="testing">Testing your installation</h2>
309
310<p>
311Check that Go is installed correctly by building a simple program.
312</p>
313
314<p>
315Create a file named <code>hello.go</code> and put the following program in it:
316</p>
317
318<pre>
319package main
320
321import "fmt"
322
323func main() {
Dan Willemsenf3f2eb62018-08-28 11:28:58 -0700324 fmt.Printf("hello, world\n")
Colin Cross7bb052a2015-02-03 12:59:37 -0800325}
326</pre>
327
328<p>
329Then run it with the <code>go</code> tool:
330</p>
331
332<pre>
333$ go run hello.go
334hello, world
335</pre>
336
337<p>
338If you see the "hello, world" message then Go is installed correctly.
339</p>
340
341<h2 id="gopath">Set up your work environment</h2>
342
343<p>
344You're almost done.
345You just need to do a little more setup.
346</p>
347
348<p>
349<a href="/doc/code.html" class="download" id="start">
350<span class="big">How to Write Go Code</span>
351<span class="desc">Learn how to set up and use the Go tools</span>
352</a>
353</p>
354
355<p>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800356The <a href="/doc/code.html">How to Write Go Code</a> document
Colin Cross7bb052a2015-02-03 12:59:37 -0800357provides <b>essential setup instructions</b> for using the Go tools.
358</p>
359
360
361<h2 id="tools">Install additional tools</h2>
362
363<p>
364The source code for several Go tools (including <a href="/cmd/godoc/">godoc</a>)
365is kept in <a href="https://golang.org/x/tools">the go.tools repository</a>.
Colin Cross1371fe42019-03-19 21:08:48 -0700366To install one of the tools (<code>godoc</code> in this case):
Colin Cross7bb052a2015-02-03 12:59:37 -0800367</p>
368
369<pre>
370$ go get golang.org/x/tools/cmd/godoc
371</pre>
372
373<p>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800374To install these tools, the <code>go</code> <code>get</code> command requires
Colin Cross7bb052a2015-02-03 12:59:37 -0800375that <a href="#git">Git</a> be installed locally.
376</p>
377
378<p>
379You must also have a workspace (<code>GOPATH</code>) set up;
380see <a href="/doc/code.html">How to Write Go Code</a> for the details.
381</p>
382
Colin Cross7bb052a2015-02-03 12:59:37 -0800383<h2 id="community">Community resources</h2>
384
385<p>
386The usual community resources such as
Dan Willemsenf3f2eb62018-08-28 11:28:58 -0700387<code>#go-nuts</code> on the <a href="https://freenode.net/">Freenode</a> IRC server
Colin Cross7bb052a2015-02-03 12:59:37 -0800388and 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 Willemsencc0b9f52017-08-25 11:20:05 -0700409<code class="versionTag">go1.9</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>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800445</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800446
447<li><code>$GOROOT_FINAL</code>
448<p>
449The value assumed by installed binaries and scripts when
450<code>$GOROOT</code> is not set explicitly.
451It defaults to the value of <code>$GOROOT</code>.
452If you want to build the Go tree in one location
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800453but move it elsewhere after the build, set
Colin Cross7bb052a2015-02-03 12:59:37 -0800454<code>$GOROOT_FINAL</code> to the eventual location.
455</p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800456</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800457
Colin Crossefed6342019-09-07 08:34:44 -0700458<li id="gopath"><code>$GOPATH</code>
459<p>
460The directory where Go projects outside the Go distribution are typically
461checked out. For example, <code>golang.org/x/tools</code> might be checked out
462to <code>$GOPATH/src/golang.org/x/tools</code>. Executables outside the
463Go distribution are installed in <code>$GOPATH/bin</code> (or
464<code>$GOBIN</code>, if set). Modules are downloaded and cached in
465<code>$GOPATH/pkg/mod</code>.
466</p>
467
468<p>The default location of <code>$GOPATH</code> is <code>$HOME/go</code>,
469and it's not usually necessary to set <code>GOPATH</code> explicitly. However,
470if you have checked out the Go distribution to <code>$HOME/go</code>,
471you must set <code>GOPATH</code> to another location to avoid conflicts.
472</p>
473</li>
474
475<li><code>$GOBIN</code>
476<p>
477The directory where executables outside the Go distribution are installed
478using the <a href="/cmd/go">go command</a>. For example,
479<code>go get golang.org/x/tools/cmd/godoc</code> downloads, builds, and
480installs <code>$GOBIN/godoc</code>. By default, <code>$GOBIN</code> is
481<code>$GOPATH/bin</code> (or <code>$HOME/go/bin</code> if <code>GOPATH</code>
482is not set). After installing, you will want to add this directory to
483your <code>$PATH</code> so you can use installed tools.
484</p>
485
486<p>
487Note that the Go distribution's executables are installed in
488<code>$GOROOT/bin</code> (for executables invoked by people) or
489<code>$GOTOOLDIR</code> (for executables invoked by the go command;
490defaults to <code>$GOROOT/pkg/$GOOS_GOARCH</code>) instead of
491<code>$GOBIN</code>.
492</p>
493</li>
494
Colin Cross7bb052a2015-02-03 12:59:37 -0800495<li><code>$GOOS</code> and <code>$GOARCH</code>
496<p>
497The name of the target operating system and compilation architecture.
498These default to the values of <code>$GOHOSTOS</code> and
499<code>$GOHOSTARCH</code> respectively (described below).
Dan Willemsene1b3b182018-02-27 19:36:27 -0800500</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800501
502<p>
503Choices for <code>$GOOS</code> are
Patrice Arruda7f4776e2020-06-25 11:55:41 -0700504<code>android</code>, <code>darwin</code> (macOS/iOS),
Colin Crossefed6342019-09-07 08:34:44 -0700505<code>dragonfly</code>, <code>freebsd</code>, <code>illumos</code>, <code>js</code>,
Dan Willemsen6ff23252015-09-15 13:49:18 -0700506<code>linux</code>, <code>netbsd</code>, <code>openbsd</code>,
Colin Cross7bb052a2015-02-03 12:59:37 -0800507<code>plan9</code>, <code>solaris</code> and <code>windows</code>.
Colin Crossefed6342019-09-07 08:34:44 -0700508</p>
509
510<p>
Colin Cross7bb052a2015-02-03 12:59:37 -0800511Choices for <code>$GOARCH</code> are
512<code>amd64</code> (64-bit x86, the most mature port),
Dan Willemsen6ff23252015-09-15 13:49:18 -0700513<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 -0700514<code>ppc64le</code> (PowerPC 64-bit, little-endian), <code>ppc64</code> (PowerPC 64-bit, big-endian),
Dan Willemsene1b3b182018-02-27 19:36:27 -0800515<code>mips64le</code> (MIPS 64-bit, little-endian), <code>mips64</code> (MIPS 64-bit, big-endian),
Colin Crossefed6342019-09-07 08:34:44 -0700516<code>mipsle</code> (MIPS 32-bit, little-endian), <code>mips</code> (MIPS 32-bit, big-endian),
517<code>s390x</code> (IBM System z 64-bit, big-endian), and
518<code>wasm</code> (WebAssembly 32-bit).
519</p>
520
521<p>
Colin Cross7bb052a2015-02-03 12:59:37 -0800522The valid combinations of <code>$GOOS</code> and <code>$GOARCH</code> are:
523<table cellpadding="0">
524<tr>
525<th width="50"></th><th align="left" width="100"><code>$GOOS</code></th> <th align="left" width="100"><code>$GOARCH</code></th>
526</tr>
527<tr>
Colin Crossefed6342019-09-07 08:34:44 -0700528<td></td><td><code>aix</code></td> <td><code>ppc64</code></td>
529</tr>
530<tr>
531<td></td><td><code>android</code></td> <td><code>386</code></td>
532</tr>
533<tr>
534<td></td><td><code>android</code></td> <td><code>amd64</code></td>
535</tr>
536<tr>
Dan Willemsen0c157092016-07-08 13:57:52 -0700537<td></td><td><code>android</code></td> <td><code>arm</code></td>
538</tr>
539<tr>
Colin Crossefed6342019-09-07 08:34:44 -0700540<td></td><td><code>android</code></td> <td><code>arm64</code></td>
541</tr>
542<tr>
Colin Cross7bb052a2015-02-03 12:59:37 -0800543<td></td><td><code>darwin</code></td> <td><code>amd64</code></td>
544</tr>
545<tr>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700546<td></td><td><code>darwin</code></td> <td><code>arm64</code></td>
Colin Cross7bb052a2015-02-03 12:59:37 -0800547</tr>
548<tr>
549<td></td><td><code>dragonfly</code></td> <td><code>amd64</code></td>
550</tr>
551<tr>
552<td></td><td><code>freebsd</code></td> <td><code>386</code></td>
553</tr>
554<tr>
555<td></td><td><code>freebsd</code></td> <td><code>amd64</code></td>
556</tr>
557<tr>
558<td></td><td><code>freebsd</code></td> <td><code>arm</code></td>
559</tr>
560<tr>
Colin Crossefed6342019-09-07 08:34:44 -0700561<td></td><td><code>illumos</code></td> <td><code>amd64</code></td>
562</tr>
563<tr>
564<td></td><td><code>js</code></td> <td><code>wasm</code></td>
565</tr>
566<tr>
Colin Cross7bb052a2015-02-03 12:59:37 -0800567<td></td><td><code>linux</code></td> <td><code>386</code></td>
568</tr>
569<tr>
570<td></td><td><code>linux</code></td> <td><code>amd64</code></td>
571</tr>
572<tr>
573<td></td><td><code>linux</code></td> <td><code>arm</code></td>
574</tr>
575<tr>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700576<td></td><td><code>linux</code></td> <td><code>arm64</code></td>
577</tr>
578<tr>
579<td></td><td><code>linux</code></td> <td><code>ppc64</code></td>
580</tr>
581<tr>
582<td></td><td><code>linux</code></td> <td><code>ppc64le</code></td>
583</tr>
584<tr>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800585<td></td><td><code>linux</code></td> <td><code>mips</code></td>
586</tr>
587<tr>
588<td></td><td><code>linux</code></td> <td><code>mipsle</code></td>
589</tr>
590<tr>
Dan Willemsen0c157092016-07-08 13:57:52 -0700591<td></td><td><code>linux</code></td> <td><code>mips64</code></td>
592</tr>
593<tr>
594<td></td><td><code>linux</code></td> <td><code>mips64le</code></td>
595</tr>
596<tr>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800597<td></td><td><code>linux</code></td> <td><code>s390x</code></td>
598</tr>
599<tr>
Colin Cross7bb052a2015-02-03 12:59:37 -0800600<td></td><td><code>netbsd</code></td> <td><code>386</code></td>
601</tr>
602<tr>
603<td></td><td><code>netbsd</code></td> <td><code>amd64</code></td>
604</tr>
605<tr>
606<td></td><td><code>netbsd</code></td> <td><code>arm</code></td>
607</tr>
608<tr>
609<td></td><td><code>openbsd</code></td> <td><code>386</code></td>
610</tr>
611<tr>
612<td></td><td><code>openbsd</code></td> <td><code>amd64</code></td>
613</tr>
614<tr>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700615<td></td><td><code>openbsd</code></td> <td><code>arm</code></td>
616</tr>
617<tr>
Colin Crossefed6342019-09-07 08:34:44 -0700618<td></td><td><code>openbsd</code></td> <td><code>arm64</code></td>
619</tr>
620<tr>
Colin Cross7bb052a2015-02-03 12:59:37 -0800621<td></td><td><code>plan9</code></td> <td><code>386</code></td>
622</tr>
623<tr>
624<td></td><td><code>plan9</code></td> <td><code>amd64</code></td>
625</tr>
626<tr>
Colin Crossefed6342019-09-07 08:34:44 -0700627<td></td><td><code>plan9</code></td> <td><code>arm</code></td>
628</tr>
629<tr>
Colin Cross7bb052a2015-02-03 12:59:37 -0800630<td></td><td><code>solaris</code></td> <td><code>amd64</code></td>
631</tr>
632<tr>
633<td></td><td><code>windows</code></td> <td><code>386</code></td>
634</tr>
635<tr>
636<td></td><td><code>windows</code></td> <td><code>amd64</code></td>
637</tr>
638</table>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700639<br>
Colin Cross7bb052a2015-02-03 12:59:37 -0800640
641<li><code>$GOHOSTOS</code> and <code>$GOHOSTARCH</code>
642<p>
643The name of the host operating system and compilation architecture.
644These default to the local system's operating system and
645architecture.
646</p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800647</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800648
649<p>
650Valid choices are the same as for <code>$GOOS</code> and
651<code>$GOARCH</code>, listed above.
652The specified values must be compatible with the local system.
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800653For example, you should not set <code>$GOHOSTARCH</code> to
Colin Cross7bb052a2015-02-03 12:59:37 -0800654<code>arm</code> on an x86 system.
655</p>
656
Colin Cross7bb052a2015-02-03 12:59:37 -0800657<li><code>$GO386</code> (for <code>386</code> only, default is auto-detected
658if built on either <code>386</code> or <code>amd64</code>, <code>387</code> otherwise)
659<p>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700660This controls the code generated by gc to use either the 387 floating-point unit
Colin Cross7bb052a2015-02-03 12:59:37 -0800661(set to <code>387</code>) or SSE2 instructions (set to <code>sse2</code>) for
662floating point computations.
663</p>
664<ul>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800665 <li><code>GO386=387</code>: use x87 for floating point operations; should support all x86 chips (Pentium MMX or later).</li>
666 <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 -0800667</ul>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800668</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800669
670<li><code>$GOARM</code> (for <code>arm</code> only; default is auto-detected if building
671on the target processor, 6 if not)
672<p>
673This sets the ARM floating point co-processor architecture version the run-time
674should target. If you are compiling on the target system, its value will be auto-detected.
675</p>
676<ul>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800677 <li><code>GOARM=5</code>: use software floating point; when CPU doesn't have VFP co-processor</li>
678 <li><code>GOARM=6</code>: use VFPv1 only; default if cross compiling; usually ARM11 or better cores (VFPv2 or better is also supported)</li>
679 <li><code>GOARM=7</code>: use VFPv3; usually Cortex-A cores</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800680</ul>
681<p>
682If in doubt, leave this variable unset, and adjust it if required
683when you first run the Go executable.
684The <a href="//golang.org/wiki/GoArm">GoARM</a> page
685on the <a href="//golang.org/wiki">Go community wiki</a>
686contains further details regarding Go's ARM support.
687</p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800688</li>
689
Colin Cross1371fe42019-03-19 21:08:48 -0700690<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 -0800691<p>
Colin Cross1371fe42019-03-19 21:08:48 -0700692 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 -0800693</p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800694</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800695
Colin Crossefed6342019-09-07 08:34:44 -0700696<li><code>$GOPPC64</code> (for <code>ppc64</code> and <code>ppc64le</code> only)
697<p>
698This variable sets the processor level (i.e. Instruction Set Architecture version)
699for which the compiler will target. The default is <code>power8</code>.
700</p>
701<ul>
702 <li><code>GOPPC64=power8</code>: generate ISA v2.07 instructions</li>
703 <li><code>GOPPC64=power9</code>: generate ISA v3.00 instructions</li>
704</ul>
705</li>
706
707
708<li><code>$GOWASM</code> (for <code>wasm</code> only)
709 <p>
710 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.
711 The default is to use no experimental features.
712 </p>
713 <ul>
714 <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>
715 <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>
716 </ul>
717</li>
718
Colin Cross7bb052a2015-02-03 12:59:37 -0800719</ul>
720
721<p>
722Note that <code>$GOARCH</code> and <code>$GOOS</code> identify the
723<em>target</em> environment, not the environment you are running on.
724In effect, you are always cross-compiling.
725By architecture, we mean the kind of binaries
726that the target environment can run:
727an x86-64 system running a 32-bit-only operating system
728must set <code>GOARCH</code> to <code>386</code>,
729not <code>amd64</code>.
730</p>
731
732<p>
733If you choose to override the defaults,
734set these variables in your shell profile (<code>$HOME/.bashrc</code>,
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800735<code>$HOME/.profile</code>, or equivalent). The settings might look
Colin Cross7bb052a2015-02-03 12:59:37 -0800736something like this:
737</p>
738
739<pre>
Colin Cross7bb052a2015-02-03 12:59:37 -0800740export GOARCH=amd64
741export GOOS=linux
742</pre>
743
744<p>
745although, to reiterate, none of these variables needs to be set to build,
746install, and develop the Go tree.
747</p>