Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 1 | <!--{ |
| 2 | "Title": "Installing Go from source", |
Andrew Gerrand | f78d50c | 2012-03-05 14:31:27 +1100 | [diff] [blame] | 3 | "Path": "/doc/install/source" |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 4 | }--> |
| 5 | |
| 6 | <h2 id="introduction">Introduction</h2> |
| 7 | |
Rob Pike | 95d7d3d | 2012-03-03 09:36:09 +1100 | [diff] [blame] | 8 | <p> |
| 9 | Go is an open source project, distributed under a |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 10 | <a href="/LICENSE">BSD-style license</a>. |
| 11 | This document explains how to check out the sources, |
| 12 | build them on your own machine, and run them. |
| 13 | </p> |
| 14 | |
Rob Pike | 95d7d3d | 2012-03-03 09:36:09 +1100 | [diff] [blame] | 15 | <p> |
| 16 | Most users don't need to do this, and will instead install |
| 17 | from precompiled binary packages as described in |
Andrew Gerrand | f78d50c | 2012-03-05 14:31:27 +1100 | [diff] [blame] | 18 | <a href="/doc/install">Getting Started</a>, |
Rob Pike | 95d7d3d | 2012-03-03 09:36:09 +1100 | [diff] [blame] | 19 | a much simpler process. |
| 20 | If you want to help develop what goes into those precompiled |
| 21 | packages, though, read on. |
| 22 | </p> |
| 23 | |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 24 | <div class="detail"> |
| 25 | |
| 26 | <p> |
Russ Cox | b6c871a | 2018-01-09 15:26:21 -0500 | [diff] [blame] | 27 | There are two official Go compiler toolchains. |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 28 | This document focuses on the <code>gc</code> Go |
Aaron Jacobs | 8628688 | 2015-06-24 09:50:12 +1000 | [diff] [blame] | 29 | compiler and tools. |
Rob Pike | 95d7d3d | 2012-03-03 09:36:09 +1100 | [diff] [blame] | 30 | For information on how to work on <code>gccgo</code>, a more traditional |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 31 | compiler using the GCC back end, see |
Andrew Gerrand | f78d50c | 2012-03-05 14:31:27 +1100 | [diff] [blame] | 32 | <a href="/doc/install/gccgo">Setting up and using gccgo</a>. |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 33 | </p> |
| 34 | |
| 35 | <p> |
Shenghou Ma | 8adff32 | 2016-12-01 23:12:18 -0500 | [diff] [blame] | 36 | The Go compilers support eight instruction sets. |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 37 | There are important differences in the quality of the compilers for the different |
| 38 | architectures. |
| 39 | </p> |
| 40 | |
| 41 | <dl> |
| 42 | <dt> |
Michael Hudson-Doyle | f74ea6c | 2015-06-10 21:56:01 +1200 | [diff] [blame] | 43 | <code>amd64</code> (also known as <code>x86-64</code>) |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 44 | </dt> |
| 45 | <dd> |
Quentin Smith | f35b865 | 2016-10-18 15:54:04 -0400 | [diff] [blame] | 46 | A mature implementation. |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 47 | </dd> |
| 48 | <dt> |
Michael Hudson-Doyle | f74ea6c | 2015-06-10 21:56:01 +1200 | [diff] [blame] | 49 | <code>386</code> (<code>x86</code> or <code>x86-32</code>) |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 50 | </dt> |
| 51 | <dd> |
Quentin Smith | f35b865 | 2016-10-18 15:54:04 -0400 | [diff] [blame] | 52 | Comparable to the <code>amd64</code> port. |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 53 | </dd> |
| 54 | <dt> |
Michael Hudson-Doyle | f74ea6c | 2015-06-10 21:56:01 +1200 | [diff] [blame] | 55 | <code>arm</code> (<code>ARM</code>) |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 56 | </dt> |
| 57 | <dd> |
Shenghou Ma | 8adff32 | 2016-12-01 23:12:18 -0500 | [diff] [blame] | 58 | Supports Linux, FreeBSD, NetBSD, OpenBSD and Darwin binaries. Less widely used than the other ports. |
Michael Hudson-Doyle | f74ea6c | 2015-06-10 21:56:01 +1200 | [diff] [blame] | 59 | </dd> |
| 60 | <dt> |
| 61 | <code>arm64</code> (<code>AArch64</code>) |
| 62 | </dt> |
| 63 | <dd> |
Robert Griesemer | 93e8e70 | 2016-05-24 14:12:35 -0700 | [diff] [blame] | 64 | Supports Linux and Darwin binaries. New in 1.5 and not as well exercised as other ports. |
Michael Hudson-Doyle | f74ea6c | 2015-06-10 21:56:01 +1200 | [diff] [blame] | 65 | </dd> |
| 66 | <dt> |
| 67 | <code>ppc64, ppc64le</code> (64-bit PowerPC big- and little-endian) |
| 68 | </dt> |
| 69 | <dd> |
Robert Griesemer | 93e8e70 | 2016-05-24 14:12:35 -0700 | [diff] [blame] | 70 | Supports Linux binaries. New in 1.5 and not as well exercised as other ports. |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 71 | </dd> |
Shenghou Ma | d75391a | 2015-11-13 03:12:26 -0500 | [diff] [blame] | 72 | <dt> |
Shenghou Ma | 8adff32 | 2016-12-01 23:12:18 -0500 | [diff] [blame] | 73 | <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> |
Shenghou Ma | d75391a | 2015-11-13 03:12:26 -0500 | [diff] [blame] | 79 | <code>mips64, mips64le</code> (64-bit MIPS big- and little-endian) |
| 80 | </dt> |
| 81 | <dd> |
Robert Griesemer | 93e8e70 | 2016-05-24 14:12:35 -0700 | [diff] [blame] | 82 | Supports Linux binaries. New in 1.6 and not as well exercised as other ports. |
Shenghou Ma | d75391a | 2015-11-13 03:12:26 -0500 | [diff] [blame] | 83 | </dd> |
Andrew Gerrand | 349f0fb | 2016-06-20 15:33:52 +1000 | [diff] [blame] | 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. |
| 89 | </dd> |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 90 | </dl> |
| 91 | |
| 92 | <p> |
| 93 | Except for things like low-level operating system interface code, the run-time |
| 94 | support is the same in all ports and includes a mark-and-sweep garbage |
| 95 | collector, efficient array and string slicing, and support for efficient |
| 96 | goroutines, such as stacks that grow and shrink on demand. |
| 97 | </p> |
| 98 | |
| 99 | <p> |
Mikio Hara | 3476704 | 2014-03-26 14:06:18 +0900 | [diff] [blame] | 100 | The compilers can target the DragonFly BSD, FreeBSD, Linux, NetBSD, OpenBSD, |
| 101 | OS X (Darwin), Plan 9, Solaris and Windows operating systems. |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 102 | The full set of supported combinations is listed in the discussion of |
| 103 | <a href="#environment">environment variables</a> below. |
| 104 | </p> |
| 105 | |
Russ Cox | d02193c | 2016-01-06 15:51:01 -0500 | [diff] [blame] | 106 | <p> |
| 107 | See the main installation page for the <a href="/doc/install#requirements">overall system requirements</a>. |
| 108 | The 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 |
| 113 | Go does not support CentOS 6 on these systems. |
| 114 | </li> |
| 115 | </ul> |
| 116 | |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 117 | </div> |
| 118 | |
Andrew Gerrand | 3b67e9c | 2015-02-11 12:44:50 +1100 | [diff] [blame] | 119 | <h2 id="go14">Install Go compiler binaries</h2> |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 120 | |
| 121 | <p> |
Russ Cox | b6c871a | 2018-01-09 15:26:21 -0500 | [diff] [blame] | 122 | The Go toolchain is written in Go. To build it, you need a Go compiler installed. |
Andrew Gerrand | 3b67e9c | 2015-02-11 12:44:50 +1100 | [diff] [blame] | 123 | The scripts that do the initial build of the tools look for an existing Go tool |
Brad Fitzpatrick | b990558 | 2016-10-28 18:03:21 +0000 | [diff] [blame] | 124 | chain in <code>$GOROOT_BOOTSTRAP</code>. |
| 125 | If unset, the default value of <code>GOROOT_BOOTSTRAP</code> |
| 126 | is <code>$HOME/go1.4</code>. |
Andrew Gerrand | 3b67e9c | 2015-02-11 12:44:50 +1100 | [diff] [blame] | 127 | </p> |
| 128 | |
| 129 | <p> |
Russ Cox | b6c871a | 2018-01-09 15:26:21 -0500 | [diff] [blame] | 130 | There are many options for the bootstrap toolchain. |
Brad Fitzpatrick | b990558 | 2016-10-28 18:03:21 +0000 | [diff] [blame] | 131 | After obtaining one, set <code>GOROOT_BOOTSTRAP</code> to the |
| 132 | directory containing the unpacked tree. |
| 133 | For example, <code>$GOROOT_BOOTSTRAP/bin/go</code> should be |
Russ Cox | b6c871a | 2018-01-09 15:26:21 -0500 | [diff] [blame] | 134 | the <code>go</code> command binary for the bootstrap toolchain. |
Andrew Gerrand | 3b67e9c | 2015-02-11 12:44:50 +1100 | [diff] [blame] | 135 | </p> |
| 136 | |
| 137 | <p> |
Russ Cox | b6c871a | 2018-01-09 15:26:21 -0500 | [diff] [blame] | 138 | To use a binary release as a bootstrap toolchain, see |
Brad Fitzpatrick | b990558 | 2016-10-28 18:03:21 +0000 | [diff] [blame] | 139 | <a href="/dl/">the downloads page</a> or use any other |
| 140 | packaged Go distribution. |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 141 | </p> |
| 142 | |
Michael Hudson-Doyle | deb6c5b | 2015-06-10 22:13:39 +1200 | [diff] [blame] | 143 | <p> |
Russ Cox | b6c871a | 2018-01-09 15:26:21 -0500 | [diff] [blame] | 144 | To build a bootstrap toolchain from source, use |
Brad Fitzpatrick | b990558 | 2016-10-28 18:03:21 +0000 | [diff] [blame] | 145 | either the git branch <code>release-branch.go1.4</code> or |
Andrew Bonventre | 4aac23c | 2017-11-26 11:30:39 -0500 | [diff] [blame] | 146 | <a href="https://dl.google.com/go/go1.4-bootstrap-20171003.tar.gz">go1.4-bootstrap-20171003.tar.gz</a>, |
Brad Fitzpatrick | b990558 | 2016-10-28 18:03:21 +0000 | [diff] [blame] | 147 | which contains the Go 1.4 source code plus accumulated fixes |
| 148 | to keep the tools running on newer operating systems. |
Russ Cox | b6c871a | 2018-01-09 15:26:21 -0500 | [diff] [blame] | 149 | (Go 1.4 was the last distribution in which the toolchain was written in C.) |
Ian Lance Taylor | 1db1671 | 2017-01-24 09:56:57 -0800 | [diff] [blame] | 150 | After unpacking the Go 1.4 source, <code>cd</code> to |
Ian Lance Taylor | 67388e9 | 2017-09-08 14:38:10 -0700 | [diff] [blame] | 151 | the <code>src</code> subdirectory, set <code>CGO_ENABLED=0</code> in |
| 152 | the environment, and run <code>make.bash</code> (or, |
Ian Lance Taylor | 1db1671 | 2017-01-24 09:56:57 -0800 | [diff] [blame] | 153 | on Windows, <code>make.bat</code>). |
Brad Fitzpatrick | b990558 | 2016-10-28 18:03:21 +0000 | [diff] [blame] | 154 | </p> |
| 155 | |
| 156 | <p> |
Russ Cox | b6c871a | 2018-01-09 15:26:21 -0500 | [diff] [blame] | 157 | To cross-compile a bootstrap toolchain from source, which is |
Brad Fitzpatrick | b990558 | 2016-10-28 18:03:21 +0000 | [diff] [blame] | 158 | necessary on systems Go 1.4 did not target (for |
| 159 | example, <code>linux/ppc64le</code>), install Go on a different system |
| 160 | and run <a href="/src/bootstrap.bash">bootstrap.bash</a>. |
Michael Hudson-Doyle | deb6c5b | 2015-06-10 22:13:39 +1200 | [diff] [blame] | 161 | </p> |
| 162 | |
| 163 | <p> |
| 164 | When 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> |
| 173 | combination, leaving the resulting tree in <code>../../go-${GOOS}-${GOARCH}-bootstrap</code>. |
| 174 | That tree can be copied to a machine of the given target type |
| 175 | and used as <code>GOROOT_BOOTSTRAP</code> to bootstrap a local build. |
| 176 | </p> |
| 177 | |
| 178 | <p> |
Brad Fitzpatrick | b990558 | 2016-10-28 18:03:21 +0000 | [diff] [blame] | 179 | To use gccgo as the bootstrap toolchain, you need to arrange |
| 180 | for <code>$GOROOT_BOOTSTRAP/bin/go</code> to be the go tool that comes |
| 181 | as part of gccgo 5. For example on Ubuntu Vivid: |
Michael Hudson-Doyle | deb6c5b | 2015-06-10 22:13:39 +1200 | [diff] [blame] | 182 | </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 | |
Andrew Gerrand | 968f0df | 2014-12-12 13:53:29 +1100 | [diff] [blame] | 190 | <h2 id="git">Install Git, if needed</h2> |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 191 | |
| 192 | <p> |
Andrew Gerrand | 968f0df | 2014-12-12 13:53:29 +1100 | [diff] [blame] | 193 | To perform the next step you must have Git installed. (Check that you |
| 194 | have a <code>git</code> command before proceeding.) |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 195 | </p> |
| 196 | |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 197 | <p> |
Andrew Gerrand | 968f0df | 2014-12-12 13:53:29 +1100 | [diff] [blame] | 198 | If you do not have a working Git installation, |
Andrew Gerrand | 0e59602 | 2012-04-14 13:27:11 +1000 | [diff] [blame] | 199 | follow the instructions on the |
Andrew Gerrand | 968f0df | 2014-12-12 13:53:29 +1100 | [diff] [blame] | 200 | <a href="http://git-scm.com/downloads">Git downloads</a> page. |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 201 | </p> |
| 202 | |
Brad Fitzpatrick | d3e6174 | 2016-01-26 22:56:08 +0000 | [diff] [blame] | 203 | <h2 id="ccompiler">(Optional) Install a C compiler</h2> |
| 204 | |
| 205 | <p> |
| 206 | To build a Go installation |
| 207 | with <code><a href="/cmd/cgo">cgo</a></code> support, which permits Go |
| 208 | programs to import C libraries, a C compiler such as <code>gcc</code> |
| 209 | or <code>clang</code> must be installed first. Do this using whatever |
| 210 | installation method is standard on the system. |
| 211 | </p> |
| 212 | |
| 213 | <p> |
| 214 | To 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> |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 218 | |
| 219 | <h2 id="fetch">Fetch the repository</h2> |
| 220 | |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 221 | <p>Go will install to a directory named <code>go</code>. |
| 222 | Change to the directory that will be its parent |
| 223 | and make sure the <code>go</code> directory does not exist. |
Andrew Gerrand | d093a62 | 2016-04-14 12:12:11 +1000 | [diff] [blame] | 224 | Then clone the repository and check out the latest release tag |
Chris Broadfoot | d77dfba | 2017-08-24 11:52:35 -0700 | [diff] [blame] | 225 | (<code class="versionTag">go1.9</code>, for example):</p> |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 226 | |
| 227 | <pre> |
Andrew Gerrand | 968f0df | 2014-12-12 13:53:29 +1100 | [diff] [blame] | 228 | $ git clone https://go.googlesource.com/go |
| 229 | $ cd go |
Andrew Gerrand | d093a62 | 2016-04-14 12:12:11 +1000 | [diff] [blame] | 230 | $ git checkout <span class="versionTag"><i><tag></i></span> |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 231 | </pre> |
| 232 | |
Andrew Gerrand | d093a62 | 2016-04-14 12:12:11 +1000 | [diff] [blame] | 233 | <p class="whereTag"> |
| 234 | Where <code><tag></code> is the version string of the release. |
| 235 | </p> |
| 236 | |
Andrew Gerrand | 968f0df | 2014-12-12 13:53:29 +1100 | [diff] [blame] | 237 | <h2 id="head">(Optional) Switch to the master branch</h2> |
Jonathan Feinberg | 452f40f | 2012-09-26 14:39:31 -0400 | [diff] [blame] | 238 | |
| 239 | <p>If you intend to modify the go source code, and |
| 240 | <a href="/doc/contribute.html">contribute your changes</a> |
| 241 | to the project, then move your repository |
Andrew Gerrand | 968f0df | 2014-12-12 13:53:29 +1100 | [diff] [blame] | 242 | off the release branch, and onto the master (development) branch. |
Jonathan Feinberg | 452f40f | 2012-09-26 14:39:31 -0400 | [diff] [blame] | 243 | Otherwise, skip this step.</p> |
| 244 | |
| 245 | <pre> |
Andrew Gerrand | 968f0df | 2014-12-12 13:53:29 +1100 | [diff] [blame] | 246 | $ git checkout master |
Jonathan Feinberg | 452f40f | 2012-09-26 14:39:31 -0400 | [diff] [blame] | 247 | </pre> |
| 248 | |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 249 | <h2 id="install">Install Go</h2> |
| 250 | |
| 251 | <p> |
| 252 | To build the Go distribution, run |
| 253 | </p> |
| 254 | |
| 255 | <pre> |
Lloyd Dewolf | 972f364 | 2015-02-25 10:57:45 -0800 | [diff] [blame] | 256 | $ cd src |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 257 | $ ./all.bash |
| 258 | </pre> |
| 259 | |
| 260 | <p> |
| 261 | (To build under Windows use <code>all.bat</code>.) |
| 262 | </p> |
| 263 | |
| 264 | <p> |
| 265 | If all goes well, it will finish by printing output like: |
| 266 | </p> |
| 267 | |
| 268 | <pre> |
| 269 | ALL TESTS PASSED |
| 270 | |
| 271 | --- |
| 272 | Installed Go for linux/amd64 in /home/you/go. |
| 273 | Installed commands in /home/you/go/bin. |
| 274 | *** You need to add /home/you/go/bin to your $PATH. *** |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 275 | </pre> |
| 276 | |
| 277 | <p> |
| 278 | where the details on the last few lines reflect the operating system, |
| 279 | architecture, and root directory used during the install. |
| 280 | </p> |
| 281 | |
| 282 | <div class="detail"> |
| 283 | <p> |
| 284 | For more information about ways to control the build, see the discussion of |
| 285 | <a href="#environment">environment variables</a> below. |
Shenghou Ma | c184940d | 2013-12-15 21:03:12 -0500 | [diff] [blame] | 286 | <code>all.bash</code> (or <code>all.bat</code>) runs important tests for Go, |
| 287 | which can take more time than simply building Go. If you do not want to run |
| 288 | the test suite use <code>make.bash</code> (or <code>make.bat</code>) |
| 289 | instead. |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 290 | </p> |
| 291 | </div> |
| 292 | |
| 293 | |
| 294 | <h2 id="testing">Testing your installation</h2> |
| 295 | |
| 296 | <p> |
| 297 | Check that Go is installed correctly by building a simple program. |
| 298 | </p> |
| 299 | |
| 300 | <p> |
| 301 | Create a file named <code>hello.go</code> and put the following program in it: |
| 302 | </p> |
| 303 | |
| 304 | <pre> |
| 305 | package main |
| 306 | |
| 307 | import "fmt" |
| 308 | |
| 309 | func main() { |
| 310 | fmt.Printf("hello, world\n") |
| 311 | } |
| 312 | </pre> |
| 313 | |
| 314 | <p> |
| 315 | Then run it with the <code>go</code> tool: |
| 316 | </p> |
| 317 | |
| 318 | <pre> |
| 319 | $ go run hello.go |
| 320 | hello, world |
| 321 | </pre> |
| 322 | |
| 323 | <p> |
| 324 | If you see the "hello, world" message then Go is installed correctly. |
| 325 | </p> |
| 326 | |
Andrew Gerrand | 9115a8b | 2012-06-13 10:33:02 +1000 | [diff] [blame] | 327 | <h2 id="gopath">Set up your work environment</h2> |
| 328 | |
| 329 | <p> |
Andrew Gerrand | c497c9e | 2013-11-21 07:55:29 +1100 | [diff] [blame] | 330 | You're almost done. |
| 331 | You just need to do a little more setup. |
Andrew Gerrand | 9115a8b | 2012-06-13 10:33:02 +1000 | [diff] [blame] | 332 | </p> |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 333 | |
Andrew Gerrand | c497c9e | 2013-11-21 07:55:29 +1100 | [diff] [blame] | 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> |
Kevin Burke | 64969c8 | 2016-12-01 17:45:26 -0800 | [diff] [blame] | 342 | The <a href="/doc/code.html">How to Write Go Code</a> document |
Andrew Gerrand | c497c9e | 2013-11-21 07:55:29 +1100 | [diff] [blame] | 343 | provides <b>essential setup instructions</b> for using the Go tools. |
| 344 | </p> |
| 345 | |
| 346 | |
Andrew Gerrand | b3caa86 | 2013-09-25 14:10:49 +1000 | [diff] [blame] | 347 | <h2 id="tools">Install additional tools</h2> |
| 348 | |
| 349 | <p> |
Andrew Gerrand | bc5e77f | 2013-09-25 14:27:23 +1000 | [diff] [blame] | 350 | The source code for several Go tools (including <a href="/cmd/godoc/">godoc</a>) |
Andrew Gerrand | 7f0be1f | 2014-11-10 09:15:57 +1100 | [diff] [blame] | 351 | is kept in <a href="https://golang.org/x/tools">the go.tools repository</a>. |
Andrew Gerrand | b3caa86 | 2013-09-25 14:10:49 +1000 | [diff] [blame] | 352 | To install all of them, run the <code>go</code> <code>get</code> command: |
| 353 | </p> |
| 354 | |
| 355 | <pre> |
Andrew Gerrand | 7f0be1f | 2014-11-10 09:15:57 +1100 | [diff] [blame] | 356 | $ go get golang.org/x/tools/cmd/... |
Andrew Gerrand | b3caa86 | 2013-09-25 14:10:49 +1000 | [diff] [blame] | 357 | </pre> |
| 358 | |
| 359 | <p> |
| 360 | Or if you just want to install a specific command (<code>godoc</code> in this case): |
| 361 | </p> |
| 362 | |
| 363 | <pre> |
Andrew Gerrand | 7f0be1f | 2014-11-10 09:15:57 +1100 | [diff] [blame] | 364 | $ go get golang.org/x/tools/cmd/godoc |
Andrew Gerrand | b3caa86 | 2013-09-25 14:10:49 +1000 | [diff] [blame] | 365 | </pre> |
| 366 | |
| 367 | <p> |
Kevin Burke | 64969c8 | 2016-12-01 17:45:26 -0800 | [diff] [blame] | 368 | To install these tools, the <code>go</code> <code>get</code> command requires |
Andrew Gerrand | 968f0df | 2014-12-12 13:53:29 +1100 | [diff] [blame] | 369 | that <a href="#git">Git</a> be installed locally. |
Andrew Gerrand | b3caa86 | 2013-09-25 14:10:49 +1000 | [diff] [blame] | 370 | </p> |
| 371 | |
| 372 | <p> |
| 373 | You must also have a workspace (<code>GOPATH</code>) set up; |
| 374 | see <a href="/doc/code.html">How to Write Go Code</a> for the details. |
| 375 | </p> |
| 376 | |
Andrew Gerrand | bc0e515 | 2013-09-25 18:15:29 +1000 | [diff] [blame] | 377 | <p> |
| 378 | <b>Note</b>: The <code>go</code> command will install the <code>godoc</code> |
| 379 | binary to <code>$GOROOT/bin</code> (or <code>$GOBIN</code>) and the |
| 380 | <code>cover</code> and <code>vet</code> binaries to |
| 381 | <code>$GOROOT/pkg/tool/$GOOS_$GOARCH</code>. |
| 382 | You can access the latter commands with |
| 383 | "<code>go</code> <code>tool</code> <code>cover</code>" and |
| 384 | "<code>go</code> <code>tool</code> <code>vet</code>". |
| 385 | </p> |
| 386 | |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 387 | <h2 id="community">Community resources</h2> |
| 388 | |
| 389 | <p> |
Rob Pike | 95d7d3d | 2012-03-03 09:36:09 +1100 | [diff] [blame] | 390 | The usual community resources such as |
| 391 | <code>#go-nuts</code> on the <a href="http://freenode.net/">Freenode</a> IRC server |
| 392 | and the |
Andrew Gerrand | 43ad89d | 2014-07-25 10:28:39 +1000 | [diff] [blame] | 393 | <a href="//groups.google.com/group/golang-nuts">Go Nuts</a> |
Rob Pike | 95d7d3d | 2012-03-03 09:36:09 +1100 | [diff] [blame] | 394 | mailing list have active developers that can help you with problems |
| 395 | with your installation or your development work. |
| 396 | For those who wish to keep up to date, |
Andrew Gerrand | 43ad89d | 2014-07-25 10:28:39 +1000 | [diff] [blame] | 397 | there is another mailing list, <a href="//groups.google.com/group/golang-checkins">golang-checkins</a>, |
Rob Pike | 95d7d3d | 2012-03-03 09:36:09 +1100 | [diff] [blame] | 398 | that receives a message summarizing each checkin to the Go repository. |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 399 | </p> |
| 400 | |
| 401 | <p> |
Andrew Gerrand | 968f0df | 2014-12-12 13:53:29 +1100 | [diff] [blame] | 402 | Bugs can be reported using the <a href="//golang.org/issue/new">Go issue tracker</a>. |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 403 | </p> |
| 404 | |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 405 | |
| 406 | <h2 id="releases">Keeping up with releases</h2> |
| 407 | |
| 408 | <p> |
Andrew Gerrand | 968f0df | 2014-12-12 13:53:29 +1100 | [diff] [blame] | 409 | New releases are announced on the |
Andrew Gerrand | 43ad89d | 2014-07-25 10:28:39 +1000 | [diff] [blame] | 410 | <a href="//groups.google.com/group/golang-announce">golang-announce</a> |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 411 | mailing list. |
Andrew Gerrand | 968f0df | 2014-12-12 13:53:29 +1100 | [diff] [blame] | 412 | Each announcement mentions the latest release tag, for instance, |
Chris Broadfoot | d77dfba | 2017-08-24 11:52:35 -0700 | [diff] [blame] | 413 | <code class="versionTag">go1.9</code>. |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 414 | </p> |
| 415 | |
| 416 | <p> |
| 417 | To update an existing tree to the latest release, you can run: |
| 418 | </p> |
| 419 | |
| 420 | <pre> |
| 421 | $ cd go/src |
Andrew Gerrand | 968f0df | 2014-12-12 13:53:29 +1100 | [diff] [blame] | 422 | $ git fetch |
Andrew Gerrand | d093a62 | 2016-04-14 12:12:11 +1000 | [diff] [blame] | 423 | $ git checkout <span class="versionTag"><i><tag></i></psan> |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 424 | $ ./all.bash |
| 425 | </pre> |
| 426 | |
Andrew Gerrand | d093a62 | 2016-04-14 12:12:11 +1000 | [diff] [blame] | 427 | <p class="whereTag"> |
Andrew Gerrand | 968f0df | 2014-12-12 13:53:29 +1100 | [diff] [blame] | 428 | Where <code><tag></code> is the version string of the release. |
Andrew Gerrand | d093a62 | 2016-04-14 12:12:11 +1000 | [diff] [blame] | 429 | </p> |
Andrew Gerrand | 968f0df | 2014-12-12 13:53:29 +1100 | [diff] [blame] | 430 | |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 431 | |
| 432 | <h2 id="environment">Optional environment variables</h2> |
| 433 | |
| 434 | <p> |
| 435 | The Go compilation environment can be customized by environment variables. |
Rob Pike | 95d7d3d | 2012-03-03 09:36:09 +1100 | [diff] [blame] | 436 | <i>None is required by the build</i>, but you may wish to set some |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 437 | to override the defaults. |
| 438 | </p> |
| 439 | |
Shenghou Ma | 1771912 | 2013-06-09 23:15:39 +0800 | [diff] [blame] | 440 | <ul> |
| 441 | <li><code>$GOROOT</code> |
Andrew Gerrand | d70627e | 2012-03-06 15:16:02 +1100 | [diff] [blame] | 442 | <p> |
Russ Cox | 74628a8 | 2016-11-30 14:56:58 -0500 | [diff] [blame] | 443 | The root of the Go tree, often <code>$HOME/go1.X</code>. |
Andrew Gerrand | d70627e | 2012-03-06 15:16:02 +1100 | [diff] [blame] | 444 | Its value is built into the tree when it is compiled, and |
| 445 | defaults to the parent of the directory where <code>all.bash</code> was run. |
| 446 | There is no need to set this unless you want to switch between multiple |
| 447 | local copies of the repository. |
| 448 | </p> |
Brad Fitzpatrick | bcc86d5 | 2018-01-30 16:55:27 +0000 | [diff] [blame] | 449 | </li> |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 450 | |
Shenghou Ma | 1771912 | 2013-06-09 23:15:39 +0800 | [diff] [blame] | 451 | <li><code>$GOROOT_FINAL</code> |
Andrew Gerrand | d70627e | 2012-03-06 15:16:02 +1100 | [diff] [blame] | 452 | <p> |
| 453 | The value assumed by installed binaries and scripts when |
| 454 | <code>$GOROOT</code> is not set explicitly. |
| 455 | It defaults to the value of <code>$GOROOT</code>. |
| 456 | If you want to build the Go tree in one location |
Kevin Burke | 64969c8 | 2016-12-01 17:45:26 -0800 | [diff] [blame] | 457 | but move it elsewhere after the build, set |
Andrew Gerrand | d70627e | 2012-03-06 15:16:02 +1100 | [diff] [blame] | 458 | <code>$GOROOT_FINAL</code> to the eventual location. |
| 459 | </p> |
Brad Fitzpatrick | bcc86d5 | 2018-01-30 16:55:27 +0000 | [diff] [blame] | 460 | </li> |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 461 | |
Shenghou Ma | 1771912 | 2013-06-09 23:15:39 +0800 | [diff] [blame] | 462 | <li><code>$GOOS</code> and <code>$GOARCH</code> |
Andrew Gerrand | d70627e | 2012-03-06 15:16:02 +1100 | [diff] [blame] | 463 | <p> |
| 464 | The name of the target operating system and compilation architecture. |
| 465 | These default to the values of <code>$GOHOSTOS</code> and |
| 466 | <code>$GOHOSTARCH</code> respectively (described below). |
Brad Fitzpatrick | bcc86d5 | 2018-01-30 16:55:27 +0000 | [diff] [blame] | 467 | </li> |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 468 | |
Andrew Gerrand | d70627e | 2012-03-06 15:16:02 +1100 | [diff] [blame] | 469 | <p> |
| 470 | Choices for <code>$GOOS</code> are |
Brad Fitzpatrick | cfea260 | 2016-09-09 05:26:20 +0000 | [diff] [blame] | 471 | <code>darwin</code> (Mac OS X 10.8 and above and iOS), <code>dragonfly</code>, <code>freebsd</code>, |
Michael Hudson-Doyle | f74ea6c | 2015-06-10 21:56:01 +1200 | [diff] [blame] | 472 | <code>linux</code>, <code>netbsd</code>, <code>openbsd</code>, |
Shenghou Ma | 708a53f9 | 2014-03-25 23:21:28 -0400 | [diff] [blame] | 473 | <code>plan9</code>, <code>solaris</code> and <code>windows</code>. |
Andrew Gerrand | d70627e | 2012-03-06 15:16:02 +1100 | [diff] [blame] | 474 | Choices for <code>$GOARCH</code> are |
| 475 | <code>amd64</code> (64-bit x86, the most mature port), |
Michael Hudson-Doyle | f74ea6c | 2015-06-10 21:56:01 +1200 | [diff] [blame] | 476 | <code>386</code> (32-bit x86), <code>arm</code> (32-bit ARM), <code>arm64</code> (64-bit ARM), |
Shenghou Ma | d75391a | 2015-11-13 03:12:26 -0500 | [diff] [blame] | 477 | <code>ppc64le</code> (PowerPC 64-bit, little-endian), <code>ppc64</code> (PowerPC 64-bit, big-endian), |
Michael Munday | c2f8ed2 | 2017-08-23 12:45:27 +0100 | [diff] [blame] | 478 | <code>mips64le</code> (MIPS 64-bit, little-endian), <code>mips64</code> (MIPS 64-bit, big-endian), |
| 479 | <code>mipsle</code> (MIPS 32-bit, little-endian), <code>mips</code> (MIPS 32-bit, big-endian), and |
| 480 | <code>s390x</code> (IBM System z 64-bit, big-endian). |
Andrew Gerrand | d70627e | 2012-03-06 15:16:02 +1100 | [diff] [blame] | 481 | The valid combinations of <code>$GOOS</code> and <code>$GOARCH</code> are: |
| 482 | <table cellpadding="0"> |
| 483 | <tr> |
Shenghou Ma | 1771912 | 2013-06-09 23:15:39 +0800 | [diff] [blame] | 484 | <th width="50"></th><th align="left" width="100"><code>$GOOS</code></th> <th align="left" width="100"><code>$GOARCH</code></th> |
Andrew Gerrand | d70627e | 2012-03-06 15:16:02 +1100 | [diff] [blame] | 485 | </tr> |
| 486 | <tr> |
Burcu Dogan | 9e173f9 | 2016-02-24 15:06:03 -0800 | [diff] [blame] | 487 | <td></td><td><code>android</code></td> <td><code>arm</code></td> |
| 488 | </tr> |
| 489 | <tr> |
Andrew Gerrand | d70627e | 2012-03-06 15:16:02 +1100 | [diff] [blame] | 490 | <td></td><td><code>darwin</code></td> <td><code>386</code></td> |
| 491 | </tr> |
| 492 | <tr> |
| 493 | <td></td><td><code>darwin</code></td> <td><code>amd64</code></td> |
| 494 | </tr> |
| 495 | <tr> |
Michael Hudson-Doyle | f74ea6c | 2015-06-10 21:56:01 +1200 | [diff] [blame] | 496 | <td></td><td><code>darwin</code></td> <td><code>arm</code></td> |
| 497 | </tr> |
| 498 | <tr> |
| 499 | <td></td><td><code>darwin</code></td> <td><code>arm64</code></td> |
Mikio Hara | 3476704 | 2014-03-26 14:06:18 +0900 | [diff] [blame] | 500 | </tr> |
| 501 | <tr> |
| 502 | <td></td><td><code>dragonfly</code></td> <td><code>amd64</code></td> |
| 503 | </tr> |
| 504 | <tr> |
Andrew Gerrand | d70627e | 2012-03-06 15:16:02 +1100 | [diff] [blame] | 505 | <td></td><td><code>freebsd</code></td> <td><code>386</code></td> |
| 506 | </tr> |
| 507 | <tr> |
| 508 | <td></td><td><code>freebsd</code></td> <td><code>amd64</code></td> |
| 509 | </tr> |
| 510 | <tr> |
Shenghou Ma | 1771912 | 2013-06-09 23:15:39 +0800 | [diff] [blame] | 511 | <td></td><td><code>freebsd</code></td> <td><code>arm</code></td> |
| 512 | </tr> |
| 513 | <tr> |
Andrew Gerrand | d70627e | 2012-03-06 15:16:02 +1100 | [diff] [blame] | 514 | <td></td><td><code>linux</code></td> <td><code>386</code></td> |
| 515 | </tr> |
| 516 | <tr> |
| 517 | <td></td><td><code>linux</code></td> <td><code>amd64</code></td> |
| 518 | </tr> |
| 519 | <tr> |
| 520 | <td></td><td><code>linux</code></td> <td><code>arm</code></td> |
| 521 | </tr> |
| 522 | <tr> |
Michael Hudson-Doyle | f74ea6c | 2015-06-10 21:56:01 +1200 | [diff] [blame] | 523 | <td></td><td><code>linux</code></td> <td><code>arm64</code></td> |
| 524 | </tr> |
| 525 | <tr> |
| 526 | <td></td><td><code>linux</code></td> <td><code>ppc64</code></td> |
| 527 | </tr> |
| 528 | <tr> |
| 529 | <td></td><td><code>linux</code></td> <td><code>ppc64le</code></td> |
| 530 | </tr> |
| 531 | <tr> |
Shenghou Ma | 8adff32 | 2016-12-01 23:12:18 -0500 | [diff] [blame] | 532 | <td></td><td><code>linux</code></td> <td><code>mips</code></td> |
| 533 | </tr> |
| 534 | <tr> |
| 535 | <td></td><td><code>linux</code></td> <td><code>mipsle</code></td> |
| 536 | </tr> |
| 537 | <tr> |
Shenghou Ma | d75391a | 2015-11-13 03:12:26 -0500 | [diff] [blame] | 538 | <td></td><td><code>linux</code></td> <td><code>mips64</code></td> |
| 539 | </tr> |
| 540 | <tr> |
| 541 | <td></td><td><code>linux</code></td> <td><code>mips64le</code></td> |
| 542 | </tr> |
| 543 | <tr> |
Michael Munday | c2f8ed2 | 2017-08-23 12:45:27 +0100 | [diff] [blame] | 544 | <td></td><td><code>linux</code></td> <td><code>s390x</code></td> |
| 545 | </tr> |
| 546 | <tr> |
Andrew Gerrand | d70627e | 2012-03-06 15:16:02 +1100 | [diff] [blame] | 547 | <td></td><td><code>netbsd</code></td> <td><code>386</code></td> |
| 548 | </tr> |
| 549 | <tr> |
| 550 | <td></td><td><code>netbsd</code></td> <td><code>amd64</code></td> |
| 551 | </tr> |
| 552 | <tr> |
Shenghou Ma | 1771912 | 2013-06-09 23:15:39 +0800 | [diff] [blame] | 553 | <td></td><td><code>netbsd</code></td> <td><code>arm</code></td> |
| 554 | </tr> |
| 555 | <tr> |
Andrew Gerrand | d70627e | 2012-03-06 15:16:02 +1100 | [diff] [blame] | 556 | <td></td><td><code>openbsd</code></td> <td><code>386</code></td> |
| 557 | </tr> |
| 558 | <tr> |
| 559 | <td></td><td><code>openbsd</code></td> <td><code>amd64</code></td> |
| 560 | </tr> |
| 561 | <tr> |
Michael Hudson-Doyle | f74ea6c | 2015-06-10 21:56:01 +1200 | [diff] [blame] | 562 | <td></td><td><code>openbsd</code></td> <td><code>arm</code></td> |
| 563 | </tr> |
| 564 | <tr> |
Andrew Gerrand | d70627e | 2012-03-06 15:16:02 +1100 | [diff] [blame] | 565 | <td></td><td><code>plan9</code></td> <td><code>386</code></td> |
| 566 | </tr> |
| 567 | <tr> |
Shenghou Ma | 1771912 | 2013-06-09 23:15:39 +0800 | [diff] [blame] | 568 | <td></td><td><code>plan9</code></td> <td><code>amd64</code></td> |
| 569 | </tr> |
| 570 | <tr> |
Shenghou Ma | 708a53f9 | 2014-03-25 23:21:28 -0400 | [diff] [blame] | 571 | <td></td><td><code>solaris</code></td> <td><code>amd64</code></td> |
| 572 | </tr> |
| 573 | <tr> |
Andrew Gerrand | d70627e | 2012-03-06 15:16:02 +1100 | [diff] [blame] | 574 | <td></td><td><code>windows</code></td> <td><code>386</code></td> |
| 575 | </tr> |
| 576 | <tr> |
| 577 | <td></td><td><code>windows</code></td> <td><code>amd64</code></td> |
| 578 | </tr> |
| 579 | </table> |
Hari haran | 4230c73 | 2015-07-22 16:30:32 +0530 | [diff] [blame] | 580 | <br> |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 581 | |
Shenghou Ma | 1771912 | 2013-06-09 23:15:39 +0800 | [diff] [blame] | 582 | <li><code>$GOHOSTOS</code> and <code>$GOHOSTARCH</code> |
Andrew Gerrand | d70627e | 2012-03-06 15:16:02 +1100 | [diff] [blame] | 583 | <p> |
| 584 | The name of the host operating system and compilation architecture. |
| 585 | These default to the local system's operating system and |
| 586 | architecture. |
| 587 | </p> |
Brad Fitzpatrick | bcc86d5 | 2018-01-30 16:55:27 +0000 | [diff] [blame] | 588 | </li> |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 589 | |
Andrew Gerrand | d70627e | 2012-03-06 15:16:02 +1100 | [diff] [blame] | 590 | <p> |
| 591 | Valid choices are the same as for <code>$GOOS</code> and |
| 592 | <code>$GOARCH</code>, listed above. |
| 593 | The specified values must be compatible with the local system. |
Kevin Burke | 64969c8 | 2016-12-01 17:45:26 -0800 | [diff] [blame] | 594 | For example, you should not set <code>$GOHOSTARCH</code> to |
Andrew Gerrand | d70627e | 2012-03-06 15:16:02 +1100 | [diff] [blame] | 595 | <code>arm</code> on an x86 system. |
| 596 | </p> |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 597 | |
Shenghou Ma | 1771912 | 2013-06-09 23:15:39 +0800 | [diff] [blame] | 598 | <li><code>$GOBIN</code> |
Andrew Gerrand | d70627e | 2012-03-06 15:16:02 +1100 | [diff] [blame] | 599 | <p> |
Russ Cox | 9d7076b | 2012-03-27 11:57:39 -0400 | [diff] [blame] | 600 | The location where Go binaries will be installed. |
Andrew Gerrand | d70627e | 2012-03-06 15:16:02 +1100 | [diff] [blame] | 601 | The default is <code>$GOROOT/bin</code>. |
| 602 | After installing, you will want to arrange to add this |
| 603 | directory to your <code>$PATH</code>, so you can use the tools. |
Russ Cox | 9d7076b | 2012-03-27 11:57:39 -0400 | [diff] [blame] | 604 | If <code>$GOBIN</code> is set, the <a href="/cmd/go">go command</a> |
| 605 | installs all commands there. |
Andrew Gerrand | d70627e | 2012-03-06 15:16:02 +1100 | [diff] [blame] | 606 | </p> |
Brad Fitzpatrick | bcc86d5 | 2018-01-30 16:55:27 +0000 | [diff] [blame] | 607 | </li> |
Andrew Gerrand | d70627e | 2012-03-06 15:16:02 +1100 | [diff] [blame] | 608 | |
Shenghou Ma | 1771912 | 2013-06-09 23:15:39 +0800 | [diff] [blame] | 609 | <li><code>$GO386</code> (for <code>386</code> only, default is auto-detected |
Shenghou Ma | ae1b5c7 | 2014-06-04 19:53:37 -0400 | [diff] [blame] | 610 | if built on either <code>386</code> or <code>amd64</code>, <code>387</code> otherwise) |
Andrew Gerrand | d70627e | 2012-03-06 15:16:02 +1100 | [diff] [blame] | 611 | <p> |
Aaron Jacobs | 8628688 | 2015-06-24 09:50:12 +1000 | [diff] [blame] | 612 | This controls the code generated by gc to use either the 387 floating-point unit |
Shenghou Ma | 1771912 | 2013-06-09 23:15:39 +0800 | [diff] [blame] | 613 | (set to <code>387</code>) or SSE2 instructions (set to <code>sse2</code>) for |
| 614 | floating point computations. |
| 615 | </p> |
| 616 | <ul> |
Brad Fitzpatrick | bcc86d5 | 2018-01-30 16:55:27 +0000 | [diff] [blame] | 617 | <li><code>GO386=387</code>: use x87 for floating point operations; should support all x86 chips (Pentium MMX or later).</li> |
| 618 | <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> |
Shenghou Ma | 1771912 | 2013-06-09 23:15:39 +0800 | [diff] [blame] | 619 | </ul> |
Brad Fitzpatrick | bcc86d5 | 2018-01-30 16:55:27 +0000 | [diff] [blame] | 620 | </li> |
Shenghou Ma | 1771912 | 2013-06-09 23:15:39 +0800 | [diff] [blame] | 621 | |
| 622 | <li><code>$GOARM</code> (for <code>arm</code> only; default is auto-detected if building |
| 623 | on the target processor, 6 if not) |
| 624 | <p> |
| 625 | This sets the ARM floating point co-processor architecture version the run-time |
| 626 | should target. If you are compiling on the target system, its value will be auto-detected. |
| 627 | </p> |
| 628 | <ul> |
Brad Fitzpatrick | bcc86d5 | 2018-01-30 16:55:27 +0000 | [diff] [blame] | 629 | <li><code>GOARM=5</code>: use software floating point; when CPU doesn't have VFP co-processor</li> |
| 630 | <li><code>GOARM=6</code>: use VFPv1 only; default if cross compiling; usually ARM11 or better cores (VFPv2 or better is also supported)</li> |
| 631 | <li><code>GOARM=7</code>: use VFPv3; usually Cortex-A cores</li> |
Shenghou Ma | 1771912 | 2013-06-09 23:15:39 +0800 | [diff] [blame] | 632 | </ul> |
| 633 | <p> |
| 634 | If in doubt, leave this variable unset, and adjust it if required |
| 635 | when you first run the Go executable. |
Andrew Gerrand | 43ad89d | 2014-07-25 10:28:39 +1000 | [diff] [blame] | 636 | The <a href="//golang.org/wiki/GoArm">GoARM</a> page |
| 637 | on the <a href="//golang.org/wiki">Go community wiki</a> |
Shenghou Ma | 1771912 | 2013-06-09 23:15:39 +0800 | [diff] [blame] | 638 | contains further details regarding Go's ARM support. |
Andrew Gerrand | d70627e | 2012-03-06 15:16:02 +1100 | [diff] [blame] | 639 | </p> |
Brad Fitzpatrick | bcc86d5 | 2018-01-30 16:55:27 +0000 | [diff] [blame] | 640 | </li> |
| 641 | |
| 642 | <li><code>$GOMIPS</code> (for <code>mips</code> and <code>mipsle</code> only) |
| 643 | <p> |
| 644 | This sets whether to use floating point instructions. |
| 645 | </p> |
| 646 | <ul> |
| 647 | <li><code>GOMIPS=hardfloat</code>: use floating point instructions (the default)</li> |
| 648 | <li><code>GOMIPS=softfloat</code>: use soft floating point</li> |
| 649 | </ul> |
| 650 | </li> |
Andrew Gerrand | d70627e | 2012-03-06 15:16:02 +1100 | [diff] [blame] | 651 | |
Shenghou Ma | 1771912 | 2013-06-09 23:15:39 +0800 | [diff] [blame] | 652 | </ul> |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 653 | |
| 654 | <p> |
| 655 | Note that <code>$GOARCH</code> and <code>$GOOS</code> identify the |
| 656 | <em>target</em> environment, not the environment you are running on. |
| 657 | In effect, you are always cross-compiling. |
| 658 | By architecture, we mean the kind of binaries |
| 659 | that the target environment can run: |
| 660 | an x86-64 system running a 32-bit-only operating system |
| 661 | must set <code>GOARCH</code> to <code>386</code>, |
| 662 | not <code>amd64</code>. |
| 663 | </p> |
| 664 | |
| 665 | <p> |
| 666 | If you choose to override the defaults, |
| 667 | set these variables in your shell profile (<code>$HOME/.bashrc</code>, |
Kevin Burke | 64969c8 | 2016-12-01 17:45:26 -0800 | [diff] [blame] | 668 | <code>$HOME/.profile</code>, or equivalent). The settings might look |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 669 | something like this: |
| 670 | </p> |
| 671 | |
| 672 | <pre> |
Russ Cox | 74628a8 | 2016-11-30 14:56:58 -0500 | [diff] [blame] | 673 | export GOROOT=$HOME/go1.X |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 674 | export GOARCH=amd64 |
| 675 | export GOOS=linux |
| 676 | </pre> |
Rob Pike | 95d7d3d | 2012-03-03 09:36:09 +1100 | [diff] [blame] | 677 | |
| 678 | <p> |
| 679 | although, to reiterate, none of these variables needs to be set to build, |
| 680 | install, and develop the Go tree. |
| 681 | </p> |