blob: 8c9322fd53bd16e2d2d3af549fe188db90adc5d4 [file] [log] [blame]
Andrew Gerrand7cb21a72012-01-19 11:24:54 +11001<!--{
Andrew Gerrandd84de092012-02-13 21:22:36 +11002 "Title": "Getting Started",
Andrew Gerrandf78d50c2012-03-05 14:31:27 +11003 "Path": "/doc/install"
Andrew Gerrand7cb21a72012-01-19 11:24:54 +11004}-->
Russ Coxfb39a4d2009-10-23 15:24:08 -07005
Andrew Gerrand062a86b2013-04-03 15:59:17 +11006<h2 id="download">Download the Go distribution</h2>
Russ Coxfb39a4d2009-10-23 15:24:08 -07007
8<p>
Matthew Dempsky6e55f7a2014-09-12 09:15:58 +10009<a href="https://golang.org/dl/" id="start" class="download" target="_blank">
Andrew Gerrand062a86b2013-04-03 15:59:17 +110010<span class="big">Download Go</span>
11<span class="desc">Click here to visit the downloads page</span>
12</a>
Russ Coxfb39a4d2009-10-23 15:24:08 -070013</p>
14
Rob Pike5f50a812009-11-05 15:07:42 -080015<p>
Matthew Dempsky6e55f7a2014-09-12 09:15:58 +100016<a href="https://golang.org/dl/" target="_blank">Official binary
Bill Thiedee9ce76b2015-01-17 21:09:15 -080017distributions</a> are available for the FreeBSD (release 8-STABLE and above),
18Linux, Mac OS X (Snow Leopard and above), and Windows operating systems and
19the 32-bit (<code>386</code>) and 64-bit (<code>amd64</code>) x86 processor
20architectures.
Andrew Gerrand062a86b2013-04-03 15:59:17 +110021</p>
22
23<p>
24If a binary distribution is not available for your combination of operating
Andrew Gerrandc497c9e2013-11-21 07:55:29 +110025system and architecture, try
Andrew Gerrand062a86b2013-04-03 15:59:17 +110026<a href="/doc/install/source">installing from source</a> or
27<a href="/doc/install/gccgo">installing gccgo instead of gc</a>.
Rob Pike5f50a812009-11-05 15:07:42 -080028</p>
29
Andrew Gerrandc497c9e2013-11-21 07:55:29 +110030
Shenghou Maab708e32012-05-16 14:54:48 +100031<h2 id="requirements">System requirements</h2>
Andrew Gerrandc497c9e2013-11-21 07:55:29 +110032
Shenghou Maab708e32012-05-16 14:54:48 +100033<p>
34The <code>gc</code> compiler supports the following operating systems and
35architectures. Please ensure your system meets these requirements before
36proceeding. 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 Pike761dace2014-06-10 11:19:41 -070043<th align="center">Operating system</th>
44<th align="center">Architectures</th>
45<th align="center">Notes</th>
Shenghou Maab708e32012-05-16 14:54:48 +100046</tr>
47<tr><td colspan="3"><hr></td></tr>
Bill Thiedee9ce76b2015-01-17 21:09:15 -080048<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 Maedc7b472012-08-07 11:12:54 +080049<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 Gerrandc72bce92013-11-13 11:53:01 +110050<tr><td>Mac OS X 10.6 or later</td> <td>amd64, 386</td> <td>use the gcc<sup>&#8224;</sup> that comes with Xcode<sup>&#8225;</sup></td></tr>
Yasuhiro Matsumoto59439f82014-11-14 14:05:14 +110051<tr><td>Windows XP or later</td> <td>amd64, 386</td> <td>use MinGW gcc<sup>&#8224;</sup>. No need for cygwin or msys.</td></tr>
Shenghou Maab708e32012-05-16 14:54:48 +100052</table>
53
54<p>
Shenghou Ma27010462012-08-20 21:21:09 +080055<sup>&#8224;</sup><code>gcc</code> is required only if you plan to use
56<a href="/cmd/cgo">cgo</a>.<br/>
57<sup>&#8225;</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
59installed Xcode 4.3+, you can install it from the Components tab of the
60Downloads preferences panel.
Shenghou Maab708e32012-05-16 14:54:48 +100061</p>
62
Andrew Gerrandc497c9e2013-11-21 07:55:29 +110063
Andrew Gerrandce06e152012-03-26 13:59:30 +110064<h2 id="install">Install the Go tools</h2>
Russ Coxfb39a4d2009-10-23 15:24:08 -070065
66<p>
Andrew Gerrand218f08a2012-09-17 17:01:09 -070067If you are upgrading from an older version of Go you must
Andrew Gerrandf43b6d42013-09-16 11:20:07 +100068first <a href="#uninstall">remove the existing version</a>.
Andrew Gerrandc497c9e2013-11-21 07:55:29 +110069</p>
70
71<h3 id="tarball">Linux, Mac OS X, and FreeBSD tarballs</h3>
Andrew Gerrande10dc822012-02-27 14:16:56 +110072
73<p>
Matthew Dempsky6e55f7a2014-09-12 09:15:58 +100074<a href="https://golang.org/dl/">Download the archive</a>
Andrew Gerrandc497c9e2013-11-21 07:55:29 +110075and extract it into <code>/usr/local</code>, creating a Go tree in
76<code>/usr/local/go</code>. For example:
Russ Coxfb39a4d2009-10-23 15:24:08 -070077</p>
78
79<pre>
Shenghou Ma2b6eb112014-02-06 16:09:01 -050080tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz
Russ Coxfb39a4d2009-10-23 15:24:08 -070081</pre>
82
Andrew Gerrandce06e152012-03-26 13:59:30 +110083<p>
Shenghou Ma2b6eb112014-02-06 16:09:01 -050084Choose the archive file appropriate for your installation.
Andrew Gerrand77edde1a2014-03-03 11:26:18 +110085For instance, if you are installing Go version 1.2.1 for 64-bit x86 on Linux,
86the archive you want is called <code>go1.2.1.linux-amd64.tar.gz</code>.
Andrew Gerranda7d4c3f2012-09-27 15:34:18 -070087</p>
88
89<p>
Andrew Gerrandce06e152012-03-26 13:59:30 +110090(Typically these commands must be run as root or through <code>sudo</code>.)
91</p>
Andrew Gerrande10dc822012-02-27 14:16:56 +110092
Russ Coxfb39a4d2009-10-23 15:24:08 -070093<p>
Andrew Gerrande07f0892012-02-14 17:02:28 +110094Add <code>/usr/local/go/bin</code> to the <code>PATH</code> environment
95variable. 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 Coxfb39a4d2009-10-23 15:24:08 -070097</p>
98
99<pre>
Andrew Gerrande07f0892012-02-14 17:02:28 +1100100export PATH=$PATH:/usr/local/go/bin
Russ Coxfb39a4d2009-10-23 15:24:08 -0700101</pre>
102
Oling Cat07d21952013-11-25 13:36:16 +1100103<h4 id="tarball_non_standard">Installing to a custom location</h4>
Andrew Gerrandc497c9e2013-11-21 07:55:29 +1100104
105<p>
106The Go binary distributions assume they will be installed in
107<code>/usr/local/go</code> (or <code>c:\Go</code> under Windows),
Oling Cat07d21952013-11-25 13:36:16 +1100108but it is possible to install the Go tools to a different location.
Andrew Gerrandc497c9e2013-11-21 07:55:29 +1100109In this case you must set the <code>GOROOT</code> environment variable
110to point to the directory in which it was installed.
111</p>
112
113<p>
114For example, if you installed Go to your home directory you should add the
115following commands to <code>$HOME/.profile</code>:
116</p>
117
118<pre>
119export GOROOT=$HOME/go
120export 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
125location.
126</p>
127
Andrew Gerrand218f08a2012-09-17 17:01:09 -0700128<h3 id="osx">Mac OS X package installer</h3>
Andrew Gerrande07f0892012-02-14 17:02:28 +1100129
Russ Coxfb39a4d2009-10-23 15:24:08 -0700130<p>
Matthew Dempsky6e55f7a2014-09-12 09:15:58 +1000131<a href="https://golang.org/dl/">Download the package file</a>,
Andrew Gerrandc497c9e2013-11-21 07:55:29 +1100132open it, and follow the prompts to install the Go tools.
Andrew Gerrande07f0892012-02-14 17:02:28 +1100133The package installs the Go distribution to <code>/usr/local/go</code>.
Russ Coxfb39a4d2009-10-23 15:24:08 -0700134</p>
135
Andrew Gerrande07f0892012-02-14 17:02:28 +1100136<p>
137The 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
139Terminal sessions for the change to take effect.
140</p>
Andrew Gerrand6ab8d242010-09-16 14:01:02 +1000141
Andrew Gerrande07f0892012-02-14 17:02:28 +1100142<h3 id="windows">Windows</h3>
Russ Coxfb39a4d2009-10-23 15:24:08 -0700143
144<p>
Andrew Gerrandcf460402012-03-13 15:02:14 +1100145The Go project provides two installation options for Windows users
146(besides <a href="/doc/install/source">installing from source</a>):
Andrew Gerrand1b89d512012-03-27 11:19:30 +1100147a zip archive that requires you to set some environment variables and an
Andrew Gerrandf43b6d42013-09-16 11:20:07 +1000148MSI installer that configures your installation automatically.
Andrew Gerrandcf460402012-03-13 15:02:14 +1100149</p>
150
Andrew Gerrandf43b6d42013-09-16 11:20:07 +1000151<h4 id="windows_msi">MSI installer</h4>
Andrew Gerrandcf460402012-03-13 15:02:14 +1100152
153<p>
Matthew Dempsky6e55f7a2014-09-12 09:15:58 +1000154Open the <a href="https://golang.org/dl/">MSI file</a>
Andrew Gerrandce06e152012-03-26 13:59:30 +1100155and follow the prompts to install the Go tools.
Andrew Gerrandd70627e2012-03-06 15:16:02 +1100156By default, the installer puts the Go distribution in <code>c:\Go</code>.
157</p>
158
159<p>
160The 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
162command prompts for the change to take effect.
Andrew Gerrande07f0892012-02-14 17:02:28 +1100163</p>
164
Andrew Gerrandc497c9e2013-11-21 07:55:29 +1100165<h4 id="windows_zip">Zip archive</h4>
166
167<p>
Matthew Dempsky6e55f7a2014-09-12 09:15:58 +1000168<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 Gerrandc497c9e2013-11-21 07:55:29 +1100169</p>
170
171<p>
172If you chose a directory other than <code>c:\Go</code>,
173you must set the <code>GOROOT</code> environment variable to your chosen path.
174</p>
175
176<p>
177Add 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 Gerrandcf460402012-03-13 15:02:14 +1100180<h4 id="windows_env">Setting environment variables under Windows</h4>
181
182<p>
183Under Windows, you may set environment variables through the "Environment
184Variables" button on the "Advanced" tab of the "System" control panel. Some
185versions of Windows provide this control panel through the "Advanced System
186Settings" option inside the "System" control panel.
187</p>
188
Andrew Gerrandc497c9e2013-11-21 07:55:29 +1100189
Andrew Gerrandce06e152012-03-26 13:59:30 +1100190<h2 id="testing">Test your installation</h2>
Andrew Gerrande07f0892012-02-14 17:02:28 +1100191
192<p>
193Check that Go is installed correctly by building a simple program, as follows.
194</p>
195
196<p>
197Create a file named <code>hello.go</code> and put the following program in it:
Russ Coxfb39a4d2009-10-23 15:24:08 -0700198</p>
199
200<pre>
Russ Coxfb39a4d2009-10-23 15:24:08 -0700201package main
202
203import "fmt"
204
205func main() {
Andrew Gerrande07f0892012-02-14 17:02:28 +1100206 fmt.Printf("hello, world\n")
Russ Coxfb39a4d2009-10-23 15:24:08 -0700207}
Russ Coxfb39a4d2009-10-23 15:24:08 -0700208</pre>
209
210<p>
Andrew Gerrande07f0892012-02-14 17:02:28 +1100211Then run it with the <code>go</code> tool:
Russ Coxfb39a4d2009-10-23 15:24:08 -0700212</p>
213
Andrew Gerrande07f0892012-02-14 17:02:28 +1100214<pre>
215$ go run hello.go
216hello, world
217</pre>
218
Russ Coxfb39a4d2009-10-23 15:24:08 -0700219<p>
Andrew Gerrande07f0892012-02-14 17:02:28 +1100220If you see the "hello, world" message then your Go installation is working.
Russ Coxfb39a4d2009-10-23 15:24:08 -0700221</p>
Andrew Gerrand6ab8d242010-09-16 14:01:02 +1000222
Andrew Gerrandc497c9e2013-11-21 07:55:29 +1100223
Andrew Gerrand9115a8b2012-06-13 10:33:02 +1000224<h2 id="gopath">Set up your work environment</h2>
225
226<p>
Andrew Gerrandc497c9e2013-11-21 07:55:29 +1100227You're almost done.
Andrew Gerranddc089572014-09-09 07:35:44 +1000228You just need to set up your environment.
Andrew Gerrand6ab8d242010-09-16 14:01:02 +1000229</p>
230
231<p>
Andrew Gerranddc089572014-09-09 07:35:44 +1000232Read the <a href="/doc/code.html">How to Write Go Code</a> document,
233which provides <b>essential setup instructions</b> for using the Go tools.
Russ Cox8b04cef2009-11-08 23:38:30 -0800234</p>
Andrew Gerrandf43b6d42013-09-16 11:20:07 +1000235
236
237<h2 id="uninstall">Uninstalling Go</h2>
238
239<p>
240To remove an existing Go installation from your system delete the
241<code>go</code> directory. This is usually <code>/usr/local/go</code>
242under Linux, Mac OS X, and FreeBSD or <code>c:\Go</code>
243under Windows.
244</p>
245
246<p>
247You should also remove the Go <code>bin</code> directory from your
248<code>PATH</code> environment variable.
249Under Linux and FreeBSD you should edit <code>/etc/profile</code> or
250<code>$HOME/.profile</code>.
251If you installed Go with the <a href="#osx">Mac OS X package</a> then you
252should remove the <code>/etc/paths.d/go</code> file.
253Windows users should read the section about <a href="#windows_env">setting
254environment variables under Windows</a>.
255</p>
256
257
Andrew Gerrandc497c9e2013-11-21 07:55:29 +1100258<h2 id="help">Getting help</h2>
259
260<p>
261For 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>
266The official mailing list for discussion of the Go language is
Andrew Gerrand43ad89d2014-07-25 10:28:39 +1000267<a href="//groups.google.com/group/golang-nuts">Go Nuts</a>.
Andrew Gerrandc497c9e2013-11-21 07:55:29 +1100268</p>
269
270<p>
271Report bugs using the
Andrew Gerrand43ad89d2014-07-25 10:28:39 +1000272<a href="//golang.org/issue">Go issue tracker</a>.
Andrew Gerrandc497c9e2013-11-21 07:55:29 +1100273</p>