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> |
| 27 | There are two official Go compiler tool chains. |
| 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> |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 36 | The Go compilers support eight 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> |
| 90 | </dl> |
| 91 | |
| 92 | <p> |
| 93 | Except for things like low-level operating system interface code, the run-time |
| 94 | support is the same in all ports and includes a mark-and-sweep garbage |
| 95 | collector, efficient array and string slicing, and support for efficient |
| 96 | goroutines, such as stacks that grow and shrink on demand. |
| 97 | </p> |
| 98 | |
| 99 | <p> |
| 100 | The compilers can target the DragonFly BSD, FreeBSD, Linux, NetBSD, OpenBSD, |
| 101 | OS X (Darwin), Plan 9, Solaris and Windows operating systems. |
| 102 | The full set of supported combinations is listed in the discussion of |
| 103 | <a href="#environment">environment variables</a> below. |
| 104 | </p> |
| 105 | |
Dan Willemsen | 0c15709 | 2016-07-08 13:57:52 -0700 | [diff] [blame] | 106 | <p> |
| 107 | See the main installation page for the <a href="/doc/install#requirements">overall system requirements</a>. |
| 108 | The following additional constraints apply to systems that can be built only from source: |
| 109 | </p> |
| 110 | |
| 111 | <ul> |
| 112 | <li>For Linux on PowerPC 64-bit, the minimum supported kernel version is 2.6.37, meaning that |
| 113 | Go does not support CentOS 6 on these systems. |
| 114 | </li> |
| 115 | </ul> |
| 116 | |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 117 | </div> |
| 118 | |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 119 | <h2 id="go14">Install Go compiler binaries</h2> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 120 | |
| 121 | <p> |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 122 | The Go tool chain is written in Go. To build it, you need a Go compiler installed. |
| 123 | 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] | 124 | chain in <code>$GOROOT_BOOTSTRAP</code>. |
| 125 | If unset, the default value of <code>GOROOT_BOOTSTRAP</code> |
| 126 | is <code>$HOME/go1.4</code>. |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 127 | </p> |
| 128 | |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 129 | <p> |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 130 | There are many options for the bootstrap tool chain. |
| 131 | After obtaining one, set <code>GOROOT_BOOTSTRAP</code> to the |
| 132 | directory containing the unpacked tree. |
| 133 | For example, <code>$GOROOT_BOOTSTRAP/bin/go</code> should be |
| 134 | the <code>go</code> command binary for the bootstrap tool chain. |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 135 | </p> |
| 136 | |
| 137 | <p> |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 138 | To use a binary release as a bootstrap tool chain, see |
| 139 | <a href="/dl/">the downloads page</a> or use any other |
| 140 | packaged Go distribution. |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 141 | </p> |
| 142 | |
| 143 | <p> |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 144 | To build a bootstrap tool chain from source, use |
| 145 | either the git branch <code>release-branch.go1.4</code> or |
| 146 | <a href="https://storage.googleapis.com/golang/go1.4-bootstrap-20161024.tar.gz">go1.4-bootstrap-20161024.tar.gz</a>, |
| 147 | which contains the Go 1.4 source code plus accumulated fixes |
| 148 | to keep the tools running on newer operating systems. |
| 149 | (Go 1.4 was the last distribution in which the tool chain was written in C.) |
Dan Willemsen | a727cd0 | 2017-02-21 17:11:40 -0800 | [diff] [blame^] | 150 | After unpacking the Go 1.4 source, <code>cd</code> to |
| 151 | the <code>src</code> subdirectory and run <code>make.bash</code> (or, |
| 152 | on Windows, <code>make.bat</code>). |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 153 | </p> |
| 154 | |
| 155 | <p> |
| 156 | To cross-compile a bootstrap tool chain from source, which is |
| 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 | |
| 177 | <p> |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 178 | To use gccgo as the bootstrap toolchain, you need to arrange |
| 179 | for <code>$GOROOT_BOOTSTRAP/bin/go</code> to be the go tool that comes |
| 180 | as part of gccgo 5. For example on Ubuntu Vivid: |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 181 | </p> |
| 182 | |
| 183 | <pre> |
| 184 | $ sudo apt-get install gccgo-5 |
| 185 | $ sudo update-alternatives --set go /usr/bin/go-5 |
| 186 | $ GOROOT_BOOTSTRAP=/usr ./make.bash |
| 187 | </pre> |
| 188 | |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 189 | <h2 id="git">Install Git, if needed</h2> |
| 190 | |
| 191 | <p> |
| 192 | To perform the next step you must have Git installed. (Check that you |
| 193 | have a <code>git</code> command before proceeding.) |
| 194 | </p> |
| 195 | |
| 196 | <p> |
| 197 | If you do not have a working Git installation, |
| 198 | follow the instructions on the |
| 199 | <a href="http://git-scm.com/downloads">Git downloads</a> page. |
| 200 | </p> |
| 201 | |
Dan Willemsen | 0c15709 | 2016-07-08 13:57:52 -0700 | [diff] [blame] | 202 | <h2 id="ccompiler">(Optional) Install a C compiler</h2> |
| 203 | |
| 204 | <p> |
| 205 | To build a Go installation |
| 206 | with <code><a href="/cmd/cgo">cgo</a></code> support, which permits Go |
| 207 | programs to import C libraries, a C compiler such as <code>gcc</code> |
| 208 | or <code>clang</code> must be installed first. Do this using whatever |
| 209 | installation method is standard on the system. |
| 210 | </p> |
| 211 | |
| 212 | <p> |
| 213 | To build without <code>cgo</code>, set the environment variable |
| 214 | <code>CGO_ENABLED=0</code> before running <code>all.bash</code> or |
| 215 | <code>make.bash</code>. |
| 216 | </p> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 217 | |
| 218 | <h2 id="fetch">Fetch the repository</h2> |
| 219 | |
| 220 | <p>Go will install to a directory named <code>go</code>. |
| 221 | Change to the directory that will be its parent |
| 222 | and make sure the <code>go</code> directory does not exist. |
Dan Willemsen | 0c15709 | 2016-07-08 13:57:52 -0700 | [diff] [blame] | 223 | Then clone the repository and check out the latest release tag |
Dan Willemsen | a727cd0 | 2017-02-21 17:11:40 -0800 | [diff] [blame^] | 224 | (<code class="versionTag">go1.8</code>, for example):</p> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 225 | |
| 226 | <pre> |
| 227 | $ git clone https://go.googlesource.com/go |
| 228 | $ cd go |
Dan Willemsen | 0c15709 | 2016-07-08 13:57:52 -0700 | [diff] [blame] | 229 | $ git checkout <span class="versionTag"><i><tag></i></span> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 230 | </pre> |
| 231 | |
Dan Willemsen | 0c15709 | 2016-07-08 13:57:52 -0700 | [diff] [blame] | 232 | <p class="whereTag"> |
| 233 | Where <code><tag></code> is the version string of the release. |
| 234 | </p> |
| 235 | |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 236 | <h2 id="head">(Optional) Switch to the master branch</h2> |
| 237 | |
| 238 | <p>If you intend to modify the go source code, and |
| 239 | <a href="/doc/contribute.html">contribute your changes</a> |
| 240 | to the project, then move your repository |
| 241 | off the release branch, and onto the master (development) branch. |
| 242 | Otherwise, skip this step.</p> |
| 243 | |
| 244 | <pre> |
| 245 | $ git checkout master |
| 246 | </pre> |
| 247 | |
| 248 | <h2 id="install">Install Go</h2> |
| 249 | |
| 250 | <p> |
| 251 | To build the Go distribution, run |
| 252 | </p> |
| 253 | |
| 254 | <pre> |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 255 | $ cd src |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 256 | $ ./all.bash |
| 257 | </pre> |
| 258 | |
| 259 | <p> |
| 260 | (To build under Windows use <code>all.bat</code>.) |
| 261 | </p> |
| 262 | |
| 263 | <p> |
| 264 | If all goes well, it will finish by printing output like: |
| 265 | </p> |
| 266 | |
| 267 | <pre> |
| 268 | ALL TESTS PASSED |
| 269 | |
| 270 | --- |
| 271 | Installed Go for linux/amd64 in /home/you/go. |
| 272 | Installed commands in /home/you/go/bin. |
| 273 | *** You need to add /home/you/go/bin to your $PATH. *** |
| 274 | </pre> |
| 275 | |
| 276 | <p> |
| 277 | where the details on the last few lines reflect the operating system, |
| 278 | architecture, and root directory used during the install. |
| 279 | </p> |
| 280 | |
| 281 | <div class="detail"> |
| 282 | <p> |
| 283 | For more information about ways to control the build, see the discussion of |
| 284 | <a href="#environment">environment variables</a> below. |
| 285 | <code>all.bash</code> (or <code>all.bat</code>) runs important tests for Go, |
| 286 | which can take more time than simply building Go. If you do not want to run |
| 287 | the test suite use <code>make.bash</code> (or <code>make.bat</code>) |
| 288 | instead. |
| 289 | </p> |
| 290 | </div> |
| 291 | |
| 292 | |
| 293 | <h2 id="testing">Testing your installation</h2> |
| 294 | |
| 295 | <p> |
| 296 | Check that Go is installed correctly by building a simple program. |
| 297 | </p> |
| 298 | |
| 299 | <p> |
| 300 | Create a file named <code>hello.go</code> and put the following program in it: |
| 301 | </p> |
| 302 | |
| 303 | <pre> |
| 304 | package main |
| 305 | |
| 306 | import "fmt" |
| 307 | |
| 308 | func main() { |
| 309 | fmt.Printf("hello, world\n") |
| 310 | } |
| 311 | </pre> |
| 312 | |
| 313 | <p> |
| 314 | Then run it with the <code>go</code> tool: |
| 315 | </p> |
| 316 | |
| 317 | <pre> |
| 318 | $ go run hello.go |
| 319 | hello, world |
| 320 | </pre> |
| 321 | |
| 322 | <p> |
| 323 | If you see the "hello, world" message then Go is installed correctly. |
| 324 | </p> |
| 325 | |
| 326 | <h2 id="gopath">Set up your work environment</h2> |
| 327 | |
| 328 | <p> |
| 329 | You're almost done. |
| 330 | You just need to do a little more setup. |
| 331 | </p> |
| 332 | |
| 333 | <p> |
| 334 | <a href="/doc/code.html" class="download" id="start"> |
| 335 | <span class="big">How to Write Go Code</span> |
| 336 | <span class="desc">Learn how to set up and use the Go tools</span> |
| 337 | </a> |
| 338 | </p> |
| 339 | |
| 340 | <p> |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 341 | 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] | 342 | provides <b>essential setup instructions</b> for using the Go tools. |
| 343 | </p> |
| 344 | |
| 345 | |
| 346 | <h2 id="tools">Install additional tools</h2> |
| 347 | |
| 348 | <p> |
| 349 | The source code for several Go tools (including <a href="/cmd/godoc/">godoc</a>) |
| 350 | is kept in <a href="https://golang.org/x/tools">the go.tools repository</a>. |
| 351 | To install all of them, run the <code>go</code> <code>get</code> command: |
| 352 | </p> |
| 353 | |
| 354 | <pre> |
| 355 | $ go get golang.org/x/tools/cmd/... |
| 356 | </pre> |
| 357 | |
| 358 | <p> |
| 359 | Or if you just want to install a specific command (<code>godoc</code> in this case): |
| 360 | </p> |
| 361 | |
| 362 | <pre> |
| 363 | $ go get golang.org/x/tools/cmd/godoc |
| 364 | </pre> |
| 365 | |
| 366 | <p> |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 367 | 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] | 368 | that <a href="#git">Git</a> be installed locally. |
| 369 | </p> |
| 370 | |
| 371 | <p> |
| 372 | You must also have a workspace (<code>GOPATH</code>) set up; |
| 373 | see <a href="/doc/code.html">How to Write Go Code</a> for the details. |
| 374 | </p> |
| 375 | |
| 376 | <p> |
| 377 | <b>Note</b>: The <code>go</code> command will install the <code>godoc</code> |
| 378 | binary to <code>$GOROOT/bin</code> (or <code>$GOBIN</code>) and the |
| 379 | <code>cover</code> and <code>vet</code> binaries to |
| 380 | <code>$GOROOT/pkg/tool/$GOOS_$GOARCH</code>. |
| 381 | You can access the latter commands with |
| 382 | "<code>go</code> <code>tool</code> <code>cover</code>" and |
| 383 | "<code>go</code> <code>tool</code> <code>vet</code>". |
| 384 | </p> |
| 385 | |
| 386 | <h2 id="community">Community resources</h2> |
| 387 | |
| 388 | <p> |
| 389 | The usual community resources such as |
| 390 | <code>#go-nuts</code> on the <a href="http://freenode.net/">Freenode</a> IRC server |
| 391 | and the |
| 392 | <a href="//groups.google.com/group/golang-nuts">Go Nuts</a> |
| 393 | mailing list have active developers that can help you with problems |
| 394 | with your installation or your development work. |
| 395 | For those who wish to keep up to date, |
| 396 | there is another mailing list, <a href="//groups.google.com/group/golang-checkins">golang-checkins</a>, |
| 397 | that receives a message summarizing each checkin to the Go repository. |
| 398 | </p> |
| 399 | |
| 400 | <p> |
| 401 | Bugs can be reported using the <a href="//golang.org/issue/new">Go issue tracker</a>. |
| 402 | </p> |
| 403 | |
| 404 | |
| 405 | <h2 id="releases">Keeping up with releases</h2> |
| 406 | |
| 407 | <p> |
| 408 | New releases are announced on the |
| 409 | <a href="//groups.google.com/group/golang-announce">golang-announce</a> |
| 410 | mailing list. |
| 411 | Each announcement mentions the latest release tag, for instance, |
Dan Willemsen | a727cd0 | 2017-02-21 17:11:40 -0800 | [diff] [blame^] | 412 | <code class="versionTag">go1.8</code>. |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 413 | </p> |
| 414 | |
| 415 | <p> |
| 416 | To update an existing tree to the latest release, you can run: |
| 417 | </p> |
| 418 | |
| 419 | <pre> |
| 420 | $ cd go/src |
| 421 | $ git fetch |
Dan Willemsen | 0c15709 | 2016-07-08 13:57:52 -0700 | [diff] [blame] | 422 | $ git checkout <span class="versionTag"><i><tag></i></psan> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 423 | $ ./all.bash |
| 424 | </pre> |
| 425 | |
Dan Willemsen | 0c15709 | 2016-07-08 13:57:52 -0700 | [diff] [blame] | 426 | <p class="whereTag"> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 427 | Where <code><tag></code> is the version string of the release. |
Dan Willemsen | 0c15709 | 2016-07-08 13:57:52 -0700 | [diff] [blame] | 428 | </p> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 429 | |
| 430 | |
| 431 | <h2 id="environment">Optional environment variables</h2> |
| 432 | |
| 433 | <p> |
| 434 | The Go compilation environment can be customized by environment variables. |
| 435 | <i>None is required by the build</i>, but you may wish to set some |
| 436 | to override the defaults. |
| 437 | </p> |
| 438 | |
| 439 | <ul> |
| 440 | <li><code>$GOROOT</code> |
| 441 | <p> |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 442 | The root of the Go tree, often <code>$HOME/go1.X</code>. |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 443 | Its value is built into the tree when it is compiled, and |
| 444 | defaults to the parent of the directory where <code>all.bash</code> was run. |
| 445 | There is no need to set this unless you want to switch between multiple |
| 446 | local copies of the repository. |
| 447 | </p> |
| 448 | |
| 449 | <li><code>$GOROOT_FINAL</code> |
| 450 | <p> |
| 451 | The value assumed by installed binaries and scripts when |
| 452 | <code>$GOROOT</code> is not set explicitly. |
| 453 | It defaults to the value of <code>$GOROOT</code>. |
| 454 | If you want to build the Go tree in one location |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 455 | but move it elsewhere after the build, set |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 456 | <code>$GOROOT_FINAL</code> to the eventual location. |
| 457 | </p> |
| 458 | |
| 459 | <li><code>$GOOS</code> and <code>$GOARCH</code> |
| 460 | <p> |
| 461 | The name of the target operating system and compilation architecture. |
| 462 | These default to the values of <code>$GOHOSTOS</code> and |
| 463 | <code>$GOHOSTARCH</code> respectively (described below). |
| 464 | |
| 465 | <p> |
| 466 | Choices for <code>$GOOS</code> are |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 467 | <code>darwin</code> (Mac OS X 10.8 and above and iOS), <code>dragonfly</code>, <code>freebsd</code>, |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 468 | <code>linux</code>, <code>netbsd</code>, <code>openbsd</code>, |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 469 | <code>plan9</code>, <code>solaris</code> and <code>windows</code>. |
| 470 | Choices for <code>$GOARCH</code> are |
| 471 | <code>amd64</code> (64-bit x86, the most mature port), |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 472 | <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] | 473 | <code>ppc64le</code> (PowerPC 64-bit, little-endian), <code>ppc64</code> (PowerPC 64-bit, big-endian), |
| 474 | <code>mips64le</code> (MIPS 64-bit, little-endian), and <code>mips64</code> (MIPS 64-bit, big-endian). |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 475 | <code>mipsle</code> (MIPS 32-bit, little-endian), and <code>mips</code> (MIPS 32-bit, big-endian). |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 476 | The valid combinations of <code>$GOOS</code> and <code>$GOARCH</code> are: |
| 477 | <table cellpadding="0"> |
| 478 | <tr> |
| 479 | <th width="50"></th><th align="left" width="100"><code>$GOOS</code></th> <th align="left" width="100"><code>$GOARCH</code></th> |
| 480 | </tr> |
| 481 | <tr> |
Dan Willemsen | 0c15709 | 2016-07-08 13:57:52 -0700 | [diff] [blame] | 482 | <td></td><td><code>android</code></td> <td><code>arm</code></td> |
| 483 | </tr> |
| 484 | <tr> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 485 | <td></td><td><code>darwin</code></td> <td><code>386</code></td> |
| 486 | </tr> |
| 487 | <tr> |
| 488 | <td></td><td><code>darwin</code></td> <td><code>amd64</code></td> |
| 489 | </tr> |
| 490 | <tr> |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 491 | <td></td><td><code>darwin</code></td> <td><code>arm</code></td> |
| 492 | </tr> |
| 493 | <tr> |
| 494 | <td></td><td><code>darwin</code></td> <td><code>arm64</code></td> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 495 | </tr> |
| 496 | <tr> |
| 497 | <td></td><td><code>dragonfly</code></td> <td><code>amd64</code></td> |
| 498 | </tr> |
| 499 | <tr> |
| 500 | <td></td><td><code>freebsd</code></td> <td><code>386</code></td> |
| 501 | </tr> |
| 502 | <tr> |
| 503 | <td></td><td><code>freebsd</code></td> <td><code>amd64</code></td> |
| 504 | </tr> |
| 505 | <tr> |
| 506 | <td></td><td><code>freebsd</code></td> <td><code>arm</code></td> |
| 507 | </tr> |
| 508 | <tr> |
| 509 | <td></td><td><code>linux</code></td> <td><code>386</code></td> |
| 510 | </tr> |
| 511 | <tr> |
| 512 | <td></td><td><code>linux</code></td> <td><code>amd64</code></td> |
| 513 | </tr> |
| 514 | <tr> |
| 515 | <td></td><td><code>linux</code></td> <td><code>arm</code></td> |
| 516 | </tr> |
| 517 | <tr> |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 518 | <td></td><td><code>linux</code></td> <td><code>arm64</code></td> |
| 519 | </tr> |
| 520 | <tr> |
| 521 | <td></td><td><code>linux</code></td> <td><code>ppc64</code></td> |
| 522 | </tr> |
| 523 | <tr> |
| 524 | <td></td><td><code>linux</code></td> <td><code>ppc64le</code></td> |
| 525 | </tr> |
| 526 | <tr> |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 527 | <td></td><td><code>linux</code></td> <td><code>mips</code></td> |
| 528 | </tr> |
| 529 | <tr> |
| 530 | <td></td><td><code>linux</code></td> <td><code>mipsle</code></td> |
| 531 | </tr> |
| 532 | <tr> |
Dan Willemsen | 0c15709 | 2016-07-08 13:57:52 -0700 | [diff] [blame] | 533 | <td></td><td><code>linux</code></td> <td><code>mips64</code></td> |
| 534 | </tr> |
| 535 | <tr> |
| 536 | <td></td><td><code>linux</code></td> <td><code>mips64le</code></td> |
| 537 | </tr> |
| 538 | <tr> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 539 | <td></td><td><code>netbsd</code></td> <td><code>386</code></td> |
| 540 | </tr> |
| 541 | <tr> |
| 542 | <td></td><td><code>netbsd</code></td> <td><code>amd64</code></td> |
| 543 | </tr> |
| 544 | <tr> |
| 545 | <td></td><td><code>netbsd</code></td> <td><code>arm</code></td> |
| 546 | </tr> |
| 547 | <tr> |
| 548 | <td></td><td><code>openbsd</code></td> <td><code>386</code></td> |
| 549 | </tr> |
| 550 | <tr> |
| 551 | <td></td><td><code>openbsd</code></td> <td><code>amd64</code></td> |
| 552 | </tr> |
| 553 | <tr> |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 554 | <td></td><td><code>openbsd</code></td> <td><code>arm</code></td> |
| 555 | </tr> |
| 556 | <tr> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 557 | <td></td><td><code>plan9</code></td> <td><code>386</code></td> |
| 558 | </tr> |
| 559 | <tr> |
| 560 | <td></td><td><code>plan9</code></td> <td><code>amd64</code></td> |
| 561 | </tr> |
| 562 | <tr> |
| 563 | <td></td><td><code>solaris</code></td> <td><code>amd64</code></td> |
| 564 | </tr> |
| 565 | <tr> |
| 566 | <td></td><td><code>windows</code></td> <td><code>386</code></td> |
| 567 | </tr> |
| 568 | <tr> |
| 569 | <td></td><td><code>windows</code></td> <td><code>amd64</code></td> |
| 570 | </tr> |
| 571 | </table> |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 572 | <br> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 573 | |
| 574 | <li><code>$GOHOSTOS</code> and <code>$GOHOSTARCH</code> |
| 575 | <p> |
| 576 | The name of the host operating system and compilation architecture. |
| 577 | These default to the local system's operating system and |
| 578 | architecture. |
| 579 | </p> |
| 580 | |
| 581 | <p> |
| 582 | Valid choices are the same as for <code>$GOOS</code> and |
| 583 | <code>$GOARCH</code>, listed above. |
| 584 | The specified values must be compatible with the local system. |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 585 | For example, you should not set <code>$GOHOSTARCH</code> to |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 586 | <code>arm</code> on an x86 system. |
| 587 | </p> |
| 588 | |
| 589 | <li><code>$GOBIN</code> |
| 590 | <p> |
| 591 | The location where Go binaries will be installed. |
| 592 | The default is <code>$GOROOT/bin</code>. |
| 593 | After installing, you will want to arrange to add this |
| 594 | directory to your <code>$PATH</code>, so you can use the tools. |
| 595 | If <code>$GOBIN</code> is set, the <a href="/cmd/go">go command</a> |
| 596 | installs all commands there. |
| 597 | </p> |
| 598 | |
| 599 | <li><code>$GO386</code> (for <code>386</code> only, default is auto-detected |
| 600 | if built on either <code>386</code> or <code>amd64</code>, <code>387</code> otherwise) |
| 601 | <p> |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 602 | 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] | 603 | (set to <code>387</code>) or SSE2 instructions (set to <code>sse2</code>) for |
| 604 | floating point computations. |
| 605 | </p> |
| 606 | <ul> |
| 607 | <li><code>GO386=387</code>: use x87 for floating point operations; should support all x86 chips (Pentium MMX or later). |
| 608 | <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. |
| 609 | </ul> |
| 610 | |
| 611 | <li><code>$GOARM</code> (for <code>arm</code> only; default is auto-detected if building |
| 612 | on the target processor, 6 if not) |
| 613 | <p> |
| 614 | This sets the ARM floating point co-processor architecture version the run-time |
| 615 | should target. If you are compiling on the target system, its value will be auto-detected. |
| 616 | </p> |
| 617 | <ul> |
| 618 | <li><code>GOARM=5</code>: use software floating point; when CPU doesn't have VFP co-processor |
| 619 | <li><code>GOARM=6</code>: use VFPv1 only; default if cross compiling; usually ARM11 or better cores (VFPv2 or better is also supported) |
| 620 | <li><code>GOARM=7</code>: use VFPv3; usually Cortex-A cores |
| 621 | </ul> |
| 622 | <p> |
| 623 | If in doubt, leave this variable unset, and adjust it if required |
| 624 | when you first run the Go executable. |
| 625 | The <a href="//golang.org/wiki/GoArm">GoARM</a> page |
| 626 | on the <a href="//golang.org/wiki">Go community wiki</a> |
| 627 | contains further details regarding Go's ARM support. |
| 628 | </p> |
| 629 | |
| 630 | </ul> |
| 631 | |
| 632 | <p> |
| 633 | Note that <code>$GOARCH</code> and <code>$GOOS</code> identify the |
| 634 | <em>target</em> environment, not the environment you are running on. |
| 635 | In effect, you are always cross-compiling. |
| 636 | By architecture, we mean the kind of binaries |
| 637 | that the target environment can run: |
| 638 | an x86-64 system running a 32-bit-only operating system |
| 639 | must set <code>GOARCH</code> to <code>386</code>, |
| 640 | not <code>amd64</code>. |
| 641 | </p> |
| 642 | |
| 643 | <p> |
| 644 | If you choose to override the defaults, |
| 645 | set these variables in your shell profile (<code>$HOME/.bashrc</code>, |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 646 | <code>$HOME/.profile</code>, or equivalent). The settings might look |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 647 | something like this: |
| 648 | </p> |
| 649 | |
| 650 | <pre> |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 651 | export GOROOT=$HOME/go1.X |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 652 | export GOARCH=amd64 |
| 653 | export GOOS=linux |
| 654 | </pre> |
| 655 | |
| 656 | <p> |
| 657 | although, to reiterate, none of these variables needs to be set to build, |
| 658 | install, and develop the Go tree. |
| 659 | </p> |