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.) |
| 150 | </p> |
| 151 | |
| 152 | <p> |
| 153 | To cross-compile a bootstrap tool chain from source, which is |
| 154 | necessary on systems Go 1.4 did not target (for |
| 155 | example, <code>linux/ppc64le</code>), install Go on a different system |
| 156 | and run <a href="/src/bootstrap.bash">bootstrap.bash</a>. |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 157 | </p> |
| 158 | |
| 159 | <p> |
| 160 | When run as (for example) |
| 161 | </p> |
| 162 | |
| 163 | <pre> |
| 164 | $ GOOS=linux GOARCH=ppc64 ./bootstrap.bash |
| 165 | </pre> |
| 166 | |
| 167 | <p> |
| 168 | <code>bootstrap.bash</code> cross-compiles a toolchain for that <code>GOOS/GOARCH</code> |
| 169 | combination, leaving the resulting tree in <code>../../go-${GOOS}-${GOARCH}-bootstrap</code>. |
| 170 | That tree can be copied to a machine of the given target type |
| 171 | and used as <code>GOROOT_BOOTSTRAP</code> to bootstrap a local build. |
| 172 | </p> |
| 173 | |
| 174 | <p> |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 175 | To use gccgo as the bootstrap toolchain, you need to arrange |
| 176 | for <code>$GOROOT_BOOTSTRAP/bin/go</code> to be the go tool that comes |
| 177 | as part of gccgo 5. For example on Ubuntu Vivid: |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 178 | </p> |
| 179 | |
| 180 | <pre> |
| 181 | $ sudo apt-get install gccgo-5 |
| 182 | $ sudo update-alternatives --set go /usr/bin/go-5 |
| 183 | $ GOROOT_BOOTSTRAP=/usr ./make.bash |
| 184 | </pre> |
| 185 | |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 186 | <h2 id="git">Install Git, if needed</h2> |
| 187 | |
| 188 | <p> |
| 189 | To perform the next step you must have Git installed. (Check that you |
| 190 | have a <code>git</code> command before proceeding.) |
| 191 | </p> |
| 192 | |
| 193 | <p> |
| 194 | If you do not have a working Git installation, |
| 195 | follow the instructions on the |
| 196 | <a href="http://git-scm.com/downloads">Git downloads</a> page. |
| 197 | </p> |
| 198 | |
Dan Willemsen | 0c15709 | 2016-07-08 13:57:52 -0700 | [diff] [blame] | 199 | <h2 id="ccompiler">(Optional) Install a C compiler</h2> |
| 200 | |
| 201 | <p> |
| 202 | To build a Go installation |
| 203 | with <code><a href="/cmd/cgo">cgo</a></code> support, which permits Go |
| 204 | programs to import C libraries, a C compiler such as <code>gcc</code> |
| 205 | or <code>clang</code> must be installed first. Do this using whatever |
| 206 | installation method is standard on the system. |
| 207 | </p> |
| 208 | |
| 209 | <p> |
| 210 | To build without <code>cgo</code>, set the environment variable |
| 211 | <code>CGO_ENABLED=0</code> before running <code>all.bash</code> or |
| 212 | <code>make.bash</code>. |
| 213 | </p> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 214 | |
| 215 | <h2 id="fetch">Fetch the repository</h2> |
| 216 | |
| 217 | <p>Go will install to a directory named <code>go</code>. |
| 218 | Change to the directory that will be its parent |
| 219 | and make sure the <code>go</code> directory does not exist. |
Dan Willemsen | 0c15709 | 2016-07-08 13:57:52 -0700 | [diff] [blame] | 220 | Then clone the repository and check out the latest release tag |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 221 | (<code class="versionTag">go1.7.4</code>, for example):</p> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 222 | |
| 223 | <pre> |
| 224 | $ git clone https://go.googlesource.com/go |
| 225 | $ cd go |
Dan Willemsen | 0c15709 | 2016-07-08 13:57:52 -0700 | [diff] [blame] | 226 | $ git checkout <span class="versionTag"><i><tag></i></span> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 227 | </pre> |
| 228 | |
Dan Willemsen | 0c15709 | 2016-07-08 13:57:52 -0700 | [diff] [blame] | 229 | <p class="whereTag"> |
| 230 | Where <code><tag></code> is the version string of the release. |
| 231 | </p> |
| 232 | |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 233 | <h2 id="head">(Optional) Switch to the master branch</h2> |
| 234 | |
| 235 | <p>If you intend to modify the go source code, and |
| 236 | <a href="/doc/contribute.html">contribute your changes</a> |
| 237 | to the project, then move your repository |
| 238 | off the release branch, and onto the master (development) branch. |
| 239 | Otherwise, skip this step.</p> |
| 240 | |
| 241 | <pre> |
| 242 | $ git checkout master |
| 243 | </pre> |
| 244 | |
| 245 | <h2 id="install">Install Go</h2> |
| 246 | |
| 247 | <p> |
| 248 | To build the Go distribution, run |
| 249 | </p> |
| 250 | |
| 251 | <pre> |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 252 | $ cd src |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 253 | $ ./all.bash |
| 254 | </pre> |
| 255 | |
| 256 | <p> |
| 257 | (To build under Windows use <code>all.bat</code>.) |
| 258 | </p> |
| 259 | |
| 260 | <p> |
| 261 | If all goes well, it will finish by printing output like: |
| 262 | </p> |
| 263 | |
| 264 | <pre> |
| 265 | ALL TESTS PASSED |
| 266 | |
| 267 | --- |
| 268 | Installed Go for linux/amd64 in /home/you/go. |
| 269 | Installed commands in /home/you/go/bin. |
| 270 | *** You need to add /home/you/go/bin to your $PATH. *** |
| 271 | </pre> |
| 272 | |
| 273 | <p> |
| 274 | where the details on the last few lines reflect the operating system, |
| 275 | architecture, and root directory used during the install. |
| 276 | </p> |
| 277 | |
| 278 | <div class="detail"> |
| 279 | <p> |
| 280 | For more information about ways to control the build, see the discussion of |
| 281 | <a href="#environment">environment variables</a> below. |
| 282 | <code>all.bash</code> (or <code>all.bat</code>) runs important tests for Go, |
| 283 | which can take more time than simply building Go. If you do not want to run |
| 284 | the test suite use <code>make.bash</code> (or <code>make.bat</code>) |
| 285 | instead. |
| 286 | </p> |
| 287 | </div> |
| 288 | |
| 289 | |
| 290 | <h2 id="testing">Testing your installation</h2> |
| 291 | |
| 292 | <p> |
| 293 | Check that Go is installed correctly by building a simple program. |
| 294 | </p> |
| 295 | |
| 296 | <p> |
| 297 | Create a file named <code>hello.go</code> and put the following program in it: |
| 298 | </p> |
| 299 | |
| 300 | <pre> |
| 301 | package main |
| 302 | |
| 303 | import "fmt" |
| 304 | |
| 305 | func main() { |
| 306 | fmt.Printf("hello, world\n") |
| 307 | } |
| 308 | </pre> |
| 309 | |
| 310 | <p> |
| 311 | Then run it with the <code>go</code> tool: |
| 312 | </p> |
| 313 | |
| 314 | <pre> |
| 315 | $ go run hello.go |
| 316 | hello, world |
| 317 | </pre> |
| 318 | |
| 319 | <p> |
| 320 | If you see the "hello, world" message then Go is installed correctly. |
| 321 | </p> |
| 322 | |
| 323 | <h2 id="gopath">Set up your work environment</h2> |
| 324 | |
| 325 | <p> |
| 326 | You're almost done. |
| 327 | You just need to do a little more setup. |
| 328 | </p> |
| 329 | |
| 330 | <p> |
| 331 | <a href="/doc/code.html" class="download" id="start"> |
| 332 | <span class="big">How to Write Go Code</span> |
| 333 | <span class="desc">Learn how to set up and use the Go tools</span> |
| 334 | </a> |
| 335 | </p> |
| 336 | |
| 337 | <p> |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 338 | 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] | 339 | provides <b>essential setup instructions</b> for using the Go tools. |
| 340 | </p> |
| 341 | |
| 342 | |
| 343 | <h2 id="tools">Install additional tools</h2> |
| 344 | |
| 345 | <p> |
| 346 | The source code for several Go tools (including <a href="/cmd/godoc/">godoc</a>) |
| 347 | is kept in <a href="https://golang.org/x/tools">the go.tools repository</a>. |
| 348 | To install all of them, run the <code>go</code> <code>get</code> command: |
| 349 | </p> |
| 350 | |
| 351 | <pre> |
| 352 | $ go get golang.org/x/tools/cmd/... |
| 353 | </pre> |
| 354 | |
| 355 | <p> |
| 356 | Or if you just want to install a specific command (<code>godoc</code> in this case): |
| 357 | </p> |
| 358 | |
| 359 | <pre> |
| 360 | $ go get golang.org/x/tools/cmd/godoc |
| 361 | </pre> |
| 362 | |
| 363 | <p> |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 364 | 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] | 365 | that <a href="#git">Git</a> be installed locally. |
| 366 | </p> |
| 367 | |
| 368 | <p> |
| 369 | You must also have a workspace (<code>GOPATH</code>) set up; |
| 370 | see <a href="/doc/code.html">How to Write Go Code</a> for the details. |
| 371 | </p> |
| 372 | |
| 373 | <p> |
| 374 | <b>Note</b>: The <code>go</code> command will install the <code>godoc</code> |
| 375 | binary to <code>$GOROOT/bin</code> (or <code>$GOBIN</code>) and the |
| 376 | <code>cover</code> and <code>vet</code> binaries to |
| 377 | <code>$GOROOT/pkg/tool/$GOOS_$GOARCH</code>. |
| 378 | You can access the latter commands with |
| 379 | "<code>go</code> <code>tool</code> <code>cover</code>" and |
| 380 | "<code>go</code> <code>tool</code> <code>vet</code>". |
| 381 | </p> |
| 382 | |
| 383 | <h2 id="community">Community resources</h2> |
| 384 | |
| 385 | <p> |
| 386 | The usual community resources such as |
| 387 | <code>#go-nuts</code> on the <a href="http://freenode.net/">Freenode</a> IRC server |
| 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 | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 409 | <code class="versionTag">go1.7.4</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> |
| 445 | |
| 446 | <li><code>$GOROOT_FINAL</code> |
| 447 | <p> |
| 448 | The value assumed by installed binaries and scripts when |
| 449 | <code>$GOROOT</code> is not set explicitly. |
| 450 | It defaults to the value of <code>$GOROOT</code>. |
| 451 | If you want to build the Go tree in one location |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 452 | but move it elsewhere after the build, set |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 453 | <code>$GOROOT_FINAL</code> to the eventual location. |
| 454 | </p> |
| 455 | |
| 456 | <li><code>$GOOS</code> and <code>$GOARCH</code> |
| 457 | <p> |
| 458 | The name of the target operating system and compilation architecture. |
| 459 | These default to the values of <code>$GOHOSTOS</code> and |
| 460 | <code>$GOHOSTARCH</code> respectively (described below). |
| 461 | |
| 462 | <p> |
| 463 | Choices for <code>$GOOS</code> are |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 464 | <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] | 465 | <code>linux</code>, <code>netbsd</code>, <code>openbsd</code>, |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 466 | <code>plan9</code>, <code>solaris</code> and <code>windows</code>. |
| 467 | Choices for <code>$GOARCH</code> are |
| 468 | <code>amd64</code> (64-bit x86, the most mature port), |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 469 | <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] | 470 | <code>ppc64le</code> (PowerPC 64-bit, little-endian), <code>ppc64</code> (PowerPC 64-bit, big-endian), |
| 471 | <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] | 472 | <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] | 473 | The valid combinations of <code>$GOOS</code> and <code>$GOARCH</code> are: |
| 474 | <table cellpadding="0"> |
| 475 | <tr> |
| 476 | <th width="50"></th><th align="left" width="100"><code>$GOOS</code></th> <th align="left" width="100"><code>$GOARCH</code></th> |
| 477 | </tr> |
| 478 | <tr> |
Dan Willemsen | 0c15709 | 2016-07-08 13:57:52 -0700 | [diff] [blame] | 479 | <td></td><td><code>android</code></td> <td><code>arm</code></td> |
| 480 | </tr> |
| 481 | <tr> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 482 | <td></td><td><code>darwin</code></td> <td><code>386</code></td> |
| 483 | </tr> |
| 484 | <tr> |
| 485 | <td></td><td><code>darwin</code></td> <td><code>amd64</code></td> |
| 486 | </tr> |
| 487 | <tr> |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 488 | <td></td><td><code>darwin</code></td> <td><code>arm</code></td> |
| 489 | </tr> |
| 490 | <tr> |
| 491 | <td></td><td><code>darwin</code></td> <td><code>arm64</code></td> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 492 | </tr> |
| 493 | <tr> |
| 494 | <td></td><td><code>dragonfly</code></td> <td><code>amd64</code></td> |
| 495 | </tr> |
| 496 | <tr> |
| 497 | <td></td><td><code>freebsd</code></td> <td><code>386</code></td> |
| 498 | </tr> |
| 499 | <tr> |
| 500 | <td></td><td><code>freebsd</code></td> <td><code>amd64</code></td> |
| 501 | </tr> |
| 502 | <tr> |
| 503 | <td></td><td><code>freebsd</code></td> <td><code>arm</code></td> |
| 504 | </tr> |
| 505 | <tr> |
| 506 | <td></td><td><code>linux</code></td> <td><code>386</code></td> |
| 507 | </tr> |
| 508 | <tr> |
| 509 | <td></td><td><code>linux</code></td> <td><code>amd64</code></td> |
| 510 | </tr> |
| 511 | <tr> |
| 512 | <td></td><td><code>linux</code></td> <td><code>arm</code></td> |
| 513 | </tr> |
| 514 | <tr> |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 515 | <td></td><td><code>linux</code></td> <td><code>arm64</code></td> |
| 516 | </tr> |
| 517 | <tr> |
| 518 | <td></td><td><code>linux</code></td> <td><code>ppc64</code></td> |
| 519 | </tr> |
| 520 | <tr> |
| 521 | <td></td><td><code>linux</code></td> <td><code>ppc64le</code></td> |
| 522 | </tr> |
| 523 | <tr> |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 524 | <td></td><td><code>linux</code></td> <td><code>mips</code></td> |
| 525 | </tr> |
| 526 | <tr> |
| 527 | <td></td><td><code>linux</code></td> <td><code>mipsle</code></td> |
| 528 | </tr> |
| 529 | <tr> |
Dan Willemsen | 0c15709 | 2016-07-08 13:57:52 -0700 | [diff] [blame] | 530 | <td></td><td><code>linux</code></td> <td><code>mips64</code></td> |
| 531 | </tr> |
| 532 | <tr> |
| 533 | <td></td><td><code>linux</code></td> <td><code>mips64le</code></td> |
| 534 | </tr> |
| 535 | <tr> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 536 | <td></td><td><code>netbsd</code></td> <td><code>386</code></td> |
| 537 | </tr> |
| 538 | <tr> |
| 539 | <td></td><td><code>netbsd</code></td> <td><code>amd64</code></td> |
| 540 | </tr> |
| 541 | <tr> |
| 542 | <td></td><td><code>netbsd</code></td> <td><code>arm</code></td> |
| 543 | </tr> |
| 544 | <tr> |
| 545 | <td></td><td><code>openbsd</code></td> <td><code>386</code></td> |
| 546 | </tr> |
| 547 | <tr> |
| 548 | <td></td><td><code>openbsd</code></td> <td><code>amd64</code></td> |
| 549 | </tr> |
| 550 | <tr> |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 551 | <td></td><td><code>openbsd</code></td> <td><code>arm</code></td> |
| 552 | </tr> |
| 553 | <tr> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 554 | <td></td><td><code>plan9</code></td> <td><code>386</code></td> |
| 555 | </tr> |
| 556 | <tr> |
| 557 | <td></td><td><code>plan9</code></td> <td><code>amd64</code></td> |
| 558 | </tr> |
| 559 | <tr> |
| 560 | <td></td><td><code>solaris</code></td> <td><code>amd64</code></td> |
| 561 | </tr> |
| 562 | <tr> |
| 563 | <td></td><td><code>windows</code></td> <td><code>386</code></td> |
| 564 | </tr> |
| 565 | <tr> |
| 566 | <td></td><td><code>windows</code></td> <td><code>amd64</code></td> |
| 567 | </tr> |
| 568 | </table> |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 569 | <br> |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 570 | |
| 571 | <li><code>$GOHOSTOS</code> and <code>$GOHOSTARCH</code> |
| 572 | <p> |
| 573 | The name of the host operating system and compilation architecture. |
| 574 | These default to the local system's operating system and |
| 575 | architecture. |
| 576 | </p> |
| 577 | |
| 578 | <p> |
| 579 | Valid choices are the same as for <code>$GOOS</code> and |
| 580 | <code>$GOARCH</code>, listed above. |
| 581 | The specified values must be compatible with the local system. |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 582 | For example, you should not set <code>$GOHOSTARCH</code> to |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 583 | <code>arm</code> on an x86 system. |
| 584 | </p> |
| 585 | |
| 586 | <li><code>$GOBIN</code> |
| 587 | <p> |
| 588 | The location where Go binaries will be installed. |
| 589 | The default is <code>$GOROOT/bin</code>. |
| 590 | After installing, you will want to arrange to add this |
| 591 | directory to your <code>$PATH</code>, so you can use the tools. |
| 592 | If <code>$GOBIN</code> is set, the <a href="/cmd/go">go command</a> |
| 593 | installs all commands there. |
| 594 | </p> |
| 595 | |
| 596 | <li><code>$GO386</code> (for <code>386</code> only, default is auto-detected |
| 597 | if built on either <code>386</code> or <code>amd64</code>, <code>387</code> otherwise) |
| 598 | <p> |
Dan Willemsen | 6ff2325 | 2015-09-15 13:49:18 -0700 | [diff] [blame] | 599 | 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] | 600 | (set to <code>387</code>) or SSE2 instructions (set to <code>sse2</code>) for |
| 601 | floating point computations. |
| 602 | </p> |
| 603 | <ul> |
| 604 | <li><code>GO386=387</code>: use x87 for floating point operations; should support all x86 chips (Pentium MMX or later). |
| 605 | <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. |
| 606 | </ul> |
| 607 | |
| 608 | <li><code>$GOARM</code> (for <code>arm</code> only; default is auto-detected if building |
| 609 | on the target processor, 6 if not) |
| 610 | <p> |
| 611 | This sets the ARM floating point co-processor architecture version the run-time |
| 612 | should target. If you are compiling on the target system, its value will be auto-detected. |
| 613 | </p> |
| 614 | <ul> |
| 615 | <li><code>GOARM=5</code>: use software floating point; when CPU doesn't have VFP co-processor |
| 616 | <li><code>GOARM=6</code>: use VFPv1 only; default if cross compiling; usually ARM11 or better cores (VFPv2 or better is also supported) |
| 617 | <li><code>GOARM=7</code>: use VFPv3; usually Cortex-A cores |
| 618 | </ul> |
| 619 | <p> |
| 620 | If in doubt, leave this variable unset, and adjust it if required |
| 621 | when you first run the Go executable. |
| 622 | The <a href="//golang.org/wiki/GoArm">GoARM</a> page |
| 623 | on the <a href="//golang.org/wiki">Go community wiki</a> |
| 624 | contains further details regarding Go's ARM support. |
| 625 | </p> |
| 626 | |
| 627 | </ul> |
| 628 | |
| 629 | <p> |
| 630 | Note that <code>$GOARCH</code> and <code>$GOOS</code> identify the |
| 631 | <em>target</em> environment, not the environment you are running on. |
| 632 | In effect, you are always cross-compiling. |
| 633 | By architecture, we mean the kind of binaries |
| 634 | that the target environment can run: |
| 635 | an x86-64 system running a 32-bit-only operating system |
| 636 | must set <code>GOARCH</code> to <code>386</code>, |
| 637 | not <code>amd64</code>. |
| 638 | </p> |
| 639 | |
| 640 | <p> |
| 641 | If you choose to override the defaults, |
| 642 | set these variables in your shell profile (<code>$HOME/.bashrc</code>, |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 643 | <code>$HOME/.profile</code>, or equivalent). The settings might look |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 644 | something like this: |
| 645 | </p> |
| 646 | |
| 647 | <pre> |
Dan Willemsen | bbdf664 | 2017-01-13 22:57:23 -0800 | [diff] [blame] | 648 | export GOROOT=$HOME/go1.X |
Colin Cross | 7bb052a | 2015-02-03 12:59:37 -0800 | [diff] [blame] | 649 | export GOARCH=amd64 |
| 650 | export GOOS=linux |
| 651 | </pre> |
| 652 | |
| 653 | <p> |
| 654 | although, to reiterate, none of these variables needs to be set to build, |
| 655 | install, and develop the Go tree. |
| 656 | </p> |