blob: bbe7cdfd0095cbac9d8208db465794a307e05dbe [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>
Dan Willemsenbbdf6642017-01-13 22:57:23 -080036The Go compilers support eight instruction sets.
Colin Cross7bb052a2015-02-03 12:59:37 -080037There are important differences in the quality of the compilers for the different
38architectures.
39</p>
40
41<dl>
42<dt>
Dan Willemsen6ff23252015-09-15 13:49:18 -070043 <code>amd64</code> (also known as <code>x86-64</code>)
Colin Cross7bb052a2015-02-03 12:59:37 -080044</dt>
45<dd>
Dan Willemsenbbdf6642017-01-13 22:57:23 -080046 A mature implementation.
Colin Cross7bb052a2015-02-03 12:59:37 -080047</dd>
48<dt>
Dan Willemsen6ff23252015-09-15 13:49:18 -070049 <code>386</code> (<code>x86</code> or <code>x86-32</code>)
Colin Cross7bb052a2015-02-03 12:59:37 -080050</dt>
51<dd>
Dan Willemsenbbdf6642017-01-13 22:57:23 -080052 Comparable to the <code>amd64</code> port.
Colin Cross7bb052a2015-02-03 12:59:37 -080053</dd>
54<dt>
Dan Willemsen6ff23252015-09-15 13:49:18 -070055 <code>arm</code> (<code>ARM</code>)
Colin Cross7bb052a2015-02-03 12:59:37 -080056</dt>
57<dd>
Dan Willemsenbbdf6642017-01-13 22:57:23 -080058 Supports Linux, FreeBSD, NetBSD, OpenBSD and Darwin binaries. Less widely used than the other ports.
Dan Willemsen6ff23252015-09-15 13:49:18 -070059</dd>
60<dt>
61 <code>arm64</code> (<code>AArch64</code>)
62</dt>
63<dd>
Dan Willemsen0c157092016-07-08 13:57:52 -070064 Supports Linux and Darwin binaries. New in 1.5 and not as well exercised as other ports.
Dan Willemsen6ff23252015-09-15 13:49:18 -070065</dd>
66<dt>
67 <code>ppc64, ppc64le</code> (64-bit PowerPC big- and little-endian)
68</dt>
69<dd>
Dan Willemsen0c157092016-07-08 13:57:52 -070070 Supports Linux binaries. New in 1.5 and not as well exercised as other ports.
71</dd>
72<dt>
Dan Willemsenbbdf6642017-01-13 22:57:23 -080073 <code>mips, mipsle</code> (32-bit MIPS big- and little-endian)
74</dt>
75<dd>
76 Supports Linux binaries. New in 1.8 and not as well exercised as other ports.
77</dd>
78<dt>
Dan Willemsen0c157092016-07-08 13:57:52 -070079 <code>mips64, mips64le</code> (64-bit MIPS big- and little-endian)
80</dt>
81<dd>
82 Supports Linux binaries. New in 1.6 and not as well exercised as other ports.
83</dd>
84<dt>
85 <code>s390x</code> (IBM System z)
86</dt>
87<dd>
88 Supports Linux binaries. New in 1.7 and not as well exercised as other ports.
Colin Cross7bb052a2015-02-03 12:59:37 -080089</dd>
90</dl>
91
92<p>
93Except for things like low-level operating system interface code, the run-time
94support is the same in all ports and includes a mark-and-sweep garbage
95collector, efficient array and string slicing, and support for efficient
96goroutines, such as stacks that grow and shrink on demand.
97</p>
98
99<p>
100The compilers can target the DragonFly BSD, FreeBSD, Linux, NetBSD, OpenBSD,
Dan Willemsenf3f2eb62018-08-28 11:28:58 -0700101macOS (Darwin), Plan 9, Solaris and Windows operating systems.
Colin Cross7bb052a2015-02-03 12:59:37 -0800102The full set of supported combinations is listed in the discussion of
103<a href="#environment">environment variables</a> below.
104</p>
105
Dan Willemsen0c157092016-07-08 13:57:52 -0700106<p>
107See the main installation page for the <a href="/doc/install#requirements">overall system requirements</a>.
108The following additional constraints apply to systems that can be built only from source:
109</p>
110
111<ul>
112<li>For Linux on PowerPC 64-bit, the minimum supported kernel version is 2.6.37, meaning that
113Go does not support CentOS 6 on these systems.
114</li>
115</ul>
116
Colin Cross7bb052a2015-02-03 12:59:37 -0800117</div>
118
Dan Willemsen6ff23252015-09-15 13:49:18 -0700119<h2 id="go14">Install Go compiler binaries</h2>
Colin Cross7bb052a2015-02-03 12:59:37 -0800120
121<p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800122The Go toolchain is written in Go. To build it, you need a Go compiler installed.
Dan Willemsen6ff23252015-09-15 13:49:18 -0700123The scripts that do the initial build of the tools look for an existing Go tool
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800124chain in <code>$GOROOT_BOOTSTRAP</code>.
125If unset, the default value of <code>GOROOT_BOOTSTRAP</code>
126is <code>$HOME/go1.4</code>.
Colin Cross7bb052a2015-02-03 12:59:37 -0800127</p>
128
Dan Willemsen6ff23252015-09-15 13:49:18 -0700129<p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800130There are many options for the bootstrap toolchain.
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800131After obtaining one, set <code>GOROOT_BOOTSTRAP</code> to the
132directory containing the unpacked tree.
133For example, <code>$GOROOT_BOOTSTRAP/bin/go</code> should be
Dan Willemsene1b3b182018-02-27 19:36:27 -0800134the <code>go</code> command binary for the bootstrap toolchain.
Dan Willemsen6ff23252015-09-15 13:49:18 -0700135</p>
136
137<p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800138To use a binary release as a bootstrap toolchain, see
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800139<a href="/dl/">the downloads page</a> or use any other
140packaged Go distribution.
Dan Willemsen6ff23252015-09-15 13:49:18 -0700141</p>
142
143<p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800144To build a bootstrap toolchain from source, use
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800145either the git branch <code>release-branch.go1.4</code> or
Dan Willemsene1b3b182018-02-27 19:36:27 -0800146<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 -0800147which contains the Go 1.4 source code plus accumulated fixes
148to keep the tools running on newer operating systems.
Dan Willemsene1b3b182018-02-27 19:36:27 -0800149(Go 1.4 was the last distribution in which the toolchain was written in C.)
Dan Willemsena727cd02017-02-21 17:11:40 -0800150After unpacking the Go 1.4 source, <code>cd</code> to
Dan Willemsene1b3b182018-02-27 19:36:27 -0800151the <code>src</code> subdirectory, set <code>CGO_ENABLED=0</code> in
152the environment, and run <code>make.bash</code> (or,
Dan Willemsena727cd02017-02-21 17:11:40 -0800153on Windows, <code>make.bat</code>).
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800154</p>
155
156<p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800157To cross-compile a bootstrap toolchain from source, which is
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800158necessary on systems Go 1.4 did not target (for
159example, <code>linux/ppc64le</code>), install Go on a different system
160and run <a href="/src/bootstrap.bash">bootstrap.bash</a>.
Dan Willemsen6ff23252015-09-15 13:49:18 -0700161</p>
162
163<p>
164When run as (for example)
165</p>
166
167<pre>
168$ GOOS=linux GOARCH=ppc64 ./bootstrap.bash
169</pre>
170
171<p>
172<code>bootstrap.bash</code> cross-compiles a toolchain for that <code>GOOS/GOARCH</code>
173combination, leaving the resulting tree in <code>../../go-${GOOS}-${GOARCH}-bootstrap</code>.
174That tree can be copied to a machine of the given target type
175and used as <code>GOROOT_BOOTSTRAP</code> to bootstrap a local build.
176</p>
177
178<p>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800179To use gccgo as the bootstrap toolchain, you need to arrange
180for <code>$GOROOT_BOOTSTRAP/bin/go</code> to be the go tool that comes
181as part of gccgo 5. For example on Ubuntu Vivid:
Dan Willemsen6ff23252015-09-15 13:49:18 -0700182</p>
183
184<pre>
185$ sudo apt-get install gccgo-5
186$ sudo update-alternatives --set go /usr/bin/go-5
187$ GOROOT_BOOTSTRAP=/usr ./make.bash
188</pre>
189
Colin Cross7bb052a2015-02-03 12:59:37 -0800190<h2 id="git">Install Git, if needed</h2>
191
192<p>
193To perform the next step you must have Git installed. (Check that you
194have a <code>git</code> command before proceeding.)
195</p>
196
197<p>
198If you do not have a working Git installation,
199follow the instructions on the
Dan Willemsenf3f2eb62018-08-28 11:28:58 -0700200<a href="https://git-scm.com/downloads">Git downloads</a> page.
Colin Cross7bb052a2015-02-03 12:59:37 -0800201</p>
202
Dan Willemsen0c157092016-07-08 13:57:52 -0700203<h2 id="ccompiler">(Optional) Install a C compiler</h2>
204
205<p>
206To build a Go installation
207with <code><a href="/cmd/cgo">cgo</a></code> support, which permits Go
208programs to import C libraries, a C compiler such as <code>gcc</code>
209or <code>clang</code> must be installed first. Do this using whatever
210installation method is standard on the system.
211</p>
212
213<p>
214To build without <code>cgo</code>, set the environment variable
215<code>CGO_ENABLED=0</code> before running <code>all.bash</code> or
216<code>make.bash</code>.
217</p>
Colin Cross7bb052a2015-02-03 12:59:37 -0800218
219<h2 id="fetch">Fetch the repository</h2>
220
221<p>Go will install to a directory named <code>go</code>.
222Change to the directory that will be its parent
223and make sure the <code>go</code> directory does not exist.
Dan Willemsen0c157092016-07-08 13:57:52 -0700224Then clone the repository and check out the latest release tag
Dan Willemsencc0b9f52017-08-25 11:20:05 -0700225(<code class="versionTag">go1.9</code>, for example):</p>
Colin Cross7bb052a2015-02-03 12:59:37 -0800226
227<pre>
228$ git clone https://go.googlesource.com/go
229$ cd go
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 Cross7bb052a2015-02-03 12:59:37 -0800237<h2 id="head">(Optional) Switch to the master branch</h2>
238
239<p>If you intend to modify the go source code, and
240<a href="/doc/contribute.html">contribute your changes</a>
241to the project, then move your repository
242off the release branch, and onto the master (development) branch.
243Otherwise, skip this step.</p>
244
245<pre>
246$ git checkout master
247</pre>
248
249<h2 id="install">Install Go</h2>
250
251<p>
252To build the Go distribution, run
253</p>
254
255<pre>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700256$ cd src
Colin Cross7bb052a2015-02-03 12:59:37 -0800257$ ./all.bash
258</pre>
259
260<p>
261(To build under Windows use <code>all.bat</code>.)
262</p>
263
264<p>
265If all goes well, it will finish by printing output like:
266</p>
267
268<pre>
269ALL TESTS PASSED
270
271---
272Installed Go for linux/amd64 in /home/you/go.
273Installed commands in /home/you/go/bin.
274*** You need to add /home/you/go/bin to your $PATH. ***
275</pre>
276
277<p>
278where the details on the last few lines reflect the operating system,
279architecture, and root directory used during the install.
280</p>
281
282<div class="detail">
283<p>
284For more information about ways to control the build, see the discussion of
285<a href="#environment">environment variables</a> below.
286<code>all.bash</code> (or <code>all.bat</code>) runs important tests for Go,
287which can take more time than simply building Go. If you do not want to run
288the test suite use <code>make.bash</code> (or <code>make.bat</code>)
289instead.
290</p>
291</div>
292
293
294<h2 id="testing">Testing your installation</h2>
295
296<p>
297Check that Go is installed correctly by building a simple program.
298</p>
299
300<p>
301Create a file named <code>hello.go</code> and put the following program in it:
302</p>
303
304<pre>
305package main
306
307import "fmt"
308
309func main() {
Dan Willemsenf3f2eb62018-08-28 11:28:58 -0700310 fmt.Printf("hello, world\n")
Colin Cross7bb052a2015-02-03 12:59:37 -0800311}
312</pre>
313
314<p>
315Then run it with the <code>go</code> tool:
316</p>
317
318<pre>
319$ go run hello.go
320hello, world
321</pre>
322
323<p>
324If you see the "hello, world" message then Go is installed correctly.
325</p>
326
327<h2 id="gopath">Set up your work environment</h2>
328
329<p>
330You're almost done.
331You just need to do a little more setup.
332</p>
333
334<p>
335<a href="/doc/code.html" class="download" id="start">
336<span class="big">How to Write Go Code</span>
337<span class="desc">Learn how to set up and use the Go tools</span>
338</a>
339</p>
340
341<p>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800342The <a href="/doc/code.html">How to Write Go Code</a> document
Colin Cross7bb052a2015-02-03 12:59:37 -0800343provides <b>essential setup instructions</b> for using the Go tools.
344</p>
345
346
347<h2 id="tools">Install additional tools</h2>
348
349<p>
350The source code for several Go tools (including <a href="/cmd/godoc/">godoc</a>)
351is kept in <a href="https://golang.org/x/tools">the go.tools repository</a>.
Colin Cross1371fe42019-03-19 21:08:48 -0700352To install one of the tools (<code>godoc</code> in this case):
Colin Cross7bb052a2015-02-03 12:59:37 -0800353</p>
354
355<pre>
356$ go get golang.org/x/tools/cmd/godoc
357</pre>
358
359<p>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800360To install these tools, the <code>go</code> <code>get</code> command requires
Colin Cross7bb052a2015-02-03 12:59:37 -0800361that <a href="#git">Git</a> be installed locally.
362</p>
363
364<p>
365You must also have a workspace (<code>GOPATH</code>) set up;
366see <a href="/doc/code.html">How to Write Go Code</a> for the details.
367</p>
368
Colin Cross7bb052a2015-02-03 12:59:37 -0800369<h2 id="community">Community resources</h2>
370
371<p>
372The usual community resources such as
Dan Willemsenf3f2eb62018-08-28 11:28:58 -0700373<code>#go-nuts</code> on the <a href="https://freenode.net/">Freenode</a> IRC server
Colin Cross7bb052a2015-02-03 12:59:37 -0800374and the
375<a href="//groups.google.com/group/golang-nuts">Go Nuts</a>
376mailing list have active developers that can help you with problems
377with your installation or your development work.
378For those who wish to keep up to date,
379there is another mailing list, <a href="//groups.google.com/group/golang-checkins">golang-checkins</a>,
380that receives a message summarizing each checkin to the Go repository.
381</p>
382
383<p>
384Bugs can be reported using the <a href="//golang.org/issue/new">Go issue tracker</a>.
385</p>
386
387
388<h2 id="releases">Keeping up with releases</h2>
389
390<p>
391New releases are announced on the
392<a href="//groups.google.com/group/golang-announce">golang-announce</a>
393mailing list.
394Each announcement mentions the latest release tag, for instance,
Dan Willemsencc0b9f52017-08-25 11:20:05 -0700395<code class="versionTag">go1.9</code>.
Colin Cross7bb052a2015-02-03 12:59:37 -0800396</p>
397
398<p>
399To update an existing tree to the latest release, you can run:
400</p>
401
402<pre>
403$ cd go/src
404$ git fetch
Dan Willemsen0c157092016-07-08 13:57:52 -0700405$ git checkout <span class="versionTag"><i>&lt;tag&gt;</i></psan>
Colin Cross7bb052a2015-02-03 12:59:37 -0800406$ ./all.bash
407</pre>
408
Dan Willemsen0c157092016-07-08 13:57:52 -0700409<p class="whereTag">
Colin Cross7bb052a2015-02-03 12:59:37 -0800410Where <code>&lt;tag&gt;</code> is the version string of the release.
Dan Willemsen0c157092016-07-08 13:57:52 -0700411</p>
Colin Cross7bb052a2015-02-03 12:59:37 -0800412
413
414<h2 id="environment">Optional environment variables</h2>
415
416<p>
417The Go compilation environment can be customized by environment variables.
418<i>None is required by the build</i>, but you may wish to set some
419to override the defaults.
420</p>
421
422<ul>
423<li><code>$GOROOT</code>
424<p>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800425The root of the Go tree, often <code>$HOME/go1.X</code>.
Colin Cross7bb052a2015-02-03 12:59:37 -0800426Its value is built into the tree when it is compiled, and
427defaults to the parent of the directory where <code>all.bash</code> was run.
428There is no need to set this unless you want to switch between multiple
429local copies of the repository.
430</p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800431</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800432
433<li><code>$GOROOT_FINAL</code>
434<p>
435The value assumed by installed binaries and scripts when
436<code>$GOROOT</code> is not set explicitly.
437It defaults to the value of <code>$GOROOT</code>.
438If you want to build the Go tree in one location
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800439but move it elsewhere after the build, set
Colin Cross7bb052a2015-02-03 12:59:37 -0800440<code>$GOROOT_FINAL</code> to the eventual location.
441</p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800442</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800443
444<li><code>$GOOS</code> and <code>$GOARCH</code>
445<p>
446The name of the target operating system and compilation architecture.
447These default to the values of <code>$GOHOSTOS</code> and
448<code>$GOHOSTARCH</code> respectively (described below).
Dan Willemsene1b3b182018-02-27 19:36:27 -0800449</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800450
451<p>
452Choices for <code>$GOOS</code> are
Dan Willemsenf3f2eb62018-08-28 11:28:58 -0700453<code>darwin</code> (macOS 10.10 and above and iOS), <code>dragonfly</code>, <code>freebsd</code>,
Dan Willemsen6ff23252015-09-15 13:49:18 -0700454<code>linux</code>, <code>netbsd</code>, <code>openbsd</code>,
Colin Cross7bb052a2015-02-03 12:59:37 -0800455<code>plan9</code>, <code>solaris</code> and <code>windows</code>.
456Choices for <code>$GOARCH</code> are
457<code>amd64</code> (64-bit x86, the most mature port),
Dan Willemsen6ff23252015-09-15 13:49:18 -0700458<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 -0700459<code>ppc64le</code> (PowerPC 64-bit, little-endian), <code>ppc64</code> (PowerPC 64-bit, big-endian),
Dan Willemsene1b3b182018-02-27 19:36:27 -0800460<code>mips64le</code> (MIPS 64-bit, little-endian), <code>mips64</code> (MIPS 64-bit, big-endian),
461<code>mipsle</code> (MIPS 32-bit, little-endian), <code>mips</code> (MIPS 32-bit, big-endian), and
462<code>s390x</code> (IBM System z 64-bit, big-endian).
Colin Cross7bb052a2015-02-03 12:59:37 -0800463The valid combinations of <code>$GOOS</code> and <code>$GOARCH</code> are:
464<table cellpadding="0">
465<tr>
466<th width="50"></th><th align="left" width="100"><code>$GOOS</code></th> <th align="left" width="100"><code>$GOARCH</code></th>
467</tr>
468<tr>
Dan Willemsen0c157092016-07-08 13:57:52 -0700469<td></td><td><code>android</code></td> <td><code>arm</code></td>
470</tr>
471<tr>
Colin Cross7bb052a2015-02-03 12:59:37 -0800472<td></td><td><code>darwin</code></td> <td><code>386</code></td>
473</tr>
474<tr>
475<td></td><td><code>darwin</code></td> <td><code>amd64</code></td>
476</tr>
477<tr>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700478<td></td><td><code>darwin</code></td> <td><code>arm</code></td>
479</tr>
480<tr>
481<td></td><td><code>darwin</code></td> <td><code>arm64</code></td>
Colin Cross7bb052a2015-02-03 12:59:37 -0800482</tr>
483<tr>
484<td></td><td><code>dragonfly</code></td> <td><code>amd64</code></td>
485</tr>
486<tr>
487<td></td><td><code>freebsd</code></td> <td><code>386</code></td>
488</tr>
489<tr>
490<td></td><td><code>freebsd</code></td> <td><code>amd64</code></td>
491</tr>
492<tr>
493<td></td><td><code>freebsd</code></td> <td><code>arm</code></td>
494</tr>
495<tr>
496<td></td><td><code>linux</code></td> <td><code>386</code></td>
497</tr>
498<tr>
499<td></td><td><code>linux</code></td> <td><code>amd64</code></td>
500</tr>
501<tr>
502<td></td><td><code>linux</code></td> <td><code>arm</code></td>
503</tr>
504<tr>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700505<td></td><td><code>linux</code></td> <td><code>arm64</code></td>
506</tr>
507<tr>
508<td></td><td><code>linux</code></td> <td><code>ppc64</code></td>
509</tr>
510<tr>
511<td></td><td><code>linux</code></td> <td><code>ppc64le</code></td>
512</tr>
513<tr>
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800514<td></td><td><code>linux</code></td> <td><code>mips</code></td>
515</tr>
516<tr>
517<td></td><td><code>linux</code></td> <td><code>mipsle</code></td>
518</tr>
519<tr>
Dan Willemsen0c157092016-07-08 13:57:52 -0700520<td></td><td><code>linux</code></td> <td><code>mips64</code></td>
521</tr>
522<tr>
523<td></td><td><code>linux</code></td> <td><code>mips64le</code></td>
524</tr>
525<tr>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800526<td></td><td><code>linux</code></td> <td><code>s390x</code></td>
527</tr>
528<tr>
Colin Cross7bb052a2015-02-03 12:59:37 -0800529<td></td><td><code>netbsd</code></td> <td><code>386</code></td>
530</tr>
531<tr>
532<td></td><td><code>netbsd</code></td> <td><code>amd64</code></td>
533</tr>
534<tr>
535<td></td><td><code>netbsd</code></td> <td><code>arm</code></td>
536</tr>
537<tr>
538<td></td><td><code>openbsd</code></td> <td><code>386</code></td>
539</tr>
540<tr>
541<td></td><td><code>openbsd</code></td> <td><code>amd64</code></td>
542</tr>
543<tr>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700544<td></td><td><code>openbsd</code></td> <td><code>arm</code></td>
545</tr>
546<tr>
Colin Cross7bb052a2015-02-03 12:59:37 -0800547<td></td><td><code>plan9</code></td> <td><code>386</code></td>
548</tr>
549<tr>
550<td></td><td><code>plan9</code></td> <td><code>amd64</code></td>
551</tr>
552<tr>
553<td></td><td><code>solaris</code></td> <td><code>amd64</code></td>
554</tr>
555<tr>
556<td></td><td><code>windows</code></td> <td><code>386</code></td>
557</tr>
558<tr>
559<td></td><td><code>windows</code></td> <td><code>amd64</code></td>
560</tr>
561</table>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700562<br>
Colin Cross7bb052a2015-02-03 12:59:37 -0800563
564<li><code>$GOHOSTOS</code> and <code>$GOHOSTARCH</code>
565<p>
566The name of the host operating system and compilation architecture.
567These default to the local system's operating system and
568architecture.
569</p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800570</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800571
572<p>
573Valid choices are the same as for <code>$GOOS</code> and
574<code>$GOARCH</code>, listed above.
575The specified values must be compatible with the local system.
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800576For example, you should not set <code>$GOHOSTARCH</code> to
Colin Cross7bb052a2015-02-03 12:59:37 -0800577<code>arm</code> on an x86 system.
578</p>
579
580<li><code>$GOBIN</code>
581<p>
582The location where Go binaries will be installed.
583The default is <code>$GOROOT/bin</code>.
584After installing, you will want to arrange to add this
585directory to your <code>$PATH</code>, so you can use the tools.
586If <code>$GOBIN</code> is set, the <a href="/cmd/go">go command</a>
587installs all commands there.
588</p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800589</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800590
591<li><code>$GO386</code> (for <code>386</code> only, default is auto-detected
592if built on either <code>386</code> or <code>amd64</code>, <code>387</code> otherwise)
593<p>
Dan Willemsen6ff23252015-09-15 13:49:18 -0700594This controls the code generated by gc to use either the 387 floating-point unit
Colin Cross7bb052a2015-02-03 12:59:37 -0800595(set to <code>387</code>) or SSE2 instructions (set to <code>sse2</code>) for
596floating point computations.
597</p>
598<ul>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800599 <li><code>GO386=387</code>: use x87 for floating point operations; should support all x86 chips (Pentium MMX or later).</li>
600 <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 -0800601</ul>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800602</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800603
604<li><code>$GOARM</code> (for <code>arm</code> only; default is auto-detected if building
605on the target processor, 6 if not)
606<p>
607This sets the ARM floating point co-processor architecture version the run-time
608should target. If you are compiling on the target system, its value will be auto-detected.
609</p>
610<ul>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800611 <li><code>GOARM=5</code>: use software floating point; when CPU doesn't have VFP co-processor</li>
612 <li><code>GOARM=6</code>: use VFPv1 only; default if cross compiling; usually ARM11 or better cores (VFPv2 or better is also supported)</li>
613 <li><code>GOARM=7</code>: use VFPv3; usually Cortex-A cores</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800614</ul>
615<p>
616If in doubt, leave this variable unset, and adjust it if required
617when you first run the Go executable.
618The <a href="//golang.org/wiki/GoArm">GoARM</a> page
619on the <a href="//golang.org/wiki">Go community wiki</a>
620contains further details regarding Go's ARM support.
621</p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800622</li>
623
Colin Cross1371fe42019-03-19 21:08:48 -0700624<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 -0800625<p>
Colin Cross1371fe42019-03-19 21:08:48 -0700626 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 -0800627</p>
Dan Willemsene1b3b182018-02-27 19:36:27 -0800628</li>
Colin Cross7bb052a2015-02-03 12:59:37 -0800629
630</ul>
631
632<p>
633Note that <code>$GOARCH</code> and <code>$GOOS</code> identify the
634<em>target</em> environment, not the environment you are running on.
635In effect, you are always cross-compiling.
636By architecture, we mean the kind of binaries
637that the target environment can run:
638an x86-64 system running a 32-bit-only operating system
639must set <code>GOARCH</code> to <code>386</code>,
640not <code>amd64</code>.
641</p>
642
643<p>
644If you choose to override the defaults,
645set these variables in your shell profile (<code>$HOME/.bashrc</code>,
Dan Willemsenbbdf6642017-01-13 22:57:23 -0800646<code>$HOME/.profile</code>, or equivalent). The settings might look
Colin Cross7bb052a2015-02-03 12:59:37 -0800647something like this:
648</p>
649
650<pre>
Colin Cross7bb052a2015-02-03 12:59:37 -0800651export GOARCH=amd64
652export GOOS=linux
653</pre>
654
655<p>
656although, to reiterate, none of these variables needs to be set to build,
657install, and develop the Go tree.
658</p>