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