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