Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 1 | <!--{ |
| 2 | "Title": "Installing Go from source", |
| 3 | "Path": "/doc/install/source" |
| 4 | }--> |
| 5 | |
| 6 | <h2 id="introduction">Introduction</h2> |
| 7 | |
| 8 | <p> |
| 9 | Go is an open source project, distributed under a |
| 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 | |
| 15 | <p> |
| 16 | Most users don't need to do this, and will instead install |
| 17 | from precompiled binary packages as described in |
| 18 | <a href="/doc/install">Getting Started</a>, |
| 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 | |
| 24 | <div class="detail"> |
| 25 | |
| 26 | <p> |
Dan Willemsen | e1b3b18 | 2018-02-27 19:36:27 -0800 | [diff] [blame] | 27 | There are two official Go compiler toolchains. |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 28 | This document focuses on the <code>gc</code> Go |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 29 | compiler and tools. |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 30 | For information on how to work on <code>gccgo</code>, a more traditional |
| 31 | compiler using the GCC back end, see |
| 32 | <a href="/doc/install/gccgo">Setting up and using gccgo</a>. |
| 33 | </p> |
| 34 | |
| 35 | <p> |
Colin Cross | efed634 | 2019-09-07 08:34:44 -0700 | [diff] [blame^] | 36 | The Go compilers support nine instruction sets. |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [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> |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 43 | <code>amd64</code> (also known as <code>x86-64</code>) |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 44 | </dt> |
| 45 | <dd> |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 46 | A mature implementation. |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 47 | </dd> |
| 48 | <dt> |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 49 | <code>386</code> (<code>x86</code> or <code>x86-32</code>) |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 50 | </dt> |
| 51 | <dd> |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 52 | Comparable to the <code>amd64</code> port. |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 53 | </dd> |
| 54 | <dt> |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 55 | <code>arm</code> (<code>ARM</code>) |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 56 | </dt> |
| 57 | <dd> |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 58 | Supports Linux, FreeBSD, NetBSD, OpenBSD and Darwin binaries. Less widely used than the other ports. |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 59 | </dd> |
| 60 | <dt> |
| 61 | <code>arm64</code> (<code>AArch64</code>) |
| 62 | </dt> |
| 63 | <dd> |
Dan Willemsen | 0c15709 | 2016-07-08 13:57:52 -0700 | [diff] [blame] | 64 | Supports Linux and Darwin binaries. New in 1.5 and not as well exercised as other ports. |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 65 | </dd> |
| 66 | <dt> |
| 67 | <code>ppc64, ppc64le</code> (64-bit PowerPC big- and little-endian) |
| 68 | </dt> |
| 69 | <dd> |
Dan Willemsen | 0c15709 | 2016-07-08 13:57:52 -0700 | [diff] [blame] | 70 | Supports Linux binaries. New in 1.5 and not as well exercised as other ports. |
| 71 | </dd> |
| 72 | <dt> |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [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> |
Dan Willemsen | 0c15709 | 2016-07-08 13:57:52 -0700 | [diff] [blame] | 79 | <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 Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 89 | </dd> |
Colin Cross | efed634 | 2019-09-07 08:34:44 -0700 | [diff] [blame^] | 90 | <dt> |
| 91 | <code>wasm</code> (WebAssembly) |
| 92 | </dt> |
| 93 | <dd> |
| 94 | Targets the WebAssembly platform. New in 1.11 and not as well exercised as other ports. |
| 95 | </dd> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 96 | </dl> |
| 97 | |
| 98 | <p> |
| 99 | Except for things like low-level operating system interface code, the run-time |
| 100 | support is the same in all ports and includes a mark-and-sweep garbage |
| 101 | collector, efficient array and string slicing, and support for efficient |
| 102 | goroutines, such as stacks that grow and shrink on demand. |
| 103 | </p> |
| 104 | |
| 105 | <p> |
| 106 | The compilers can target the DragonFly BSD, FreeBSD, Linux, NetBSD, OpenBSD, |
Dan Willemsen | f3f2eb6 | 2018-08-28 11:28:58 -0700 | [diff] [blame] | 107 | macOS (Darwin), Plan 9, Solaris and Windows operating systems. |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 108 | The full set of supported combinations is listed in the discussion of |
| 109 | <a href="#environment">environment variables</a> below. |
| 110 | </p> |
| 111 | |
Dan Willemsen | 0c15709 | 2016-07-08 13:57:52 -0700 | [diff] [blame] | 112 | <p> |
| 113 | See the main installation page for the <a href="/doc/install#requirements">overall system requirements</a>. |
| 114 | The following additional constraints apply to systems that can be built only from source: |
| 115 | </p> |
| 116 | |
| 117 | <ul> |
| 118 | <li>For Linux on PowerPC 64-bit, the minimum supported kernel version is 2.6.37, meaning that |
| 119 | Go does not support CentOS 6 on these systems. |
| 120 | </li> |
| 121 | </ul> |
| 122 | |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 123 | </div> |
| 124 | |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 125 | <h2 id="go14">Install Go compiler binaries</h2> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 126 | |
| 127 | <p> |
Dan Willemsen | e1b3b18 | 2018-02-27 19:36:27 -0800 | [diff] [blame] | 128 | The Go toolchain is written in Go. To build it, you need a Go compiler installed. |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 129 | The scripts that do the initial build of the tools look for an existing Go tool |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 130 | chain in <code>$GOROOT_BOOTSTRAP</code>. |
| 131 | If unset, the default value of <code>GOROOT_BOOTSTRAP</code> |
| 132 | is <code>$HOME/go1.4</code>. |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 133 | </p> |
| 134 | |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 135 | <p> |
Dan Willemsen | e1b3b18 | 2018-02-27 19:36:27 -0800 | [diff] [blame] | 136 | There are many options for the bootstrap toolchain. |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 137 | After obtaining one, set <code>GOROOT_BOOTSTRAP</code> to the |
| 138 | directory containing the unpacked tree. |
| 139 | For example, <code>$GOROOT_BOOTSTRAP/bin/go</code> should be |
Dan Willemsen | e1b3b18 | 2018-02-27 19:36:27 -0800 | [diff] [blame] | 140 | the <code>go</code> command binary for the bootstrap toolchain. |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 141 | </p> |
| 142 | |
Colin Cross | efed634 | 2019-09-07 08:34:44 -0700 | [diff] [blame^] | 143 | <h3 id="bootstrapFromBinaryRelease">Bootstrap toolchain from binary release</h3> |
| 144 | |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 145 | <p> |
Dan Willemsen | e1b3b18 | 2018-02-27 19:36:27 -0800 | [diff] [blame] | 146 | To use a binary release as a bootstrap toolchain, see |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 147 | <a href="/dl/">the downloads page</a> or use any other |
| 148 | packaged Go distribution. |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 149 | </p> |
| 150 | |
Colin Cross | efed634 | 2019-09-07 08:34:44 -0700 | [diff] [blame^] | 151 | <h3 id="bootstrapFromSource">Bootstrap toolchain from source</h3> |
| 152 | |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 153 | <p> |
Dan Willemsen | e1b3b18 | 2018-02-27 19:36:27 -0800 | [diff] [blame] | 154 | To build a bootstrap toolchain from source, use |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 155 | either the git branch <code>release-branch.go1.4</code> or |
Dan Willemsen | e1b3b18 | 2018-02-27 19:36:27 -0800 | [diff] [blame] | 156 | <a href="https://dl.google.com/go/go1.4-bootstrap-20171003.tar.gz">go1.4-bootstrap-20171003.tar.gz</a>, |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 157 | which contains the Go 1.4 source code plus accumulated fixes |
| 158 | to keep the tools running on newer operating systems. |
Dan Willemsen | e1b3b18 | 2018-02-27 19:36:27 -0800 | [diff] [blame] | 159 | (Go 1.4 was the last distribution in which the toolchain was written in C.) |
Dan Willemsen | a727cd0 | 2017-02-21 17:11:40 -0800 | [diff] [blame] | 160 | After unpacking the Go 1.4 source, <code>cd</code> to |
Dan Willemsen | e1b3b18 | 2018-02-27 19:36:27 -0800 | [diff] [blame] | 161 | the <code>src</code> subdirectory, set <code>CGO_ENABLED=0</code> in |
| 162 | the environment, and run <code>make.bash</code> (or, |
Dan Willemsen | a727cd0 | 2017-02-21 17:11:40 -0800 | [diff] [blame] | 163 | on Windows, <code>make.bat</code>). |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 164 | </p> |
| 165 | |
| 166 | <p> |
Colin Cross | efed634 | 2019-09-07 08:34:44 -0700 | [diff] [blame^] | 167 | Once the Go 1.4 source has been unpacked into your GOROOT_BOOTSTRAP directory, |
| 168 | you must keep this git clone instance checked out to branch |
| 169 | <code>release-branch.go1.4</code>. Specifically, do not attempt to reuse |
| 170 | this git clone in the later step named "Fetch the repository." The go1.4 |
| 171 | bootstrap toolchain <b>must be able</b> to properly traverse the go1.4 sources |
| 172 | that it assumes are present under this repository root. |
| 173 | </p> |
| 174 | |
| 175 | <h3 id="bootstrapFromCrosscompiledSource">Bootstrap toolchain from cross-compiled source</h3> |
| 176 | |
| 177 | <p> |
Dan Willemsen | e1b3b18 | 2018-02-27 19:36:27 -0800 | [diff] [blame] | 178 | To cross-compile a bootstrap toolchain from source, which is |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 179 | necessary on systems Go 1.4 did not target (for |
| 180 | example, <code>linux/ppc64le</code>), install Go on a different system |
| 181 | and run <a href="/src/bootstrap.bash">bootstrap.bash</a>. |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 182 | </p> |
| 183 | |
| 184 | <p> |
| 185 | When run as (for example) |
| 186 | </p> |
| 187 | |
| 188 | <pre> |
| 189 | $ GOOS=linux GOARCH=ppc64 ./bootstrap.bash |
| 190 | </pre> |
| 191 | |
| 192 | <p> |
| 193 | <code>bootstrap.bash</code> cross-compiles a toolchain for that <code>GOOS/GOARCH</code> |
| 194 | combination, leaving the resulting tree in <code>../../go-${GOOS}-${GOARCH}-bootstrap</code>. |
| 195 | That tree can be copied to a machine of the given target type |
| 196 | and used as <code>GOROOT_BOOTSTRAP</code> to bootstrap a local build. |
| 197 | </p> |
| 198 | |
Colin Cross | efed634 | 2019-09-07 08:34:44 -0700 | [diff] [blame^] | 199 | <h3 id="bootstrapFromGccgo">Bootstrap toolchain using gccgo</h3> |
| 200 | |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 201 | <p> |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 202 | To use gccgo as the bootstrap toolchain, you need to arrange |
| 203 | for <code>$GOROOT_BOOTSTRAP/bin/go</code> to be the go tool that comes |
| 204 | as part of gccgo 5. For example on Ubuntu Vivid: |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 205 | </p> |
| 206 | |
| 207 | <pre> |
| 208 | $ sudo apt-get install gccgo-5 |
| 209 | $ sudo update-alternatives --set go /usr/bin/go-5 |
| 210 | $ GOROOT_BOOTSTRAP=/usr ./make.bash |
| 211 | </pre> |
| 212 | |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 213 | <h2 id="git">Install Git, if needed</h2> |
| 214 | |
| 215 | <p> |
| 216 | To perform the next step you must have Git installed. (Check that you |
| 217 | have a <code>git</code> command before proceeding.) |
| 218 | </p> |
| 219 | |
| 220 | <p> |
| 221 | If you do not have a working Git installation, |
| 222 | follow the instructions on the |
Dan Willemsen | f3f2eb6 | 2018-08-28 11:28:58 -0700 | [diff] [blame] | 223 | <a href="https://git-scm.com/downloads">Git downloads</a> page. |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 224 | </p> |
| 225 | |
Dan Willemsen | 0c15709 | 2016-07-08 13:57:52 -0700 | [diff] [blame] | 226 | <h2 id="ccompiler">(Optional) Install a C compiler</h2> |
| 227 | |
| 228 | <p> |
| 229 | To build a Go installation |
| 230 | with <code><a href="/cmd/cgo">cgo</a></code> support, which permits Go |
| 231 | programs to import C libraries, a C compiler such as <code>gcc</code> |
| 232 | or <code>clang</code> must be installed first. Do this using whatever |
| 233 | installation method is standard on the system. |
| 234 | </p> |
| 235 | |
| 236 | <p> |
| 237 | To build without <code>cgo</code>, set the environment variable |
| 238 | <code>CGO_ENABLED=0</code> before running <code>all.bash</code> or |
| 239 | <code>make.bash</code>. |
| 240 | </p> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 241 | |
| 242 | <h2 id="fetch">Fetch the repository</h2> |
| 243 | |
Colin Cross | efed634 | 2019-09-07 08:34:44 -0700 | [diff] [blame^] | 244 | <p>Change to the directory where you intend to install Go, and make sure |
| 245 | the <code>goroot</code> directory does not exist. Then clone the repository |
| 246 | and check out the latest release tag (<code class="versionTag">go1.12</code>, |
| 247 | for example):</p> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 248 | |
| 249 | <pre> |
Colin Cross | efed634 | 2019-09-07 08:34:44 -0700 | [diff] [blame^] | 250 | $ git clone https://go.googlesource.com/go goroot |
| 251 | $ cd goroot |
Dan Willemsen | 0c15709 | 2016-07-08 13:57:52 -0700 | [diff] [blame] | 252 | $ git checkout <span class="versionTag"><i><tag></i></span> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 253 | </pre> |
| 254 | |
Dan Willemsen | 0c15709 | 2016-07-08 13:57:52 -0700 | [diff] [blame] | 255 | <p class="whereTag"> |
| 256 | Where <code><tag></code> is the version string of the release. |
| 257 | </p> |
| 258 | |
Colin Cross | efed634 | 2019-09-07 08:34:44 -0700 | [diff] [blame^] | 259 | <p>Go will be installed in the directory where it is checked out. For example, |
| 260 | if Go is checked out in <code>$HOME/goroot</code>, executables will be installed |
| 261 | in <code>$HOME/goroot/bin</code>. The directory may have any name, but note |
| 262 | that if Go is checked out in <code>$HOME/go</code>, it will conflict with |
| 263 | the default location of <code>$GOPATH</code>. |
| 264 | See <a href="#gopath"><code>GOPATH</code></a> below.</p> |
| 265 | |
| 266 | Reminder: If you opted to also compile the bootstrap binaries from source (in an |
| 267 | earlier section), you still need to <code>git clone</code> again at this point |
| 268 | (to checkout the latest <code><tag></code>), because you must keep your |
| 269 | go1.4 repository distinct. |
| 270 | |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 271 | <h2 id="head">(Optional) Switch to the master branch</h2> |
| 272 | |
| 273 | <p>If you intend to modify the go source code, and |
| 274 | <a href="/doc/contribute.html">contribute your changes</a> |
| 275 | to the project, then move your repository |
| 276 | off the release branch, and onto the master (development) branch. |
| 277 | Otherwise, skip this step.</p> |
| 278 | |
| 279 | <pre> |
| 280 | $ git checkout master |
| 281 | </pre> |
| 282 | |
| 283 | <h2 id="install">Install Go</h2> |
| 284 | |
| 285 | <p> |
| 286 | To build the Go distribution, run |
| 287 | </p> |
| 288 | |
| 289 | <pre> |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 290 | $ cd src |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 291 | $ ./all.bash |
| 292 | </pre> |
| 293 | |
| 294 | <p> |
| 295 | (To build under Windows use <code>all.bat</code>.) |
| 296 | </p> |
| 297 | |
| 298 | <p> |
| 299 | If all goes well, it will finish by printing output like: |
| 300 | </p> |
| 301 | |
| 302 | <pre> |
| 303 | ALL TESTS PASSED |
| 304 | |
| 305 | --- |
| 306 | Installed Go for linux/amd64 in /home/you/go. |
| 307 | Installed commands in /home/you/go/bin. |
| 308 | *** You need to add /home/you/go/bin to your $PATH. *** |
| 309 | </pre> |
| 310 | |
| 311 | <p> |
| 312 | where the details on the last few lines reflect the operating system, |
| 313 | architecture, and root directory used during the install. |
| 314 | </p> |
| 315 | |
| 316 | <div class="detail"> |
| 317 | <p> |
| 318 | For more information about ways to control the build, see the discussion of |
| 319 | <a href="#environment">environment variables</a> below. |
| 320 | <code>all.bash</code> (or <code>all.bat</code>) runs important tests for Go, |
| 321 | which can take more time than simply building Go. If you do not want to run |
| 322 | the test suite use <code>make.bash</code> (or <code>make.bat</code>) |
| 323 | instead. |
| 324 | </p> |
| 325 | </div> |
| 326 | |
| 327 | |
| 328 | <h2 id="testing">Testing your installation</h2> |
| 329 | |
| 330 | <p> |
| 331 | Check that Go is installed correctly by building a simple program. |
| 332 | </p> |
| 333 | |
| 334 | <p> |
| 335 | Create a file named <code>hello.go</code> and put the following program in it: |
| 336 | </p> |
| 337 | |
| 338 | <pre> |
| 339 | package main |
| 340 | |
| 341 | import "fmt" |
| 342 | |
| 343 | func main() { |
Dan Willemsen | f3f2eb6 | 2018-08-28 11:28:58 -0700 | [diff] [blame] | 344 | fmt.Printf("hello, world\n") |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 345 | } |
| 346 | </pre> |
| 347 | |
| 348 | <p> |
| 349 | Then run it with the <code>go</code> tool: |
| 350 | </p> |
| 351 | |
| 352 | <pre> |
| 353 | $ go run hello.go |
| 354 | hello, world |
| 355 | </pre> |
| 356 | |
| 357 | <p> |
| 358 | If you see the "hello, world" message then Go is installed correctly. |
| 359 | </p> |
| 360 | |
| 361 | <h2 id="gopath">Set up your work environment</h2> |
| 362 | |
| 363 | <p> |
| 364 | You're almost done. |
| 365 | You just need to do a little more setup. |
| 366 | </p> |
| 367 | |
| 368 | <p> |
| 369 | <a href="/doc/code.html" class="download" id="start"> |
| 370 | <span class="big">How to Write Go Code</span> |
| 371 | <span class="desc">Learn how to set up and use the Go tools</span> |
| 372 | </a> |
| 373 | </p> |
| 374 | |
| 375 | <p> |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 376 | The <a href="/doc/code.html">How to Write Go Code</a> document |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 377 | provides <b>essential setup instructions</b> for using the Go tools. |
| 378 | </p> |
| 379 | |
| 380 | |
| 381 | <h2 id="tools">Install additional tools</h2> |
| 382 | |
| 383 | <p> |
| 384 | The source code for several Go tools (including <a href="/cmd/godoc/">godoc</a>) |
| 385 | is kept in <a href="https://golang.org/x/tools">the go.tools repository</a>. |
Colin Cross | 1371fe4 | 2019-03-19 21:08:48 -0700 | [diff] [blame] | 386 | To install one of the tools (<code>godoc</code> in this case): |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 387 | </p> |
| 388 | |
| 389 | <pre> |
| 390 | $ go get golang.org/x/tools/cmd/godoc |
| 391 | </pre> |
| 392 | |
| 393 | <p> |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 394 | To install these tools, the <code>go</code> <code>get</code> command requires |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 395 | that <a href="#git">Git</a> be installed locally. |
| 396 | </p> |
| 397 | |
| 398 | <p> |
| 399 | You must also have a workspace (<code>GOPATH</code>) set up; |
| 400 | see <a href="/doc/code.html">How to Write Go Code</a> for the details. |
| 401 | </p> |
| 402 | |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 403 | <h2 id="community">Community resources</h2> |
| 404 | |
| 405 | <p> |
| 406 | The usual community resources such as |
Dan Willemsen | f3f2eb6 | 2018-08-28 11:28:58 -0700 | [diff] [blame] | 407 | <code>#go-nuts</code> on the <a href="https://freenode.net/">Freenode</a> IRC server |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 408 | and the |
| 409 | <a href="//groups.google.com/group/golang-nuts">Go Nuts</a> |
| 410 | mailing list have active developers that can help you with problems |
| 411 | with your installation or your development work. |
| 412 | For those who wish to keep up to date, |
| 413 | there is another mailing list, <a href="//groups.google.com/group/golang-checkins">golang-checkins</a>, |
| 414 | that receives a message summarizing each checkin to the Go repository. |
| 415 | </p> |
| 416 | |
| 417 | <p> |
| 418 | Bugs can be reported using the <a href="//golang.org/issue/new">Go issue tracker</a>. |
| 419 | </p> |
| 420 | |
| 421 | |
| 422 | <h2 id="releases">Keeping up with releases</h2> |
| 423 | |
| 424 | <p> |
| 425 | New releases are announced on the |
| 426 | <a href="//groups.google.com/group/golang-announce">golang-announce</a> |
| 427 | mailing list. |
| 428 | Each announcement mentions the latest release tag, for instance, |
Dan Willemsen | cc0b9f5 | 2017-08-25 11:20:05 -0700 | [diff] [blame] | 429 | <code class="versionTag">go1.9</code>. |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 430 | </p> |
| 431 | |
| 432 | <p> |
| 433 | To update an existing tree to the latest release, you can run: |
| 434 | </p> |
| 435 | |
| 436 | <pre> |
| 437 | $ cd go/src |
| 438 | $ git fetch |
Dan Willemsen | 0c15709 | 2016-07-08 13:57:52 -0700 | [diff] [blame] | 439 | $ git checkout <span class="versionTag"><i><tag></i></psan> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 440 | $ ./all.bash |
| 441 | </pre> |
| 442 | |
Dan Willemsen | 0c15709 | 2016-07-08 13:57:52 -0700 | [diff] [blame] | 443 | <p class="whereTag"> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 444 | Where <code><tag></code> is the version string of the release. |
Dan Willemsen | 0c15709 | 2016-07-08 13:57:52 -0700 | [diff] [blame] | 445 | </p> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 446 | |
| 447 | |
| 448 | <h2 id="environment">Optional environment variables</h2> |
| 449 | |
| 450 | <p> |
| 451 | The Go compilation environment can be customized by environment variables. |
| 452 | <i>None is required by the build</i>, but you may wish to set some |
| 453 | to override the defaults. |
| 454 | </p> |
| 455 | |
| 456 | <ul> |
| 457 | <li><code>$GOROOT</code> |
| 458 | <p> |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 459 | The root of the Go tree, often <code>$HOME/go1.X</code>. |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 460 | Its value is built into the tree when it is compiled, and |
| 461 | defaults to the parent of the directory where <code>all.bash</code> was run. |
| 462 | There is no need to set this unless you want to switch between multiple |
| 463 | local copies of the repository. |
| 464 | </p> |
Dan Willemsen | e1b3b18 | 2018-02-27 19:36:27 -0800 | [diff] [blame] | 465 | </li> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 466 | |
| 467 | <li><code>$GOROOT_FINAL</code> |
| 468 | <p> |
| 469 | The value assumed by installed binaries and scripts when |
| 470 | <code>$GOROOT</code> is not set explicitly. |
| 471 | It defaults to the value of <code>$GOROOT</code>. |
| 472 | If you want to build the Go tree in one location |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 473 | but move it elsewhere after the build, set |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 474 | <code>$GOROOT_FINAL</code> to the eventual location. |
| 475 | </p> |
Dan Willemsen | e1b3b18 | 2018-02-27 19:36:27 -0800 | [diff] [blame] | 476 | </li> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 477 | |
Colin Cross | efed634 | 2019-09-07 08:34:44 -0700 | [diff] [blame^] | 478 | <li id="gopath"><code>$GOPATH</code> |
| 479 | <p> |
| 480 | The directory where Go projects outside the Go distribution are typically |
| 481 | checked out. For example, <code>golang.org/x/tools</code> might be checked out |
| 482 | to <code>$GOPATH/src/golang.org/x/tools</code>. Executables outside the |
| 483 | Go distribution are installed in <code>$GOPATH/bin</code> (or |
| 484 | <code>$GOBIN</code>, if set). Modules are downloaded and cached in |
| 485 | <code>$GOPATH/pkg/mod</code>. |
| 486 | </p> |
| 487 | |
| 488 | <p>The default location of <code>$GOPATH</code> is <code>$HOME/go</code>, |
| 489 | and it's not usually necessary to set <code>GOPATH</code> explicitly. However, |
| 490 | if you have checked out the Go distribution to <code>$HOME/go</code>, |
| 491 | you must set <code>GOPATH</code> to another location to avoid conflicts. |
| 492 | </p> |
| 493 | </li> |
| 494 | |
| 495 | <li><code>$GOBIN</code> |
| 496 | <p> |
| 497 | The directory where executables outside the Go distribution are installed |
| 498 | using the <a href="/cmd/go">go command</a>. For example, |
| 499 | <code>go get golang.org/x/tools/cmd/godoc</code> downloads, builds, and |
| 500 | installs <code>$GOBIN/godoc</code>. By default, <code>$GOBIN</code> is |
| 501 | <code>$GOPATH/bin</code> (or <code>$HOME/go/bin</code> if <code>GOPATH</code> |
| 502 | is not set). After installing, you will want to add this directory to |
| 503 | your <code>$PATH</code> so you can use installed tools. |
| 504 | </p> |
| 505 | |
| 506 | <p> |
| 507 | Note that the Go distribution's executables are installed in |
| 508 | <code>$GOROOT/bin</code> (for executables invoked by people) or |
| 509 | <code>$GOTOOLDIR</code> (for executables invoked by the go command; |
| 510 | defaults to <code>$GOROOT/pkg/$GOOS_GOARCH</code>) instead of |
| 511 | <code>$GOBIN</code>. |
| 512 | </p> |
| 513 | </li> |
| 514 | |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 515 | <li><code>$GOOS</code> and <code>$GOARCH</code> |
| 516 | <p> |
| 517 | The name of the target operating system and compilation architecture. |
| 518 | These default to the values of <code>$GOHOSTOS</code> and |
| 519 | <code>$GOHOSTARCH</code> respectively (described below). |
Dan Willemsen | e1b3b18 | 2018-02-27 19:36:27 -0800 | [diff] [blame] | 520 | </li> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 521 | |
| 522 | <p> |
| 523 | Choices for <code>$GOOS</code> are |
Colin Cross | efed634 | 2019-09-07 08:34:44 -0700 | [diff] [blame^] | 524 | <code>android</code>, <code>darwin</code> (macOS 10.11 and above and iOS), |
| 525 | <code>dragonfly</code>, <code>freebsd</code>, <code>illumos</code>, <code>js</code>, |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 526 | <code>linux</code>, <code>netbsd</code>, <code>openbsd</code>, |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 527 | <code>plan9</code>, <code>solaris</code> and <code>windows</code>. |
Colin Cross | efed634 | 2019-09-07 08:34:44 -0700 | [diff] [blame^] | 528 | </p> |
| 529 | |
| 530 | <p> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 531 | Choices for <code>$GOARCH</code> are |
| 532 | <code>amd64</code> (64-bit x86, the most mature port), |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 533 | <code>386</code> (32-bit x86), <code>arm</code> (32-bit ARM), <code>arm64</code> (64-bit ARM), |
Dan Willemsen | 0c15709 | 2016-07-08 13:57:52 -0700 | [diff] [blame] | 534 | <code>ppc64le</code> (PowerPC 64-bit, little-endian), <code>ppc64</code> (PowerPC 64-bit, big-endian), |
Dan Willemsen | e1b3b18 | 2018-02-27 19:36:27 -0800 | [diff] [blame] | 535 | <code>mips64le</code> (MIPS 64-bit, little-endian), <code>mips64</code> (MIPS 64-bit, big-endian), |
Colin Cross | efed634 | 2019-09-07 08:34:44 -0700 | [diff] [blame^] | 536 | <code>mipsle</code> (MIPS 32-bit, little-endian), <code>mips</code> (MIPS 32-bit, big-endian), |
| 537 | <code>s390x</code> (IBM System z 64-bit, big-endian), and |
| 538 | <code>wasm</code> (WebAssembly 32-bit). |
| 539 | </p> |
| 540 | |
| 541 | <p> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 542 | The valid combinations of <code>$GOOS</code> and <code>$GOARCH</code> are: |
| 543 | <table cellpadding="0"> |
| 544 | <tr> |
| 545 | <th width="50"></th><th align="left" width="100"><code>$GOOS</code></th> <th align="left" width="100"><code>$GOARCH</code></th> |
| 546 | </tr> |
| 547 | <tr> |
Colin Cross | efed634 | 2019-09-07 08:34:44 -0700 | [diff] [blame^] | 548 | <td></td><td><code>aix</code></td> <td><code>ppc64</code></td> |
| 549 | </tr> |
| 550 | <tr> |
| 551 | <td></td><td><code>android</code></td> <td><code>386</code></td> |
| 552 | </tr> |
| 553 | <tr> |
| 554 | <td></td><td><code>android</code></td> <td><code>amd64</code></td> |
| 555 | </tr> |
| 556 | <tr> |
Dan Willemsen | 0c15709 | 2016-07-08 13:57:52 -0700 | [diff] [blame] | 557 | <td></td><td><code>android</code></td> <td><code>arm</code></td> |
| 558 | </tr> |
| 559 | <tr> |
Colin Cross | efed634 | 2019-09-07 08:34:44 -0700 | [diff] [blame^] | 560 | <td></td><td><code>android</code></td> <td><code>arm64</code></td> |
| 561 | </tr> |
| 562 | <tr> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 563 | <td></td><td><code>darwin</code></td> <td><code>386</code></td> |
| 564 | </tr> |
| 565 | <tr> |
| 566 | <td></td><td><code>darwin</code></td> <td><code>amd64</code></td> |
| 567 | </tr> |
| 568 | <tr> |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 569 | <td></td><td><code>darwin</code></td> <td><code>arm</code></td> |
| 570 | </tr> |
| 571 | <tr> |
| 572 | <td></td><td><code>darwin</code></td> <td><code>arm64</code></td> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 573 | </tr> |
| 574 | <tr> |
| 575 | <td></td><td><code>dragonfly</code></td> <td><code>amd64</code></td> |
| 576 | </tr> |
| 577 | <tr> |
| 578 | <td></td><td><code>freebsd</code></td> <td><code>386</code></td> |
| 579 | </tr> |
| 580 | <tr> |
| 581 | <td></td><td><code>freebsd</code></td> <td><code>amd64</code></td> |
| 582 | </tr> |
| 583 | <tr> |
| 584 | <td></td><td><code>freebsd</code></td> <td><code>arm</code></td> |
| 585 | </tr> |
| 586 | <tr> |
Colin Cross | efed634 | 2019-09-07 08:34:44 -0700 | [diff] [blame^] | 587 | <td></td><td><code>illumos</code></td> <td><code>amd64</code></td> |
| 588 | </tr> |
| 589 | <tr> |
| 590 | <td></td><td><code>js</code></td> <td><code>wasm</code></td> |
| 591 | </tr> |
| 592 | <tr> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 593 | <td></td><td><code>linux</code></td> <td><code>386</code></td> |
| 594 | </tr> |
| 595 | <tr> |
| 596 | <td></td><td><code>linux</code></td> <td><code>amd64</code></td> |
| 597 | </tr> |
| 598 | <tr> |
| 599 | <td></td><td><code>linux</code></td> <td><code>arm</code></td> |
| 600 | </tr> |
| 601 | <tr> |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 602 | <td></td><td><code>linux</code></td> <td><code>arm64</code></td> |
| 603 | </tr> |
| 604 | <tr> |
| 605 | <td></td><td><code>linux</code></td> <td><code>ppc64</code></td> |
| 606 | </tr> |
| 607 | <tr> |
| 608 | <td></td><td><code>linux</code></td> <td><code>ppc64le</code></td> |
| 609 | </tr> |
| 610 | <tr> |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 611 | <td></td><td><code>linux</code></td> <td><code>mips</code></td> |
| 612 | </tr> |
| 613 | <tr> |
| 614 | <td></td><td><code>linux</code></td> <td><code>mipsle</code></td> |
| 615 | </tr> |
| 616 | <tr> |
Dan Willemsen | 0c15709 | 2016-07-08 13:57:52 -0700 | [diff] [blame] | 617 | <td></td><td><code>linux</code></td> <td><code>mips64</code></td> |
| 618 | </tr> |
| 619 | <tr> |
| 620 | <td></td><td><code>linux</code></td> <td><code>mips64le</code></td> |
| 621 | </tr> |
| 622 | <tr> |
Dan Willemsen | e1b3b18 | 2018-02-27 19:36:27 -0800 | [diff] [blame] | 623 | <td></td><td><code>linux</code></td> <td><code>s390x</code></td> |
| 624 | </tr> |
| 625 | <tr> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 626 | <td></td><td><code>netbsd</code></td> <td><code>386</code></td> |
| 627 | </tr> |
| 628 | <tr> |
| 629 | <td></td><td><code>netbsd</code></td> <td><code>amd64</code></td> |
| 630 | </tr> |
| 631 | <tr> |
| 632 | <td></td><td><code>netbsd</code></td> <td><code>arm</code></td> |
| 633 | </tr> |
| 634 | <tr> |
| 635 | <td></td><td><code>openbsd</code></td> <td><code>386</code></td> |
| 636 | </tr> |
| 637 | <tr> |
| 638 | <td></td><td><code>openbsd</code></td> <td><code>amd64</code></td> |
| 639 | </tr> |
| 640 | <tr> |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 641 | <td></td><td><code>openbsd</code></td> <td><code>arm</code></td> |
| 642 | </tr> |
| 643 | <tr> |
Colin Cross | efed634 | 2019-09-07 08:34:44 -0700 | [diff] [blame^] | 644 | <td></td><td><code>openbsd</code></td> <td><code>arm64</code></td> |
| 645 | </tr> |
| 646 | <tr> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 647 | <td></td><td><code>plan9</code></td> <td><code>386</code></td> |
| 648 | </tr> |
| 649 | <tr> |
| 650 | <td></td><td><code>plan9</code></td> <td><code>amd64</code></td> |
| 651 | </tr> |
| 652 | <tr> |
Colin Cross | efed634 | 2019-09-07 08:34:44 -0700 | [diff] [blame^] | 653 | <td></td><td><code>plan9</code></td> <td><code>arm</code></td> |
| 654 | </tr> |
| 655 | <tr> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 656 | <td></td><td><code>solaris</code></td> <td><code>amd64</code></td> |
| 657 | </tr> |
| 658 | <tr> |
| 659 | <td></td><td><code>windows</code></td> <td><code>386</code></td> |
| 660 | </tr> |
| 661 | <tr> |
| 662 | <td></td><td><code>windows</code></td> <td><code>amd64</code></td> |
| 663 | </tr> |
| 664 | </table> |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 665 | <br> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 666 | |
| 667 | <li><code>$GOHOSTOS</code> and <code>$GOHOSTARCH</code> |
| 668 | <p> |
| 669 | The name of the host operating system and compilation architecture. |
| 670 | These default to the local system's operating system and |
| 671 | architecture. |
| 672 | </p> |
Dan Willemsen | e1b3b18 | 2018-02-27 19:36:27 -0800 | [diff] [blame] | 673 | </li> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 674 | |
| 675 | <p> |
| 676 | Valid choices are the same as for <code>$GOOS</code> and |
| 677 | <code>$GOARCH</code>, listed above. |
| 678 | The specified values must be compatible with the local system. |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 679 | For example, you should not set <code>$GOHOSTARCH</code> to |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 680 | <code>arm</code> on an x86 system. |
| 681 | </p> |
| 682 | |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 683 | <li><code>$GO386</code> (for <code>386</code> only, default is auto-detected |
| 684 | if built on either <code>386</code> or <code>amd64</code>, <code>387</code> otherwise) |
| 685 | <p> |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 686 | This controls the code generated by gc to use either the 387 floating-point unit |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 687 | (set to <code>387</code>) or SSE2 instructions (set to <code>sse2</code>) for |
| 688 | floating point computations. |
| 689 | </p> |
| 690 | <ul> |
Dan Willemsen | e1b3b18 | 2018-02-27 19:36:27 -0800 | [diff] [blame] | 691 | <li><code>GO386=387</code>: use x87 for floating point operations; should support all x86 chips (Pentium MMX or later).</li> |
| 692 | <li><code>GO386=sse2</code>: use SSE2 for floating point operations; has better performance than 387, but only available on Pentium 4/Opteron/Athlon 64 or later.</li> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 693 | </ul> |
Dan Willemsen | e1b3b18 | 2018-02-27 19:36:27 -0800 | [diff] [blame] | 694 | </li> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 695 | |
| 696 | <li><code>$GOARM</code> (for <code>arm</code> only; default is auto-detected if building |
| 697 | on the target processor, 6 if not) |
| 698 | <p> |
| 699 | This sets the ARM floating point co-processor architecture version the run-time |
| 700 | should target. If you are compiling on the target system, its value will be auto-detected. |
| 701 | </p> |
| 702 | <ul> |
Dan Willemsen | e1b3b18 | 2018-02-27 19:36:27 -0800 | [diff] [blame] | 703 | <li><code>GOARM=5</code>: use software floating point; when CPU doesn't have VFP co-processor</li> |
| 704 | <li><code>GOARM=6</code>: use VFPv1 only; default if cross compiling; usually ARM11 or better cores (VFPv2 or better is also supported)</li> |
| 705 | <li><code>GOARM=7</code>: use VFPv3; usually Cortex-A cores</li> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 706 | </ul> |
| 707 | <p> |
| 708 | If in doubt, leave this variable unset, and adjust it if required |
| 709 | when you first run the Go executable. |
| 710 | The <a href="//golang.org/wiki/GoArm">GoARM</a> page |
| 711 | on the <a href="//golang.org/wiki">Go community wiki</a> |
| 712 | contains further details regarding Go's ARM support. |
| 713 | </p> |
Dan Willemsen | e1b3b18 | 2018-02-27 19:36:27 -0800 | [diff] [blame] | 714 | </li> |
| 715 | |
Colin Cross | 1371fe4 | 2019-03-19 21:08:48 -0700 | [diff] [blame] | 716 | <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 Willemsen | e1b3b18 | 2018-02-27 19:36:27 -0800 | [diff] [blame] | 717 | <p> |
Colin Cross | 1371fe4 | 2019-03-19 21:08:48 -0700 | [diff] [blame] | 718 | 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 Willemsen | e1b3b18 | 2018-02-27 19:36:27 -0800 | [diff] [blame] | 719 | </p> |
Dan Willemsen | e1b3b18 | 2018-02-27 19:36:27 -0800 | [diff] [blame] | 720 | </li> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 721 | |
Colin Cross | efed634 | 2019-09-07 08:34:44 -0700 | [diff] [blame^] | 722 | <li><code>$GOPPC64</code> (for <code>ppc64</code> and <code>ppc64le</code> only) |
| 723 | <p> |
| 724 | This variable sets the processor level (i.e. Instruction Set Architecture version) |
| 725 | for which the compiler will target. The default is <code>power8</code>. |
| 726 | </p> |
| 727 | <ul> |
| 728 | <li><code>GOPPC64=power8</code>: generate ISA v2.07 instructions</li> |
| 729 | <li><code>GOPPC64=power9</code>: generate ISA v3.00 instructions</li> |
| 730 | </ul> |
| 731 | </li> |
| 732 | |
| 733 | |
| 734 | <li><code>$GOWASM</code> (for <code>wasm</code> only) |
| 735 | <p> |
| 736 | This variable is a comma separated list of <a href="https://github.com/WebAssembly/proposals">experimental WebAssembly features</a> that the compiled WebAssembly binary is allowed to use. |
| 737 | The default is to use no experimental features. |
| 738 | </p> |
| 739 | <ul> |
| 740 | <li><code>GOWASM=satconv</code>: generate <a href="https://github.com/WebAssembly/nontrapping-float-to-int-conversions/blob/master/proposals/nontrapping-float-to-int-conversion/Overview.md">saturating (non-trapping) float-to-int conversions</a></li> |
| 741 | <li><code>GOWASM=signext</code>: generate <a href="https://github.com/WebAssembly/sign-extension-ops/blob/master/proposals/sign-extension-ops/Overview.md">sign-extension operators</a></li> |
| 742 | </ul> |
| 743 | </li> |
| 744 | |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 745 | </ul> |
| 746 | |
| 747 | <p> |
| 748 | Note that <code>$GOARCH</code> and <code>$GOOS</code> identify the |
| 749 | <em>target</em> environment, not the environment you are running on. |
| 750 | In effect, you are always cross-compiling. |
| 751 | By architecture, we mean the kind of binaries |
| 752 | that the target environment can run: |
| 753 | an x86-64 system running a 32-bit-only operating system |
| 754 | must set <code>GOARCH</code> to <code>386</code>, |
| 755 | not <code>amd64</code>. |
| 756 | </p> |
| 757 | |
| 758 | <p> |
| 759 | If you choose to override the defaults, |
| 760 | set these variables in your shell profile (<code>$HOME/.bashrc</code>, |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 761 | <code>$HOME/.profile</code>, or equivalent). The settings might look |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 762 | something like this: |
| 763 | </p> |
| 764 | |
| 765 | <pre> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 766 | export GOARCH=amd64 |
| 767 | export GOOS=linux |
| 768 | </pre> |
| 769 | |
| 770 | <p> |
| 771 | although, to reiterate, none of these variables needs to be set to build, |
| 772 | install, and develop the Go tree. |
| 773 | </p> |