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> |
Rob Pike | 966bf71 | 2011-03-01 13:54:22 -0800 | [diff] [blame] | 57 | Except for things like low-level operating system interface code, the run-time |
Rob Pike | 5f50a81 | 2009-11-05 15:07:42 -0800 | [diff] [blame] | 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, |
Russ Cox | c3e6e6e | 2011-04-26 21:39:22 -0400 | [diff] [blame] | 83 | <li>GNU <tt>make</tt> (version 3.81 or later), |
Andrew Gerrand | 6ab8d24 | 2010-09-16 14:01:02 +1000 | [diff] [blame] | 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 | eb5e4b8 | 2011-04-14 10:28:59 +1000 | [diff] [blame] | 94 | <p>On Ubuntu/Debian, use <code>sudo apt-get install bison ed gawk gcc libc6-dev |
| 95 | make</code>. If you want to build 32-bit binaries on a 64-bit system you'll |
| 96 | also need the <code>libc6-dev-i386</code> package. |
Andrew Gerrand | 6ab8d24 | 2010-09-16 14:01:02 +1000 | [diff] [blame] | 97 | </p> |
| 98 | |
| 99 | <h2 id="mercurial">Install Mercurial, if needed</h2> |
| 100 | |
| 101 | <p> |
Robert Griesemer | 686490c | 2010-09-29 12:34:24 -0700 | [diff] [blame] | 102 | 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] | 103 | </p> |
| 104 | <pre> |
| 105 | sudo easy_install mercurial |
| 106 | </pre> |
| 107 | (On Ubuntu/Debian, you might try <code>apt-get install python-setuptools |
| 108 | python-dev build-essential</code> first. The Mercurial in your distribution's |
| 109 | package repository will most likely be old and broken.) |
| 110 | </p> |
| 111 | <p> |
| 112 | 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] | 113 | </p> |
| 114 | |
Robert Griesemer | 68b40fb | 2011-02-02 15:53:32 -0800 | [diff] [blame] | 115 | <p> |
| 116 | Mercurial versions 1.7.x and up require the configuration of |
| 117 | <a href="http://mercurial.selenic.com/wiki/CACertificates">Certification Authorities</a> |
| 118 | (CAs). Error messages of the form: |
| 119 | </p> |
| 120 | <pre> |
| 121 | warning: go.googlecode.com certificate with fingerprint b1:af: ... bc not verified (check hostfingerprints or web.cacerts config setting) |
| 122 | </pre> |
| 123 | <p> |
| 124 | when using Mercurial indicate that the CAs are missing. |
| 125 | Check your Mercurial version (<code>hg --version</code>) and |
| 126 | <a href="http://mercurial.selenic.com/wiki/CACertificates#Configuration_of_HTTPS_certificate_authorities">configure the CAs</a> |
| 127 | if necessary. |
| 128 | </p> |
| 129 | |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 130 | <h2 id="fetch">Fetch the repository</h2> |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 131 | |
| 132 | <p> |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 133 | <p>Go will install to a directory named <code>go</code>. |
| 134 | Change to the directory that will be its parent |
| 135 | and make sure the <code>go</code> directory does not exist. |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 136 | Then check out the repository:</p> |
| 137 | |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 138 | <pre> |
Andrew Gerrand | a3baf7f | 2011-05-02 20:40:47 -0700 | [diff] [blame] | 139 | $ hg clone -u release https://go.googlecode.com/hg/ go |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 140 | </pre> |
| 141 | |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 142 | <h2 id="install">Install Go</h2> |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 143 | |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 144 | <p> |
Devon H. O'Dell | 857d4cf | 2009-12-11 15:14:09 -0800 | [diff] [blame] | 145 | To build the Go distribution, run |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 146 | </p> |
| 147 | |
| 148 | <pre> |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 149 | $ cd go/src |
Christopher Wedgwood | 34191d9 | 2010-01-25 00:09:46 -0800 | [diff] [blame] | 150 | $ ./all.bash |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 151 | </pre> |
| 152 | |
| 153 | <p> |
Russ Cox | da392d9 | 2010-08-18 10:08:49 -0400 | [diff] [blame] | 154 | If all goes well, it will finish by printing output like: |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 155 | </p> |
| 156 | |
| 157 | <pre> |
Russ Cox | b9f9476 | 2011-02-14 09:27:02 -0500 | [diff] [blame] | 158 | ALL TESTS PASSED |
Russ Cox | da392d9 | 2010-08-18 10:08:49 -0400 | [diff] [blame] | 159 | |
| 160 | --- |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 161 | Installed Go for linux/amd64 in /home/you/go. |
| 162 | Installed commands in /home/you/go/bin. |
| 163 | *** You need to add /home/you/go/bin to your $PATH. *** |
| 164 | The compiler is 6g. |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 165 | </pre> |
| 166 | |
| 167 | <p> |
Andrew Gerrand | 3fea5ba | 2011-03-03 16:41:03 +1100 | [diff] [blame] | 168 | where the details on the last few lines reflect the operating system, |
Russ Cox | da392d9 | 2010-08-18 10:08:49 -0400 | [diff] [blame] | 169 | architecture, and root directory used during the install. |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 170 | </p> |
| 171 | |
Andrew Gerrand | 6ab8d24 | 2010-09-16 14:01:02 +1000 | [diff] [blame] | 172 | <div class="detail"> |
| 173 | |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 174 | <p>For more information about ways to control the build, |
| 175 | see the discussion of <a href="#environment">environment variables</a> below.</p> |
Andrew Gerrand | 6ab8d24 | 2010-09-16 14:01:02 +1000 | [diff] [blame] | 176 | </div> |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 177 | |
| 178 | <h2 id="writing">Writing programs</h2> |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 179 | |
| 180 | <p> |
| 181 | Given a file <code>file.go</code>, compile it using |
| 182 | </p> |
| 183 | |
| 184 | <pre> |
| 185 | $ 6g file.go |
| 186 | </pre> |
| 187 | |
| 188 | <p> |
| 189 | <code>6g</code> is the Go compiler for <code>amd64</code>; it will write the output |
| 190 | in <code>file.6</code>. The ‘<code>6</code>’ identifies |
| 191 | files for the <code>amd64</code> architecture. |
| 192 | The identifier letters for <code>386</code> and <code>arm</code> |
| 193 | are ‘<code>8</code>’ and ‘<code>5</code>’. |
| 194 | That is, if you were compiling for <code>386</code>, you would use |
| 195 | <code>8g</code> and the output would be named <code>file.8</code>. |
| 196 | </p> |
| 197 | |
| 198 | <p> |
| 199 | To link the file, use |
| 200 | </p> |
| 201 | |
| 202 | <pre> |
| 203 | $ 6l file.6 |
| 204 | </pre> |
| 205 | |
| 206 | <p> |
| 207 | and to run it |
| 208 | </p> |
| 209 | |
| 210 | <pre> |
| 211 | $ ./6.out |
| 212 | </pre> |
| 213 | |
| 214 | <p>A complete example: |
| 215 | </p> |
| 216 | |
| 217 | <pre> |
| 218 | $ cat >hello.go <<EOF |
| 219 | package main |
| 220 | |
| 221 | import "fmt" |
| 222 | |
| 223 | func main() { |
| 224 | fmt.Printf("hello, world\n") |
| 225 | } |
| 226 | EOF |
| 227 | $ 6g hello.go |
| 228 | $ 6l hello.6 |
| 229 | $ ./6.out |
| 230 | hello, world |
| 231 | $ |
| 232 | </pre> |
| 233 | |
| 234 | <p> |
| 235 | There is no need to list <code>hello.6</code>'s package dependencies |
| 236 | (in this case, package <code>fmt</code>) on the <code>6l</code> |
| 237 | command line. |
| 238 | The linker learns about them by reading <code>hello.6</code>. |
| 239 | </p> |
| 240 | |
Andrew Gerrand | 6ab8d24 | 2010-09-16 14:01:02 +1000 | [diff] [blame] | 241 | <div class="detail"> |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 242 | <p> |
| 243 | To build more complicated programs, you will probably |
Russ Cox | 6fff7b2 | 2009-11-08 22:12:51 -0800 | [diff] [blame] | 244 | want to use a |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 245 | <code>Makefile</code>. |
Rob Pike | 5f50a81 | 2009-11-05 15:07:42 -0800 | [diff] [blame] | 246 | There are examples in places like |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 247 | <code>go/src/cmd/godoc/Makefile</code> |
| 248 | and <code>go/src/pkg/*/Makefile</code>. |
Rob Pike | 5f50a81 | 2009-11-05 15:07:42 -0800 | [diff] [blame] | 249 | The |
| 250 | <a href="contribute.html">document</a> |
| 251 | about contributing to the Go project |
| 252 | gives more detail about |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 253 | the process of building and testing Go programs. |
| 254 | </p> |
Andrew Gerrand | 6ab8d24 | 2010-09-16 14:01:02 +1000 | [diff] [blame] | 255 | </div> |
| 256 | |
| 257 | <h2 id="next">What's next</h2> |
| 258 | |
| 259 | <p> |
| 260 | Start by reading the <a href="go_tutorial.html">Go Tutorial</a>. |
| 261 | </p> |
| 262 | |
| 263 | <p> |
| 264 | Build a web application by following the <a href="codelab/wiki/">Wiki |
| 265 | Codelab</a>. |
| 266 | </p> |
| 267 | |
| 268 | <p> |
| 269 | Read <a href="effective_go.html">Effective Go</a> to learn about writing |
| 270 | idiomatic Go code. |
| 271 | </p> |
| 272 | |
| 273 | <p> |
| 274 | For the full story, consult Go's extensive |
| 275 | <a href="docs.html">documentation</a>. |
| 276 | </p> |
Russ Cox | 8b04cef | 2009-11-08 23:38:30 -0800 | [diff] [blame] | 277 | |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 278 | <h2 id="releases">Keeping up with releases</h2> |
Russ Cox | 3269647 | 2009-12-15 19:16:56 -0800 | [diff] [blame] | 279 | |
Andrew Gerrand | 929449d | 2011-03-17 16:33:10 +1100 | [diff] [blame] | 280 | <p> |
| 281 | The Go project maintains two stable tags in its Mercurial repository: |
| 282 | <code>release</code> and <code>weekly</code>. |
| 283 | The <code>weekly</code> tag is updated about once a week, and should be used by |
| 284 | those who want to track the project's development. |
| 285 | The <code>release</code> tag is given, less often, to those weekly releases |
| 286 | that have proven themselves to be robust. |
| 287 | </p> |
| 288 | |
| 289 | <p> |
| 290 | Most Go users will want to keep their Go installation at the latest |
| 291 | <code>release</code> tag. |
| 292 | New releases are announced on the |
| 293 | <a href="http://groups.google.com/group/golang-announce">golang-announce</a> |
| 294 | mailing list. |
| 295 | </p> |
| 296 | |
| 297 | <p> |
Russ Cox | 3269647 | 2009-12-15 19:16:56 -0800 | [diff] [blame] | 298 | To update an existing tree to the latest release, you can run: |
| 299 | </p> |
| 300 | |
| 301 | <pre> |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 302 | $ cd go/src |
Russ Cox | 3269647 | 2009-12-15 19:16:56 -0800 | [diff] [blame] | 303 | $ hg pull |
| 304 | $ hg update release |
Russ Cox | 05f2636 | 2010-01-28 18:18:40 -0800 | [diff] [blame] | 305 | $ ./all.bash |
Russ Cox | 3269647 | 2009-12-15 19:16:56 -0800 | [diff] [blame] | 306 | </pre> |
| 307 | |
Andrew Gerrand | 929449d | 2011-03-17 16:33:10 +1100 | [diff] [blame] | 308 | <p> |
| 309 | To use the <code>weekly</code> tag run <code>hg update weekly</code> instead. |
| 310 | </p> |
| 311 | |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 312 | <h2 id="community">Community resources</h2> |
Russ Cox | 8b04cef | 2009-11-08 23:38:30 -0800 | [diff] [blame] | 313 | |
| 314 | <p> |
| 315 | For real-time help, there may be users or developers on |
| 316 | <code>#go-nuts</code> on the <a href="http://freenode.net/">Freenode</a> IRC server. |
| 317 | </p> |
| 318 | |
| 319 | <p> |
| 320 | The official mailing list for discussion of the Go language is |
| 321 | <a href="http://groups.google.com/group/golang-nuts">Go Nuts</a>. |
| 322 | </p> |
| 323 | |
| 324 | <p> |
| 325 | Bugs can be reported using the <a href="http://code.google.com/p/go/issues/list">Go issue tracker</a>. |
| 326 | </p> |
| 327 | |
| 328 | <p> |
| 329 | For those who wish to keep up with development, |
| 330 | there is another mailing list, <a href="http://groups.google.com/group/golang-checkins">golang-checkins</a>, |
| 331 | that receives a message summarizing each checkin to the Go repository. |
| 332 | </p> |
| 333 | |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 334 | <h2 id="environment">Environment variables</h2> |
Russ Cox | 8b04cef | 2009-11-08 23:38:30 -0800 | [diff] [blame] | 335 | |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 336 | <p> |
Andrew Gerrand | f89050d | 2010-12-05 12:04:15 +0900 | [diff] [blame] | 337 | The Go compilation environment can be customized by environment variables. |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 338 | None are required by the build, but you may wish to set them |
| 339 | to override the defaults. |
| 340 | </p> |
| 341 | |
| 342 | <dl> |
| 343 | <dt> |
| 344 | <code>$GOROOT</code> |
| 345 | </dt> |
| 346 | <dd> |
| 347 | The root of the Go tree, often <code>$HOME/go</code>. |
| 348 | This defaults to the parent of the directory where <code>all.bash</code> is run. |
| 349 | If you choose not to set <code>$GOROOT</code>, you must |
| 350 | run <code>gomake</code> instead of <code>make</code> or <code>gmake</code> |
| 351 | when developing Go programs using the conventional makefiles. |
| 352 | </dd> |
| 353 | |
| 354 | <dt> |
| 355 | <code>$GOROOT_FINAL</code> |
| 356 | </dt> |
| 357 | <dd> |
| 358 | The value assumed by installed binaries and scripts when |
| 359 | <code>$GOROOT</code> is not set. |
| 360 | It defaults to the value used for <code>$GOROOT</code>. |
| 361 | If you want to build the Go tree in one location |
| 362 | but move it elsewhere after the build, set |
| 363 | <code>$GOROOT_FINAL</code> to the eventual location. |
| 364 | </dd> |
| 365 | |
| 366 | <dt> |
| 367 | <code>$GOOS</code> and <code>$GOARCH</code> |
| 368 | </dt> |
| 369 | <dd> |
| 370 | The name of the target operating system and compilation architecture. |
Andrew Gerrand | f89050d | 2010-12-05 12:04:15 +0900 | [diff] [blame] | 371 | These default to the values of <code>$GOHOSTOS</code> and |
| 372 | <code>$GOHOSTARCH</code> respectively (described below). |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 373 | |
| 374 | <p> |
| 375 | Choices for <code>$GOOS</code> are <code>linux</code>, |
| 376 | <code>freebsd</code>, |
| 377 | <code>darwin</code> (Mac OS X 10.5 or 10.6), |
Peter Mundy | c17394df | 2010-12-08 20:27:45 +1100 | [diff] [blame] | 378 | and <code>windows</code> (Windows, an incomplete port). |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 379 | Choices for <code>$GOARCH</code> are <code>amd64</code> (64-bit x86, the most mature port), |
| 380 | <code>386</code> (32-bit x86), and |
| 381 | <code>arm</code> (32-bit ARM, an incomplete port). |
| 382 | The valid combinations of <code>$GOOS</code> and <code>$GOARCH</code> are: |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 383 | <table cellpadding="0"> |
| 384 | <tr> |
| 385 | <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> |
| 386 | </tr> |
| 387 | <tr> |
| 388 | <td></td><td><code>darwin</code></td> <td><code>386</code></td> |
| 389 | </tr> |
| 390 | <tr> |
| 391 | <td></td><td><code>darwin</code></td> <td><code>amd64</code></td> |
| 392 | </tr> |
| 393 | <tr> |
| 394 | <td></td><td><code>freebsd</code></td> <td><code>386</code></td> |
| 395 | </tr> |
| 396 | <tr> |
| 397 | <td></td><td><code>freebsd</code></td> <td><code>amd64</code></td> |
| 398 | </tr> |
| 399 | <tr> |
| 400 | <td></td><td><code>linux</code></td> <td><code>386</code></td> |
| 401 | </tr> |
| 402 | <tr> |
| 403 | <td></td><td><code>linux</code></td> <td><code>amd64</code></td> |
| 404 | </tr> |
| 405 | <tr> |
| 406 | <td></td><td><code>linux</code></td> <td><code>arm</code></td> <td><i>incomplete</i></td> |
| 407 | </tr> |
| 408 | <tr> |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 409 | <td></td><td><code>windows</code></td> <td><code>386</code></td> <td><i>incomplete</i></td> |
| 410 | </tr> |
| 411 | </table> |
| 412 | </dd> |
| 413 | |
| 414 | <dt> |
Andrew Gerrand | f89050d | 2010-12-05 12:04:15 +0900 | [diff] [blame] | 415 | <code>$GOHOSTOS</code> and <code>$GOHOSTARCH</code> |
| 416 | </dt> |
| 417 | <dd> |
| 418 | The name of the host operating system and compilation architecture. |
| 419 | These default to the local system's operating system and |
| 420 | architecture. |
| 421 | |
| 422 | <p> |
| 423 | Valid choices are the same as for <code>$GOOS</code> and |
| 424 | <code>$GOARCH</code>, listed above. |
| 425 | The specified values must be compatible with the local system. |
| 426 | For example, you should not set <code>$GOHOSTARCH</code> to |
| 427 | <code>arm</code> on an x86 system. |
| 428 | </dd> |
| 429 | |
| 430 | <dt> |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 431 | <code>$GOBIN</code> |
| 432 | </dt> |
| 433 | <dd> |
| 434 | The location where binaries will be installed. |
| 435 | The default is <code>$GOROOT/bin</code>. |
| 436 | After installing, you will want to arrange to add this |
| 437 | directory to your <code>$PATH</code>, so you can use the tools. |
| 438 | </dd> |
| 439 | |
| 440 | <dt> |
| 441 | <code>$GOARM</code> (arm, default=6) |
| 442 | </dt> |
| 443 | <dd> |
Rob Pike | 966bf71 | 2011-03-01 13:54:22 -0800 | [diff] [blame] | 444 | The ARM architecture version the run-time libraries should target. |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 445 | ARMv6 cores have more efficient synchronization primitives. Setting |
Rob Pike | 966bf71 | 2011-03-01 13:54:22 -0800 | [diff] [blame] | 446 | <code>$GOARM</code> to 5 will compile the run-time libraries using |
Russ Cox | 86920ad | 2010-08-24 20:00:50 -0400 | [diff] [blame] | 447 | just SWP instructions that work on older architectures as well. |
| 448 | Running v6 code on an older core will cause an illegal instruction trap. |
| 449 | </dd> |
| 450 | </dl> |
| 451 | |
| 452 | <p> |
| 453 | Note that <code>$GOARCH</code> and <code>$GOOS</code> identify the |
| 454 | <em>target</em> environment, not the environment you are running on. |
| 455 | In effect, you are always cross-compiling. |
| 456 | By architecture, we mean the kind of binaries |
| 457 | that the target environment can run: |
| 458 | an x86-64 system running a 32-bit-only operating system |
| 459 | must set <code>GOARCH</code> to <code>386</code>, |
| 460 | not <code>amd64</code>. |
| 461 | </p> |
| 462 | |
| 463 | <p> |
| 464 | If you choose to override the defaults, |
| 465 | set these variables in your shell profile (<code>$HOME/.bashrc</code>, |
| 466 | <code>$HOME/.profile</code>, or equivalent). The settings might look |
| 467 | something like this: |
| 468 | </p> |
| 469 | |
| 470 | <pre> |
| 471 | export GOROOT=$HOME/go |
| 472 | export GOARCH=386 |
| 473 | export GOOS=linux |
| 474 | </pre> |