Andrew Gerrand | 6ab8d24 | 2010-09-16 14:01:02 +1000 | [diff] [blame] | 1 | <!-- Getting Started --> |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 2 | |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 3 | <h2 id="introduction">Introduction</h2> |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 4 | |
Russ Cox | 6fff7b2 | 2009-11-08 22:12:51 -0800 | [diff] [blame] | 5 | <p>Go is an open source project, distributed under a |
| 6 | <a href="/LICENSE">BSD-style license</a>. |
| 7 | This document explains how to check out the sources, |
| 8 | build them on your own machine, and run them. |
| 9 | </p> |
| 10 | |
Andrew Gerrand | 6ab8d24 | 2010-09-16 14:01:02 +1000 | [diff] [blame] | 11 | <div class="detail"> |
| 12 | |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 13 | <p> |
| 14 | There are two distinct ways to experiment with Go. |
Russ Cox | 6fff7b2 | 2009-11-08 22:12:51 -0800 | [diff] [blame] | 15 | This document focuses on the <code>gc</code> Go |
Rob Pike | 5f50a81 | 2009-11-05 15:07:42 -0800 | [diff] [blame] | 16 | compiler and tools (<code>6g</code>, <code>8g</code> etc.). |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 17 | For information on how to use <code>gccgo</code>, a more traditional |
Rob Pike | 5f50a81 | 2009-11-05 15:07:42 -0800 | [diff] [blame] | 18 | compiler using the GCC back end, see |
Ian Lance Taylor | 5b387fb | 2009-11-06 14:36:34 -0800 | [diff] [blame] | 19 | <a href="gccgo_install.html">Setting up and using gccgo</a>. |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 20 | </p> |
| 21 | |
Rob Pike | 5f50a81 | 2009-11-05 15:07:42 -0800 | [diff] [blame] | 22 | <p> |
Russ Cox | a24f814 | 2010-03-16 18:45:16 -0700 | [diff] [blame] | 23 | The Go compilers support three instruction sets. |
Rob Pike | 5f50a81 | 2009-11-05 15:07:42 -0800 | [diff] [blame] | 24 | There are important differences in the quality of the compilers for the different |
| 25 | architectures. |
| 26 | </p> |
| 27 | |
| 28 | <dl> |
| 29 | <dt> |
| 30 | <code>amd64</code> (a.k.a. <code>x86-64</code>); <code>6g,6l,6c,6a</code> |
| 31 | </dt> |
| 32 | <dd> |
Rob Pike | b2d3701 | 2009-11-06 17:31:23 -0800 | [diff] [blame] | 33 | The most mature implementation. The compiler has an effective optimizer |
Rob Pike | 5f50a81 | 2009-11-05 15:07:42 -0800 | [diff] [blame] | 34 | (registerizer) and generates good code (although <code>gccgo</code> |
| 35 | can do noticeably better sometimes). |
| 36 | </dd> |
| 37 | <dt> |
| 38 | <code>386</code> (a.k.a. <code>x86</code> or <code>x86-32</code>); <code>8g,8l,8c,8a</code> |
| 39 | </dt> |
Russ Cox | 6fff7b2 | 2009-11-08 22:12:51 -0800 | [diff] [blame] | 40 | <dd> |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 41 | Comparable to the <code>amd64</code> port. |
Rob Pike | 5f50a81 | 2009-11-05 15:07:42 -0800 | [diff] [blame] | 42 | </dd> |
| 43 | <dt> |
| 44 | <code>arm</code> (a.k.a. <code>ARM</code>); <code>5g,5l,5c,5a</code> |
| 45 | </dt> |
| 46 | <dd> |
Russ Cox | b7cb844 | 2010-09-22 15:30:42 +1000 | [diff] [blame] | 47 | Incomplete. |
Rob Pike | 80e25fc | 2011-01-19 23:07:38 -0500 | [diff] [blame] | 48 | It only supports Linux binaries, the optimizer is incomplete, |
| 49 | and floating point uses the VFP unit. |
Russ Cox | e8bde0e | 2010-10-26 08:34:40 -0700 | [diff] [blame] | 50 | However, all tests pass. |
Rob Pike | 80e25fc | 2011-01-19 23:07:38 -0500 | [diff] [blame] | 51 | Work on the optimizer is continuing. |
Russ Cox | b7cb844 | 2010-09-22 15:30:42 +1000 | [diff] [blame] | 52 | Tested against a Nexus One. |
Rob Pike | 5f50a81 | 2009-11-05 15:07:42 -0800 | [diff] [blame] | 53 | </dd> |
| 54 | </dl> |
| 55 | |
| 56 | <p> |
| 57 | Except for things like low-level operating system interface code, the runtime |
| 58 | support is the same in all ports and includes a mark-and-sweep garbage collector |
| 59 | (a fancier one is in the works), efficient array and string slicing, |
| 60 | support for segmented stacks, and a strong goroutine implementation. |
| 61 | </p> |
| 62 | |
| 63 | <p> |
Russ Cox | 0c54225 | 2010-12-15 11:49:23 -0500 | [diff] [blame] | 64 | The compilers can target the FreeBSD, Linux, |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 65 | and OS X (a.k.a. Darwin) operating systems. |
Andrew Gerrand | ab7884d | 2010-12-08 08:31:26 +1100 | [diff] [blame] | 66 | (A port to Microsoft Windows is in progress but incomplete. See the |
| 67 | <a href="http://code.google.com/p/go/wiki/WindowsPort">Windows Port</a> |
| 68 | page for details.) |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 69 | The full set of supported combinations is listed in the discussion of |
| 70 | <a href="#environment">environment variables</a> below. |
Rob Pike | 5f50a81 | 2009-11-05 15:07:42 -0800 | [diff] [blame] | 71 | </p> |
| 72 | |
Andrew Gerrand | 6ab8d24 | 2010-09-16 14:01:02 +1000 | [diff] [blame] | 73 | </div> |
| 74 | |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 75 | <h2 id="ctools">Install C tools, if needed</h2> |
Robert Griesemer | 7cd4de6 | 2010-03-10 16:31:09 -0800 | [diff] [blame] | 76 | |
Andrew Gerrand | 6ab8d24 | 2010-09-16 14:01:02 +1000 | [diff] [blame] | 77 | <p>The Go tool chain is written in C. |
| 78 | To build it, you need these programs installed: |
| 79 | <ul> |
| 80 | <li>GCC, |
| 81 | <li>the standard C libraries, |
| 82 | <li>the parser generator Bison, |
| 83 | <li><tt>make</tt>, |
| 84 | <li><tt>awk</tt>, and |
| 85 | <li>the text editor <tt>ed</tt>. |
| 86 | </ul> |
Robert Griesemer | 7cd4de6 | 2010-03-10 16:31:09 -0800 | [diff] [blame] | 87 | </p> |
| 88 | |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 89 | <p>On OS X, they can be |
| 90 | installed as part of |
| 91 | <a href="http://developer.apple.com/TOOLS/Xcode/">Xcode</a>. |
| 92 | </p> |
Robert Griesemer | 7cd4de6 | 2010-03-10 16:31:09 -0800 | [diff] [blame] | 93 | |
Andrew Gerrand | 6ab8d24 | 2010-09-16 14:01:02 +1000 | [diff] [blame] | 94 | <p>On Ubuntu/Debian, use <code>sudo apt-get install bison ed gawk gcc libc6-dev make</code>. |
| 95 | </p> |
| 96 | |
| 97 | <h2 id="mercurial">Install Mercurial, if needed</h2> |
| 98 | |
| 99 | <p> |
Robert Griesemer | 686490c | 2010-09-29 12:34:24 -0700 | [diff] [blame] | 100 | To perform the next step you must have Mercurial installed. (Check that you have an <code>hg</code> command.) This suffices to install Mercurial on most systems: |
Andrew Gerrand | 6ab8d24 | 2010-09-16 14:01:02 +1000 | [diff] [blame] | 101 | </p> |
| 102 | <pre> |
| 103 | sudo easy_install mercurial |
| 104 | </pre> |
| 105 | (On Ubuntu/Debian, you might try <code>apt-get install python-setuptools |
| 106 | python-dev build-essential</code> first. The Mercurial in your distribution's |
| 107 | package repository will most likely be old and broken.) |
| 108 | </p> |
| 109 | <p> |
| 110 | If that fails, try installing manually from the <a href="http://mercurial.selenic.com/wiki/Download">Mercurial Download</a> page.</p> |
Robert Griesemer | 7cd4de6 | 2010-03-10 16:31:09 -0800 | [diff] [blame] | 111 | </p> |
| 112 | |
Robert Griesemer | 68b40fb | 2011-02-02 15:53:32 -0800 | [diff] [blame] | 113 | <p> |
| 114 | Mercurial versions 1.7.x and up require the configuration of |
| 115 | <a href="http://mercurial.selenic.com/wiki/CACertificates">Certification Authorities</a> |
| 116 | (CAs). Error messages of the form: |
| 117 | </p> |
| 118 | <pre> |
| 119 | warning: go.googlecode.com certificate with fingerprint b1:af: ... bc not verified (check hostfingerprints or web.cacerts config setting) |
| 120 | </pre> |
| 121 | <p> |
| 122 | when using Mercurial indicate that the CAs are missing. |
| 123 | Check your Mercurial version (<code>hg --version</code>) and |
| 124 | <a href="http://mercurial.selenic.com/wiki/CACertificates#Configuration_of_HTTPS_certificate_authorities">configure the CAs</a> |
| 125 | if necessary. |
| 126 | </p> |
| 127 | |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 128 | <h2 id="fetch">Fetch the repository</h2> |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 129 | |
| 130 | <p> |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 131 | <p>Go will install to a directory named <code>go</code>. |
| 132 | Change to the directory that will be its parent |
| 133 | and make sure the <code>go</code> directory does not exist. |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 134 | Then check out the repository:</p> |
| 135 | |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 136 | <pre> |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 137 | $ hg clone -r release https://go.googlecode.com/hg/ go |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 138 | </pre> |
| 139 | |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 140 | <h2 id="install">Install Go</h2> |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 141 | |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 142 | <p> |
Devon H. O'Dell | 857d4cf | 2009-12-11 15:14:09 -0800 | [diff] [blame] | 143 | To build the Go distribution, run |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 144 | </p> |
| 145 | |
| 146 | <pre> |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 147 | $ cd go/src |
Christopher Wedgwood | 34191d9 | 2010-01-25 00:09:46 -0800 | [diff] [blame] | 148 | $ ./all.bash |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 149 | </pre> |
| 150 | |
| 151 | <p> |
Russ Cox | da392d9 | 2010-08-18 10:08:49 -0400 | [diff] [blame] | 152 | If all goes well, it will finish by printing output like: |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 153 | </p> |
| 154 | |
| 155 | <pre> |
Russ Cox | b9f9476 | 2011-02-14 09:27:02 -0500 | [diff] [blame] | 156 | ALL TESTS PASSED |
Russ Cox | da392d9 | 2010-08-18 10:08:49 -0400 | [diff] [blame] | 157 | |
| 158 | --- |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 159 | Installed Go for linux/amd64 in /home/you/go. |
| 160 | Installed commands in /home/you/go/bin. |
| 161 | *** You need to add /home/you/go/bin to your $PATH. *** |
| 162 | The compiler is 6g. |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 163 | </pre> |
| 164 | |
| 165 | <p> |
Russ Cox | da392d9 | 2010-08-18 10:08:49 -0400 | [diff] [blame] | 166 | where <var>N</var> is a number that varies from release to release |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 167 | and the details on the last few lines will reflect the operating system, |
Russ Cox | da392d9 | 2010-08-18 10:08:49 -0400 | [diff] [blame] | 168 | architecture, and root directory used during the install. |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 169 | </p> |
| 170 | |
Andrew Gerrand | 6ab8d24 | 2010-09-16 14:01:02 +1000 | [diff] [blame] | 171 | <div class="detail"> |
| 172 | |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 173 | <p>For more information about ways to control the build, |
| 174 | see the discussion of <a href="#environment">environment variables</a> below.</p> |
Andrew Gerrand | 6ab8d24 | 2010-09-16 14:01:02 +1000 | [diff] [blame] | 175 | </div> |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 176 | |
| 177 | <h2 id="writing">Writing programs</h2> |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 178 | |
| 179 | <p> |
| 180 | Given a file <code>file.go</code>, compile it using |
| 181 | </p> |
| 182 | |
| 183 | <pre> |
| 184 | $ 6g file.go |
| 185 | </pre> |
| 186 | |
| 187 | <p> |
| 188 | <code>6g</code> is the Go compiler for <code>amd64</code>; it will write the output |
| 189 | in <code>file.6</code>. The ‘<code>6</code>’ identifies |
| 190 | files for the <code>amd64</code> architecture. |
| 191 | The identifier letters for <code>386</code> and <code>arm</code> |
| 192 | are ‘<code>8</code>’ and ‘<code>5</code>’. |
| 193 | That is, if you were compiling for <code>386</code>, you would use |
| 194 | <code>8g</code> and the output would be named <code>file.8</code>. |
| 195 | </p> |
| 196 | |
| 197 | <p> |
| 198 | To link the file, use |
| 199 | </p> |
| 200 | |
| 201 | <pre> |
| 202 | $ 6l file.6 |
| 203 | </pre> |
| 204 | |
| 205 | <p> |
| 206 | and to run it |
| 207 | </p> |
| 208 | |
| 209 | <pre> |
| 210 | $ ./6.out |
| 211 | </pre> |
| 212 | |
| 213 | <p>A complete example: |
| 214 | </p> |
| 215 | |
| 216 | <pre> |
| 217 | $ cat >hello.go <<EOF |
| 218 | package main |
| 219 | |
| 220 | import "fmt" |
| 221 | |
| 222 | func main() { |
| 223 | fmt.Printf("hello, world\n") |
| 224 | } |
| 225 | EOF |
| 226 | $ 6g hello.go |
| 227 | $ 6l hello.6 |
| 228 | $ ./6.out |
| 229 | hello, world |
| 230 | $ |
| 231 | </pre> |
| 232 | |
| 233 | <p> |
| 234 | There is no need to list <code>hello.6</code>'s package dependencies |
| 235 | (in this case, package <code>fmt</code>) on the <code>6l</code> |
| 236 | command line. |
| 237 | The linker learns about them by reading <code>hello.6</code>. |
| 238 | </p> |
| 239 | |
Andrew Gerrand | 6ab8d24 | 2010-09-16 14:01:02 +1000 | [diff] [blame] | 240 | <div class="detail"> |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 241 | <p> |
| 242 | To build more complicated programs, you will probably |
Russ Cox | 6fff7b2 | 2009-11-08 22:12:51 -0800 | [diff] [blame] | 243 | want to use a |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 244 | <code>Makefile</code>. |
Rob Pike | 5f50a81 | 2009-11-05 15:07:42 -0800 | [diff] [blame] | 245 | There are examples in places like |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 246 | <code>go/src/cmd/godoc/Makefile</code> |
| 247 | and <code>go/src/pkg/*/Makefile</code>. |
Rob Pike | 5f50a81 | 2009-11-05 15:07:42 -0800 | [diff] [blame] | 248 | The |
| 249 | <a href="contribute.html">document</a> |
| 250 | about contributing to the Go project |
| 251 | gives more detail about |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 252 | the process of building and testing Go programs. |
| 253 | </p> |
Andrew Gerrand | 6ab8d24 | 2010-09-16 14:01:02 +1000 | [diff] [blame] | 254 | </div> |
| 255 | |
| 256 | <h2 id="next">What's next</h2> |
| 257 | |
| 258 | <p> |
| 259 | Start by reading the <a href="go_tutorial.html">Go Tutorial</a>. |
| 260 | </p> |
| 261 | |
| 262 | <p> |
| 263 | Build a web application by following the <a href="codelab/wiki/">Wiki |
| 264 | Codelab</a>. |
| 265 | </p> |
| 266 | |
| 267 | <p> |
| 268 | Read <a href="effective_go.html">Effective Go</a> to learn about writing |
| 269 | idiomatic Go code. |
| 270 | </p> |
| 271 | |
| 272 | <p> |
| 273 | For the full story, consult Go's extensive |
| 274 | <a href="docs.html">documentation</a>. |
| 275 | </p> |
Russ Cox | 8b04cef | 2009-11-08 23:38:30 -0800 | [diff] [blame] | 276 | |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 277 | <h2 id="releases">Keeping up with releases</h2> |
Russ Cox | 3269647 | 2009-12-15 19:16:56 -0800 | [diff] [blame] | 278 | |
| 279 | <p>New releases are announced on the <a href="http://groups.google.com/group/golang-nuts">Go Nuts</a> mailing list. |
| 280 | To update an existing tree to the latest release, you can run: |
| 281 | </p> |
| 282 | |
| 283 | <pre> |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 284 | $ cd go/src |
Russ Cox | 3269647 | 2009-12-15 19:16:56 -0800 | [diff] [blame] | 285 | $ hg pull |
| 286 | $ hg update release |
Russ Cox | 05f2636 | 2010-01-28 18:18:40 -0800 | [diff] [blame] | 287 | $ ./all.bash |
Russ Cox | 3269647 | 2009-12-15 19:16:56 -0800 | [diff] [blame] | 288 | </pre> |
| 289 | |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 290 | <h2 id="community">Community resources</h2> |
Russ Cox | 8b04cef | 2009-11-08 23:38:30 -0800 | [diff] [blame] | 291 | |
| 292 | <p> |
| 293 | For real-time help, there may be users or developers on |
| 294 | <code>#go-nuts</code> on the <a href="http://freenode.net/">Freenode</a> IRC server. |
| 295 | </p> |
| 296 | |
| 297 | <p> |
| 298 | The official mailing list for discussion of the Go language is |
| 299 | <a href="http://groups.google.com/group/golang-nuts">Go Nuts</a>. |
| 300 | </p> |
| 301 | |
| 302 | <p> |
| 303 | Bugs can be reported using the <a href="http://code.google.com/p/go/issues/list">Go issue tracker</a>. |
| 304 | </p> |
| 305 | |
| 306 | <p> |
| 307 | For those who wish to keep up with development, |
| 308 | there is another mailing list, <a href="http://groups.google.com/group/golang-checkins">golang-checkins</a>, |
| 309 | that receives a message summarizing each checkin to the Go repository. |
| 310 | </p> |
| 311 | |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 312 | <h2 id="environment">Environment variables</h2> |
Russ Cox | 8b04cef | 2009-11-08 23:38:30 -0800 | [diff] [blame] | 313 | |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 314 | <p> |
Andrew Gerrand | f89050d | 2010-12-05 12:04:15 +0900 | [diff] [blame] | 315 | The Go compilation environment can be customized by environment variables. |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 316 | None are required by the build, but you may wish to set them |
| 317 | to override the defaults. |
| 318 | </p> |
| 319 | |
| 320 | <dl> |
| 321 | <dt> |
| 322 | <code>$GOROOT</code> |
| 323 | </dt> |
| 324 | <dd> |
| 325 | The root of the Go tree, often <code>$HOME/go</code>. |
| 326 | This defaults to the parent of the directory where <code>all.bash</code> is run. |
| 327 | If you choose not to set <code>$GOROOT</code>, you must |
| 328 | run <code>gomake</code> instead of <code>make</code> or <code>gmake</code> |
| 329 | when developing Go programs using the conventional makefiles. |
| 330 | </dd> |
| 331 | |
| 332 | <dt> |
| 333 | <code>$GOROOT_FINAL</code> |
| 334 | </dt> |
| 335 | <dd> |
| 336 | The value assumed by installed binaries and scripts when |
| 337 | <code>$GOROOT</code> is not set. |
| 338 | It defaults to the value used for <code>$GOROOT</code>. |
| 339 | If you want to build the Go tree in one location |
| 340 | but move it elsewhere after the build, set |
| 341 | <code>$GOROOT_FINAL</code> to the eventual location. |
| 342 | </dd> |
| 343 | |
| 344 | <dt> |
| 345 | <code>$GOOS</code> and <code>$GOARCH</code> |
| 346 | </dt> |
| 347 | <dd> |
| 348 | The name of the target operating system and compilation architecture. |
Andrew Gerrand | f89050d | 2010-12-05 12:04:15 +0900 | [diff] [blame] | 349 | These default to the values of <code>$GOHOSTOS</code> and |
| 350 | <code>$GOHOSTARCH</code> respectively (described below). |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 351 | |
| 352 | <p> |
| 353 | Choices for <code>$GOOS</code> are <code>linux</code>, |
| 354 | <code>freebsd</code>, |
| 355 | <code>darwin</code> (Mac OS X 10.5 or 10.6), |
Peter Mundy | c17394df | 2010-12-08 20:27:45 +1100 | [diff] [blame] | 356 | and <code>windows</code> (Windows, an incomplete port). |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 357 | Choices for <code>$GOARCH</code> are <code>amd64</code> (64-bit x86, the most mature port), |
| 358 | <code>386</code> (32-bit x86), and |
| 359 | <code>arm</code> (32-bit ARM, an incomplete port). |
| 360 | The valid combinations of <code>$GOOS</code> and <code>$GOARCH</code> are: |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 361 | <table cellpadding="0"> |
| 362 | <tr> |
| 363 | <th width="50"><th align="left" width="100"><code>$GOOS</code></th> <th align="left" width="100"><code>$GOARCH</code></th> <th align="left"></th> |
| 364 | </tr> |
| 365 | <tr> |
| 366 | <td></td><td><code>darwin</code></td> <td><code>386</code></td> |
| 367 | </tr> |
| 368 | <tr> |
| 369 | <td></td><td><code>darwin</code></td> <td><code>amd64</code></td> |
| 370 | </tr> |
| 371 | <tr> |
| 372 | <td></td><td><code>freebsd</code></td> <td><code>386</code></td> |
| 373 | </tr> |
| 374 | <tr> |
| 375 | <td></td><td><code>freebsd</code></td> <td><code>amd64</code></td> |
| 376 | </tr> |
| 377 | <tr> |
| 378 | <td></td><td><code>linux</code></td> <td><code>386</code></td> |
| 379 | </tr> |
| 380 | <tr> |
| 381 | <td></td><td><code>linux</code></td> <td><code>amd64</code></td> |
| 382 | </tr> |
| 383 | <tr> |
| 384 | <td></td><td><code>linux</code></td> <td><code>arm</code></td> <td><i>incomplete</i></td> |
| 385 | </tr> |
| 386 | <tr> |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 387 | <td></td><td><code>windows</code></td> <td><code>386</code></td> <td><i>incomplete</i></td> |
| 388 | </tr> |
| 389 | </table> |
| 390 | </dd> |
| 391 | |
| 392 | <dt> |
Andrew Gerrand | f89050d | 2010-12-05 12:04:15 +0900 | [diff] [blame] | 393 | <code>$GOHOSTOS</code> and <code>$GOHOSTARCH</code> |
| 394 | </dt> |
| 395 | <dd> |
| 396 | The name of the host operating system and compilation architecture. |
| 397 | These default to the local system's operating system and |
| 398 | architecture. |
| 399 | |
| 400 | <p> |
| 401 | Valid choices are the same as for <code>$GOOS</code> and |
| 402 | <code>$GOARCH</code>, listed above. |
| 403 | The specified values must be compatible with the local system. |
| 404 | For example, you should not set <code>$GOHOSTARCH</code> to |
| 405 | <code>arm</code> on an x86 system. |
| 406 | </dd> |
| 407 | |
| 408 | <dt> |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 409 | <code>$GOBIN</code> |
| 410 | </dt> |
| 411 | <dd> |
| 412 | The location where binaries will be installed. |
| 413 | The default is <code>$GOROOT/bin</code>. |
| 414 | After installing, you will want to arrange to add this |
| 415 | directory to your <code>$PATH</code>, so you can use the tools. |
| 416 | </dd> |
| 417 | |
| 418 | <dt> |
| 419 | <code>$GOARM</code> (arm, default=6) |
| 420 | </dt> |
| 421 | <dd> |
| 422 | The ARM architecture version the runtime libraries should target. |
| 423 | ARMv6 cores have more efficient synchronization primitives. Setting |
| 424 | <code>$GOARM</code> to 5 will compile the runtime libraries using |
| 425 | just SWP instructions that work on older architectures as well. |
| 426 | Running v6 code on an older core will cause an illegal instruction trap. |
| 427 | </dd> |
| 428 | </dl> |
| 429 | |
| 430 | <p> |
| 431 | Note that <code>$GOARCH</code> and <code>$GOOS</code> identify the |
| 432 | <em>target</em> environment, not the environment you are running on. |
| 433 | In effect, you are always cross-compiling. |
| 434 | By architecture, we mean the kind of binaries |
| 435 | that the target environment can run: |
| 436 | an x86-64 system running a 32-bit-only operating system |
| 437 | must set <code>GOARCH</code> to <code>386</code>, |
| 438 | not <code>amd64</code>. |
| 439 | </p> |
| 440 | |
| 441 | <p> |
| 442 | If you choose to override the defaults, |
| 443 | set these variables in your shell profile (<code>$HOME/.bashrc</code>, |
| 444 | <code>$HOME/.profile</code>, or equivalent). The settings might look |
| 445 | something like this: |
| 446 | </p> |
| 447 | |
| 448 | <pre> |
| 449 | export GOROOT=$HOME/go |
| 450 | export GOARCH=386 |
| 451 | export GOOS=linux |
| 452 | </pre> |