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