Andrew Gerrand | 7cb21a7 | 2012-01-19 11:24:54 +1100 | [diff] [blame] | 1 | <!--{ |
Andrew Gerrand | d84de09 | 2012-02-13 21:22:36 +1100 | [diff] [blame] | 2 | "Title": "Getting Started", |
Andrew Gerrand | f78d50c | 2012-03-05 14:31:27 +1100 | [diff] [blame] | 3 | "Path": "/doc/install" |
Andrew Gerrand | 7cb21a7 | 2012-01-19 11:24:54 +1100 | [diff] [blame] | 4 | }--> |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 5 | |
Andrew Gerrand | 062a86b | 2013-04-03 15:59:17 +1100 | [diff] [blame] | 6 | <h2 id="download">Download the Go distribution</h2> |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 7 | |
| 8 | <p> |
Matthew Dempsky | 6e55f7a | 2014-09-12 09:15:58 +1000 | [diff] [blame] | 9 | <a href="https://golang.org/dl/" id="start" class="download" target="_blank"> |
Andrew Gerrand | 062a86b | 2013-04-03 15:59:17 +1100 | [diff] [blame] | 10 | <span class="big">Download Go</span> |
| 11 | <span class="desc">Click here to visit the downloads page</span> |
| 12 | </a> |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 13 | </p> |
| 14 | |
Rob Pike | 5f50a81 | 2009-11-05 15:07:42 -0800 | [diff] [blame] | 15 | <p> |
Matthew Dempsky | 6e55f7a | 2014-09-12 09:15:58 +1000 | [diff] [blame] | 16 | <a href="https://golang.org/dl/" target="_blank">Official binary |
Bill Thiede | e9ce76b | 2015-01-17 21:09:15 -0800 | [diff] [blame] | 17 | distributions</a> are available for the FreeBSD (release 8-STABLE and above), |
| 18 | Linux, Mac OS X (Snow Leopard and above), and Windows operating systems and |
| 19 | the 32-bit (<code>386</code>) and 64-bit (<code>amd64</code>) x86 processor |
| 20 | architectures. |
Andrew Gerrand | 062a86b | 2013-04-03 15:59:17 +1100 | [diff] [blame] | 21 | </p> |
| 22 | |
| 23 | <p> |
| 24 | If a binary distribution is not available for your combination of operating |
Andrew Gerrand | c497c9e | 2013-11-21 07:55:29 +1100 | [diff] [blame] | 25 | system and architecture, try |
Andrew Gerrand | 062a86b | 2013-04-03 15:59:17 +1100 | [diff] [blame] | 26 | <a href="/doc/install/source">installing from source</a> or |
| 27 | <a href="/doc/install/gccgo">installing gccgo instead of gc</a>. |
Rob Pike | 5f50a81 | 2009-11-05 15:07:42 -0800 | [diff] [blame] | 28 | </p> |
| 29 | |
Andrew Gerrand | c497c9e | 2013-11-21 07:55:29 +1100 | [diff] [blame] | 30 | |
Shenghou Ma | ab708e3 | 2012-05-16 14:54:48 +1000 | [diff] [blame] | 31 | <h2 id="requirements">System requirements</h2> |
Andrew Gerrand | c497c9e | 2013-11-21 07:55:29 +1100 | [diff] [blame] | 32 | |
Shenghou Ma | ab708e3 | 2012-05-16 14:54:48 +1000 | [diff] [blame] | 33 | <p> |
| 34 | The <code>gc</code> compiler supports the following operating systems and |
| 35 | architectures. Please ensure your system meets these requirements before |
| 36 | proceeding. If your OS or architecture is not on the list, it's possible that |
| 37 | <code>gccgo</code> might support your setup; see |
| 38 | <a href="/doc/install/gccgo">Setting up and using gccgo</a> for details. |
| 39 | </p> |
| 40 | |
| 41 | <table class="codetable" frame="border" summary="requirements"> |
| 42 | <tr> |
Rob Pike | 761dace | 2014-06-10 11:19:41 -0700 | [diff] [blame] | 43 | <th align="center">Operating system</th> |
| 44 | <th align="center">Architectures</th> |
| 45 | <th align="center">Notes</th> |
Shenghou Ma | ab708e3 | 2012-05-16 14:54:48 +1000 | [diff] [blame] | 46 | </tr> |
| 47 | <tr><td colspan="3"><hr></td></tr> |
Bill Thiede | e9ce76b | 2015-01-17 21:09:15 -0800 | [diff] [blame] | 48 | <tr><td>FreeBSD 8-STABLE or later</td> <td>amd64, 386, arm</td> <td>Debian GNU/kFreeBSD not supported; FreeBSD/ARM needs FreeBSD 10 or later</td></tr> |
Shenghou Ma | edc7b47 | 2012-08-07 11:12:54 +0800 | [diff] [blame] | 49 | <tr><td>Linux 2.6.23 or later with glibc</td> <td>amd64, 386, arm</td> <td>CentOS/RHEL 5.x not supported; no binary distribution for ARM yet</td></tr> |
Andrew Gerrand | c72bce9 | 2013-11-13 11:53:01 +1100 | [diff] [blame] | 50 | <tr><td>Mac OS X 10.6 or later</td> <td>amd64, 386</td> <td>use the gcc<sup>†</sup> that comes with Xcode<sup>‡</sup></td></tr> |
Yasuhiro Matsumoto | 59439f8 | 2014-11-14 14:05:14 +1100 | [diff] [blame] | 51 | <tr><td>Windows XP or later</td> <td>amd64, 386</td> <td>use MinGW gcc<sup>†</sup>. No need for cygwin or msys.</td></tr> |
Shenghou Ma | ab708e3 | 2012-05-16 14:54:48 +1000 | [diff] [blame] | 52 | </table> |
| 53 | |
| 54 | <p> |
Shenghou Ma | 2701046 | 2012-08-20 21:21:09 +0800 | [diff] [blame] | 55 | <sup>†</sup><code>gcc</code> is required only if you plan to use |
| 56 | <a href="/cmd/cgo">cgo</a>.<br/> |
| 57 | <sup>‡</sup>You only need to install the command line tools for |
| 58 | <a href="http://developer.apple.com/Xcode/">Xcode</a>. If you have already |
| 59 | installed Xcode 4.3+, you can install it from the Components tab of the |
| 60 | Downloads preferences panel. |
Shenghou Ma | ab708e3 | 2012-05-16 14:54:48 +1000 | [diff] [blame] | 61 | </p> |
| 62 | |
Andrew Gerrand | c497c9e | 2013-11-21 07:55:29 +1100 | [diff] [blame] | 63 | |
Andrew Gerrand | ce06e15 | 2012-03-26 13:59:30 +1100 | [diff] [blame] | 64 | <h2 id="install">Install the Go tools</h2> |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 65 | |
| 66 | <p> |
Andrew Gerrand | 218f08a | 2012-09-17 17:01:09 -0700 | [diff] [blame] | 67 | If you are upgrading from an older version of Go you must |
Andrew Gerrand | f43b6d4 | 2013-09-16 11:20:07 +1000 | [diff] [blame] | 68 | first <a href="#uninstall">remove the existing version</a>. |
Andrew Gerrand | c497c9e | 2013-11-21 07:55:29 +1100 | [diff] [blame] | 69 | </p> |
| 70 | |
| 71 | <h3 id="tarball">Linux, Mac OS X, and FreeBSD tarballs</h3> |
Andrew Gerrand | e10dc82 | 2012-02-27 14:16:56 +1100 | [diff] [blame] | 72 | |
| 73 | <p> |
Matthew Dempsky | 6e55f7a | 2014-09-12 09:15:58 +1000 | [diff] [blame] | 74 | <a href="https://golang.org/dl/">Download the archive</a> |
Andrew Gerrand | c497c9e | 2013-11-21 07:55:29 +1100 | [diff] [blame] | 75 | and extract it into <code>/usr/local</code>, creating a Go tree in |
| 76 | <code>/usr/local/go</code>. For example: |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 77 | </p> |
| 78 | |
| 79 | <pre> |
Shenghou Ma | 2b6eb11 | 2014-02-06 16:09:01 -0500 | [diff] [blame] | 80 | tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 81 | </pre> |
| 82 | |
Andrew Gerrand | ce06e15 | 2012-03-26 13:59:30 +1100 | [diff] [blame] | 83 | <p> |
Shenghou Ma | 2b6eb11 | 2014-02-06 16:09:01 -0500 | [diff] [blame] | 84 | Choose the archive file appropriate for your installation. |
Andrew Gerrand | 77edde1a | 2014-03-03 11:26:18 +1100 | [diff] [blame] | 85 | For instance, if you are installing Go version 1.2.1 for 64-bit x86 on Linux, |
| 86 | the archive you want is called <code>go1.2.1.linux-amd64.tar.gz</code>. |
Andrew Gerrand | a7d4c3f | 2012-09-27 15:34:18 -0700 | [diff] [blame] | 87 | </p> |
| 88 | |
| 89 | <p> |
Andrew Gerrand | ce06e15 | 2012-03-26 13:59:30 +1100 | [diff] [blame] | 90 | (Typically these commands must be run as root or through <code>sudo</code>.) |
| 91 | </p> |
Andrew Gerrand | e10dc82 | 2012-02-27 14:16:56 +1100 | [diff] [blame] | 92 | |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 93 | <p> |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 94 | Add <code>/usr/local/go/bin</code> to the <code>PATH</code> environment |
| 95 | variable. You can do this by adding this line to your <code>/etc/profile</code> |
| 96 | (for a system-wide installation) or <code>$HOME/.profile</code>: |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 97 | </p> |
| 98 | |
| 99 | <pre> |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 100 | export PATH=$PATH:/usr/local/go/bin |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 101 | </pre> |
| 102 | |
Oling Cat | 07d2195 | 2013-11-25 13:36:16 +1100 | [diff] [blame] | 103 | <h4 id="tarball_non_standard">Installing to a custom location</h4> |
Andrew Gerrand | c497c9e | 2013-11-21 07:55:29 +1100 | [diff] [blame] | 104 | |
| 105 | <p> |
| 106 | The Go binary distributions assume they will be installed in |
| 107 | <code>/usr/local/go</code> (or <code>c:\Go</code> under Windows), |
Oling Cat | 07d2195 | 2013-11-25 13:36:16 +1100 | [diff] [blame] | 108 | but it is possible to install the Go tools to a different location. |
Andrew Gerrand | c497c9e | 2013-11-21 07:55:29 +1100 | [diff] [blame] | 109 | In this case you must set the <code>GOROOT</code> environment variable |
| 110 | to point to the directory in which it was installed. |
| 111 | </p> |
| 112 | |
| 113 | <p> |
| 114 | For example, if you installed Go to your home directory you should add the |
| 115 | following commands to <code>$HOME/.profile</code>: |
| 116 | </p> |
| 117 | |
| 118 | <pre> |
| 119 | export GOROOT=$HOME/go |
| 120 | export PATH=$PATH:$GOROOT/bin |
| 121 | </pre> |
| 122 | |
| 123 | <p> |
| 124 | <b>Note</b>: <code>GOROOT</code> must be set only when installing to a custom |
| 125 | location. |
| 126 | </p> |
| 127 | |
Andrew Gerrand | 218f08a | 2012-09-17 17:01:09 -0700 | [diff] [blame] | 128 | <h3 id="osx">Mac OS X package installer</h3> |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 129 | |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 130 | <p> |
Matthew Dempsky | 6e55f7a | 2014-09-12 09:15:58 +1000 | [diff] [blame] | 131 | <a href="https://golang.org/dl/">Download the package file</a>, |
Andrew Gerrand | c497c9e | 2013-11-21 07:55:29 +1100 | [diff] [blame] | 132 | open it, and follow the prompts to install the Go tools. |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 133 | The package installs the Go distribution to <code>/usr/local/go</code>. |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 134 | </p> |
| 135 | |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 136 | <p> |
| 137 | The package should put the <code>/usr/local/go/bin</code> directory in your |
| 138 | <code>PATH</code> environment variable. You may need to restart any open |
| 139 | Terminal sessions for the change to take effect. |
| 140 | </p> |
Andrew Gerrand | 6ab8d24 | 2010-09-16 14:01:02 +1000 | [diff] [blame] | 141 | |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 142 | <h3 id="windows">Windows</h3> |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 143 | |
| 144 | <p> |
Andrew Gerrand | cf46040 | 2012-03-13 15:02:14 +1100 | [diff] [blame] | 145 | The Go project provides two installation options for Windows users |
| 146 | (besides <a href="/doc/install/source">installing from source</a>): |
Andrew Gerrand | 1b89d51 | 2012-03-27 11:19:30 +1100 | [diff] [blame] | 147 | a zip archive that requires you to set some environment variables and an |
Andrew Gerrand | f43b6d4 | 2013-09-16 11:20:07 +1000 | [diff] [blame] | 148 | MSI installer that configures your installation automatically. |
Andrew Gerrand | cf46040 | 2012-03-13 15:02:14 +1100 | [diff] [blame] | 149 | </p> |
| 150 | |
Andrew Gerrand | f43b6d4 | 2013-09-16 11:20:07 +1000 | [diff] [blame] | 151 | <h4 id="windows_msi">MSI installer</h4> |
Andrew Gerrand | cf46040 | 2012-03-13 15:02:14 +1100 | [diff] [blame] | 152 | |
| 153 | <p> |
Matthew Dempsky | 6e55f7a | 2014-09-12 09:15:58 +1000 | [diff] [blame] | 154 | Open the <a href="https://golang.org/dl/">MSI file</a> |
Andrew Gerrand | ce06e15 | 2012-03-26 13:59:30 +1100 | [diff] [blame] | 155 | and follow the prompts to install the Go tools. |
Andrew Gerrand | d70627e | 2012-03-06 15:16:02 +1100 | [diff] [blame] | 156 | By default, the installer puts the Go distribution in <code>c:\Go</code>. |
| 157 | </p> |
| 158 | |
| 159 | <p> |
| 160 | The installer should put the <code>c:\Go\bin</code> directory in your |
| 161 | <code>PATH</code> environment variable. You may need to restart any open |
| 162 | command prompts for the change to take effect. |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 163 | </p> |
| 164 | |
Andrew Gerrand | c497c9e | 2013-11-21 07:55:29 +1100 | [diff] [blame] | 165 | <h4 id="windows_zip">Zip archive</h4> |
| 166 | |
| 167 | <p> |
Matthew Dempsky | 6e55f7a | 2014-09-12 09:15:58 +1000 | [diff] [blame] | 168 | <a href="https://golang.org/dl/">Download the zip file</a> and extract it into the directory of your choice (we suggest <code>c:\Go</code>). |
Andrew Gerrand | c497c9e | 2013-11-21 07:55:29 +1100 | [diff] [blame] | 169 | </p> |
| 170 | |
| 171 | <p> |
| 172 | If you chose a directory other than <code>c:\Go</code>, |
| 173 | you must set the <code>GOROOT</code> environment variable to your chosen path. |
| 174 | </p> |
| 175 | |
| 176 | <p> |
| 177 | Add the <code>bin</code> subdirectory of your Go root (for example, <code>c:\Go\bin</code>) to your <code>PATH</code> environment variable. |
| 178 | </p> |
| 179 | |
Andrew Gerrand | cf46040 | 2012-03-13 15:02:14 +1100 | [diff] [blame] | 180 | <h4 id="windows_env">Setting environment variables under Windows</h4> |
| 181 | |
| 182 | <p> |
| 183 | Under Windows, you may set environment variables through the "Environment |
| 184 | Variables" button on the "Advanced" tab of the "System" control panel. Some |
| 185 | versions of Windows provide this control panel through the "Advanced System |
| 186 | Settings" option inside the "System" control panel. |
| 187 | </p> |
| 188 | |
Andrew Gerrand | c497c9e | 2013-11-21 07:55:29 +1100 | [diff] [blame] | 189 | |
Andrew Gerrand | ce06e15 | 2012-03-26 13:59:30 +1100 | [diff] [blame] | 190 | <h2 id="testing">Test your installation</h2> |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 191 | |
| 192 | <p> |
| 193 | Check that Go is installed correctly by building a simple program, as follows. |
| 194 | </p> |
| 195 | |
| 196 | <p> |
| 197 | Create a file named <code>hello.go</code> and put the following program in it: |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 198 | </p> |
| 199 | |
| 200 | <pre> |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 201 | package main |
| 202 | |
| 203 | import "fmt" |
| 204 | |
| 205 | func main() { |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 206 | fmt.Printf("hello, world\n") |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 207 | } |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 208 | </pre> |
| 209 | |
| 210 | <p> |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 211 | Then run it with the <code>go</code> tool: |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 212 | </p> |
| 213 | |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 214 | <pre> |
| 215 | $ go run hello.go |
| 216 | hello, world |
| 217 | </pre> |
| 218 | |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 219 | <p> |
Andrew Gerrand | e07f089 | 2012-02-14 17:02:28 +1100 | [diff] [blame] | 220 | If you see the "hello, world" message then your Go installation is working. |
Russ Cox | fb39a4d | 2009-10-23 15:24:08 -0700 | [diff] [blame] | 221 | </p> |
Andrew Gerrand | 6ab8d24 | 2010-09-16 14:01:02 +1000 | [diff] [blame] | 222 | |
Andrew Gerrand | c497c9e | 2013-11-21 07:55:29 +1100 | [diff] [blame] | 223 | |
Andrew Gerrand | 9115a8b | 2012-06-13 10:33:02 +1000 | [diff] [blame] | 224 | <h2 id="gopath">Set up your work environment</h2> |
| 225 | |
| 226 | <p> |
Andrew Gerrand | c497c9e | 2013-11-21 07:55:29 +1100 | [diff] [blame] | 227 | You're almost done. |
Andrew Gerrand | dc08957 | 2014-09-09 07:35:44 +1000 | [diff] [blame] | 228 | You just need to set up your environment. |
Andrew Gerrand | 6ab8d24 | 2010-09-16 14:01:02 +1000 | [diff] [blame] | 229 | </p> |
| 230 | |
| 231 | <p> |
Andrew Gerrand | dc08957 | 2014-09-09 07:35:44 +1000 | [diff] [blame] | 232 | Read the <a href="/doc/code.html">How to Write Go Code</a> document, |
| 233 | which provides <b>essential setup instructions</b> for using the Go tools. |
Russ Cox | 8b04cef | 2009-11-08 23:38:30 -0800 | [diff] [blame] | 234 | </p> |
Andrew Gerrand | f43b6d4 | 2013-09-16 11:20:07 +1000 | [diff] [blame] | 235 | |
| 236 | |
| 237 | <h2 id="uninstall">Uninstalling Go</h2> |
| 238 | |
| 239 | <p> |
| 240 | To remove an existing Go installation from your system delete the |
| 241 | <code>go</code> directory. This is usually <code>/usr/local/go</code> |
| 242 | under Linux, Mac OS X, and FreeBSD or <code>c:\Go</code> |
| 243 | under Windows. |
| 244 | </p> |
| 245 | |
| 246 | <p> |
| 247 | You should also remove the Go <code>bin</code> directory from your |
| 248 | <code>PATH</code> environment variable. |
| 249 | Under Linux and FreeBSD you should edit <code>/etc/profile</code> or |
| 250 | <code>$HOME/.profile</code>. |
| 251 | If you installed Go with the <a href="#osx">Mac OS X package</a> then you |
| 252 | should remove the <code>/etc/paths.d/go</code> file. |
| 253 | Windows users should read the section about <a href="#windows_env">setting |
| 254 | environment variables under Windows</a>. |
| 255 | </p> |
| 256 | |
| 257 | |
Andrew Gerrand | c497c9e | 2013-11-21 07:55:29 +1100 | [diff] [blame] | 258 | <h2 id="help">Getting help</h2> |
| 259 | |
| 260 | <p> |
| 261 | For real-time help, ask the helpful gophers in <code>#go-nuts</code> on the |
| 262 | <a href="http://freenode.net/">Freenode</a> IRC server. |
| 263 | </p> |
| 264 | |
| 265 | <p> |
| 266 | The official mailing list for discussion of the Go language is |
Andrew Gerrand | 43ad89d | 2014-07-25 10:28:39 +1000 | [diff] [blame] | 267 | <a href="//groups.google.com/group/golang-nuts">Go Nuts</a>. |
Andrew Gerrand | c497c9e | 2013-11-21 07:55:29 +1100 | [diff] [blame] | 268 | </p> |
| 269 | |
| 270 | <p> |
| 271 | Report bugs using the |
Andrew Gerrand | 43ad89d | 2014-07-25 10:28:39 +1000 | [diff] [blame] | 272 | <a href="//golang.org/issue">Go issue tracker</a>. |
Andrew Gerrand | c497c9e | 2013-11-21 07:55:29 +1100 | [diff] [blame] | 273 | </p> |