blob: 1305c970e31375d9c027a36d4978636ab0d998fc [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 Gerrand31b0b732015-08-05 11:58:44 +10006<div class="hideFromDownload">
7
Andrew Gerrand062a86b2013-04-03 15:59:17 +11008<h2 id="download">Download the Go distribution</h2>
Russ Coxfb39a4d2009-10-23 15:24:08 -07009
10<p>
Andrew Gerrand31b0b732015-08-05 11:58:44 +100011<a href="https://golang.org/dl/" id="start" class="download">
Andrew Gerrand062a86b2013-04-03 15:59:17 +110012<span class="big">Download Go</span>
13<span class="desc">Click here to visit the downloads page</span>
14</a>
Russ Coxfb39a4d2009-10-23 15:24:08 -070015</p>
16
Rob Pike5f50a812009-11-05 15:07:42 -080017<p>
Matthew Dempsky6e55f7a2014-09-12 09:15:58 +100018<a href="https://golang.org/dl/" target="_blank">Official binary
Bill Thiedee9ce76b2015-01-17 21:09:15 -080019distributions</a> are available for the FreeBSD (release 8-STABLE and above),
Brad Fitzpatrick219ca602016-08-06 10:12:03 -070020Linux, Mac OS X (10.8 and above), and Windows operating systems and
Bill Thiedee9ce76b2015-01-17 21:09:15 -080021the 32-bit (<code>386</code>) and 64-bit (<code>amd64</code>) x86 processor
22architectures.
Andrew Gerrand062a86b2013-04-03 15:59:17 +110023</p>
24
25<p>
26If a binary distribution is not available for your combination of operating
Andrew Gerrandc497c9e2013-11-21 07:55:29 +110027system and architecture, try
Andrew Gerrand062a86b2013-04-03 15:59:17 +110028<a href="/doc/install/source">installing from source</a> or
29<a href="/doc/install/gccgo">installing gccgo instead of gc</a>.
Rob Pike5f50a812009-11-05 15:07:42 -080030</p>
31
Andrew Gerrandc497c9e2013-11-21 07:55:29 +110032
Shenghou Maab708e32012-05-16 14:54:48 +100033<h2 id="requirements">System requirements</h2>
Andrew Gerrandc497c9e2013-11-21 07:55:29 +110034
Shenghou Maab708e32012-05-16 14:54:48 +100035<p>
Russ Cox54575632015-08-18 11:15:15 -040036Go binary distributions are available for these supported operating systems and architectures.
37Please ensure your system meets these requirements before proceeding.
38If your OS or architecture is not on the list, you may be able to
39<a href="/doc/install/source">install from source</a> or
40<a href="/doc/install/gccgo">use gccgo instead</a>.
Shenghou Maab708e32012-05-16 14:54:48 +100041</p>
42
43<table class="codetable" frame="border" summary="requirements">
44<tr>
Rob Pike761dace2014-06-10 11:19:41 -070045<th align="center">Operating system</th>
46<th align="center">Architectures</th>
47<th align="center">Notes</th>
Shenghou Maab708e32012-05-16 14:54:48 +100048</tr>
49<tr><td colspan="3"><hr></td></tr>
Russ Cox54575632015-08-18 11:15:15 -040050<tr><td>FreeBSD 8-STABLE or later</td> <td>amd64</td> <td>Debian GNU/kFreeBSD not supported</td></tr>
Russ Cox73ba8462016-01-06 15:47:47 -050051<tr><td>Linux 2.6.23 or later with glibc</td> <td>amd64, 386, arm</td> <td>CentOS/RHEL 5.x not supported</td></tr>
Brad Fitzpatrickcfea2602016-09-09 05:26:20 +000052<tr><td>Mac OS X 10.8 or later</td> <td>amd64</td> <td>use the clang or gcc<sup>&#8224;</sup> that comes with Xcode<sup>&#8225;</sup> for <code>cgo</code> support</td></tr>
Yasuhiro Matsumoto59439f82014-11-14 14:05:14 +110053<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 +100054</table>
55
56<p>
Brad Fitzpatrick0ab6bb42016-09-09 01:30:49 +000057<sup>&#8224;</sup>A C compiler is required only if you plan to use
Shenghou Ma27010462012-08-20 21:21:09 +080058<a href="/cmd/cgo">cgo</a>.<br/>
59<sup>&#8225;</sup>You only need to install the command line tools for
60<a href="http://developer.apple.com/Xcode/">Xcode</a>. If you have already
61installed Xcode 4.3+, you can install it from the Components tab of the
62Downloads preferences panel.
Shenghou Maab708e32012-05-16 14:54:48 +100063</p>
64
Andrew Gerrand31b0b732015-08-05 11:58:44 +100065</div><!-- hideFromDownload -->
66
Andrew Gerrandc497c9e2013-11-21 07:55:29 +110067
Andrew Gerrandce06e152012-03-26 13:59:30 +110068<h2 id="install">Install the Go tools</h2>
Russ Coxfb39a4d2009-10-23 15:24:08 -070069
70<p>
Andrew Gerrand218f08a2012-09-17 17:01:09 -070071If you are upgrading from an older version of Go you must
Andrew Gerrandf43b6d42013-09-16 11:20:07 +100072first <a href="#uninstall">remove the existing version</a>.
Andrew Gerrandc497c9e2013-11-21 07:55:29 +110073</p>
74
Andrew Gerrand31b0b732015-08-05 11:58:44 +100075<div id="tarballInstructions">
76
Andrew Gerrandc497c9e2013-11-21 07:55:29 +110077<h3 id="tarball">Linux, Mac OS X, and FreeBSD tarballs</h3>
Andrew Gerrande10dc822012-02-27 14:16:56 +110078
79<p>
Matthew Dempsky6e55f7a2014-09-12 09:15:58 +100080<a href="https://golang.org/dl/">Download the archive</a>
Andrew Gerrandc497c9e2013-11-21 07:55:29 +110081and extract it into <code>/usr/local</code>, creating a Go tree in
82<code>/usr/local/go</code>. For example:
Russ Coxfb39a4d2009-10-23 15:24:08 -070083</p>
84
85<pre>
Andrew Gerrand31b0b732015-08-05 11:58:44 +100086tar -C /usr/local -xzf <span class="downloadFilename">go$VERSION.$OS-$ARCH.tar.gz</span>
Russ Coxfb39a4d2009-10-23 15:24:08 -070087</pre>
88
Andrew Gerrand31b0b732015-08-05 11:58:44 +100089<p class="hideFromDownload">
Shenghou Ma2b6eb112014-02-06 16:09:01 -050090Choose the archive file appropriate for your installation.
Andrew Gerrand77edde1a2014-03-03 11:26:18 +110091For instance, if you are installing Go version 1.2.1 for 64-bit x86 on Linux,
92the archive you want is called <code>go1.2.1.linux-amd64.tar.gz</code>.
Andrew Gerranda7d4c3f2012-09-27 15:34:18 -070093</p>
94
95<p>
Andrew Gerrandce06e152012-03-26 13:59:30 +110096(Typically these commands must be run as root or through <code>sudo</code>.)
97</p>
Andrew Gerrande10dc822012-02-27 14:16:56 +110098
Russ Coxfb39a4d2009-10-23 15:24:08 -070099<p>
Andrew Gerrande07f0892012-02-14 17:02:28 +1100100Add <code>/usr/local/go/bin</code> to the <code>PATH</code> environment
101variable. You can do this by adding this line to your <code>/etc/profile</code>
102(for a system-wide installation) or <code>$HOME/.profile</code>:
Russ Coxfb39a4d2009-10-23 15:24:08 -0700103</p>
104
105<pre>
Andrew Gerrande07f0892012-02-14 17:02:28 +1100106export PATH=$PATH:/usr/local/go/bin
Russ Coxfb39a4d2009-10-23 15:24:08 -0700107</pre>
108
Oling Cat07d21952013-11-25 13:36:16 +1100109<h4 id="tarball_non_standard">Installing to a custom location</h4>
Andrew Gerrandc497c9e2013-11-21 07:55:29 +1100110
111<p>
112The Go binary distributions assume they will be installed in
113<code>/usr/local/go</code> (or <code>c:\Go</code> under Windows),
Oling Cat07d21952013-11-25 13:36:16 +1100114but it is possible to install the Go tools to a different location.
Andrew Gerrandc497c9e2013-11-21 07:55:29 +1100115In this case you must set the <code>GOROOT</code> environment variable
116to point to the directory in which it was installed.
117</p>
118
119<p>
120For example, if you installed Go to your home directory you should add the
121following commands to <code>$HOME/.profile</code>:
122</p>
123
124<pre>
125export GOROOT=$HOME/go
126export PATH=$PATH:$GOROOT/bin
127</pre>
128
129<p>
130<b>Note</b>: <code>GOROOT</code> must be set only when installing to a custom
131location.
132</p>
133
Andrew Gerrand31b0b732015-08-05 11:58:44 +1000134</div><!-- tarballInstructions -->
135
136<div id="darwinPackageInstructions">
137
Andrew Gerrand218f08a2012-09-17 17:01:09 -0700138<h3 id="osx">Mac OS X package installer</h3>
Andrew Gerrande07f0892012-02-14 17:02:28 +1100139
Russ Coxfb39a4d2009-10-23 15:24:08 -0700140<p>
Matthew Dempsky6e55f7a2014-09-12 09:15:58 +1000141<a href="https://golang.org/dl/">Download the package file</a>,
Andrew Gerrandc497c9e2013-11-21 07:55:29 +1100142open it, and follow the prompts to install the Go tools.
Andrew Gerrande07f0892012-02-14 17:02:28 +1100143The package installs the Go distribution to <code>/usr/local/go</code>.
Russ Coxfb39a4d2009-10-23 15:24:08 -0700144</p>
145
Andrew Gerrande07f0892012-02-14 17:02:28 +1100146<p>
147The package should put the <code>/usr/local/go/bin</code> directory in your
148<code>PATH</code> environment variable. You may need to restart any open
149Terminal sessions for the change to take effect.
150</p>
Andrew Gerrand6ab8d242010-09-16 14:01:02 +1000151
Andrew Gerrand31b0b732015-08-05 11:58:44 +1000152</div><!-- darwinPackageInstructions -->
153
154<div id="windowsInstructions">
155
Andrew Gerrande07f0892012-02-14 17:02:28 +1100156<h3 id="windows">Windows</h3>
Russ Coxfb39a4d2009-10-23 15:24:08 -0700157
Andrew Gerrand31b0b732015-08-05 11:58:44 +1000158<p class="hideFromDownload">
Andrew Gerrandcf460402012-03-13 15:02:14 +1100159The Go project provides two installation options for Windows users
160(besides <a href="/doc/install/source">installing from source</a>):
Andrew Gerrand1b89d512012-03-27 11:19:30 +1100161a zip archive that requires you to set some environment variables and an
Andrew Gerrandf43b6d42013-09-16 11:20:07 +1000162MSI installer that configures your installation automatically.
Andrew Gerrandcf460402012-03-13 15:02:14 +1100163</p>
164
Andrew Gerrand31b0b732015-08-05 11:58:44 +1000165<div id="windowsInstallerInstructions">
166
Andrew Gerrandf43b6d42013-09-16 11:20:07 +1000167<h4 id="windows_msi">MSI installer</h4>
Andrew Gerrandcf460402012-03-13 15:02:14 +1100168
169<p>
Matthew Dempsky6e55f7a2014-09-12 09:15:58 +1000170Open the <a href="https://golang.org/dl/">MSI file</a>
Andrew Gerrandce06e152012-03-26 13:59:30 +1100171and follow the prompts to install the Go tools.
Andrew Gerrandd70627e2012-03-06 15:16:02 +1100172By default, the installer puts the Go distribution in <code>c:\Go</code>.
173</p>
174
175<p>
176The installer should put the <code>c:\Go\bin</code> directory in your
177<code>PATH</code> environment variable. You may need to restart any open
178command prompts for the change to take effect.
Andrew Gerrande07f0892012-02-14 17:02:28 +1100179</p>
180
Andrew Gerrand31b0b732015-08-05 11:58:44 +1000181</div><!-- windowsInstallerInstructions -->
182
183<div id="windowsZipInstructions">
184
Andrew Gerrandc497c9e2013-11-21 07:55:29 +1100185<h4 id="windows_zip">Zip archive</h4>
186
187<p>
Matthew Dempsky6e55f7a2014-09-12 09:15:58 +1000188<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 +1100189</p>
190
191<p>
192If you chose a directory other than <code>c:\Go</code>,
193you must set the <code>GOROOT</code> environment variable to your chosen path.
194</p>
195
196<p>
197Add the <code>bin</code> subdirectory of your Go root (for example, <code>c:\Go\bin</code>) to your <code>PATH</code> environment variable.
198</p>
199
Andrew Gerrand31b0b732015-08-05 11:58:44 +1000200</div><!-- windowsZipInstructions -->
201
Andrew Gerrandcf460402012-03-13 15:02:14 +1100202<h4 id="windows_env">Setting environment variables under Windows</h4>
203
204<p>
205Under Windows, you may set environment variables through the "Environment
206Variables" button on the "Advanced" tab of the "System" control panel. Some
207versions of Windows provide this control panel through the "Advanced System
208Settings" option inside the "System" control panel.
209</p>
210
Andrew Gerrand31b0b732015-08-05 11:58:44 +1000211</div><!-- windowsInstructions -->
212
Andrew Gerrandc497c9e2013-11-21 07:55:29 +1100213
Andrew Gerrandce06e152012-03-26 13:59:30 +1100214<h2 id="testing">Test your installation</h2>
Andrew Gerrande07f0892012-02-14 17:02:28 +1100215
216<p>
Andrew Gerrand31b0b732015-08-05 11:58:44 +1000217Check that Go is installed correctly by setting up a workspace
218and building a simple program, as follows.
Andrew Gerrande07f0892012-02-14 17:02:28 +1100219</p>
220
221<p>
Andrew Gerrand31b0b732015-08-05 11:58:44 +1000222Create a directory to contain your <a href="code.html#Workspaces">workspace</a>,
Andrew Gerrande9fc5222016-01-07 10:53:07 +1100223<code class="testUnix">$HOME/work</code>
Andrew Gerrand81a89602016-05-10 11:48:48 -0700224<code class="testWindows" style="display: none">C:\work</code>
Andrew Gerrande9fc5222016-01-07 10:53:07 +1100225for example, and set the <code>GOPATH</code> environment
Andrew Gerrand31b0b732015-08-05 11:58:44 +1000226variable to point to that location.
227</p>
228
Andrew Gerrande9fc5222016-01-07 10:53:07 +1100229<pre class="testUnix">
Andrew Gerrand31b0b732015-08-05 11:58:44 +1000230$ <b>export GOPATH=$HOME/work</b>
231</pre>
232
Andrew Gerrande9fc5222016-01-07 10:53:07 +1100233<pre class="testWindows" style="display: none">
Andrew Gerrand81a89602016-05-10 11:48:48 -0700234C:\&gt; <b>set GOPATH=C:\work</b>
Andrew Gerrande9fc5222016-01-07 10:53:07 +1100235</pre>
236
Andrew Gerrand31b0b732015-08-05 11:58:44 +1000237<p>
Andrew Gerrande9fc5222016-01-07 10:53:07 +1100238<span class="testUnix">
Andrew Gerrand31b0b732015-08-05 11:58:44 +1000239You should put the above command in your shell startup script
Andrew Gerrande9fc5222016-01-07 10:53:07 +1100240(<code>$HOME/.profile</code> for example).
241</span>
242<span class="testWindows">
243On Windows, follow the <a href="#windows_env">instructions above</a> to set the
Andrew Gerrand31b0b732015-08-05 11:58:44 +1000244<code>GOPATH</code> environment variable on your system.
Andrew Gerrande9fc5222016-01-07 10:53:07 +1100245</span>
Andrew Gerrand31b0b732015-08-05 11:58:44 +1000246</p>
247
248<p>
249Next, make the directories <code>src/github.com/user/hello</code> inside your
250workspace (if you use GitHub, substitute your user name for <code>user</code>),
251and inside the <code>hello</code> directory create a file named <code>hello.go</code>
252with the following contents:
Russ Coxfb39a4d2009-10-23 15:24:08 -0700253</p>
254
255<pre>
Russ Coxfb39a4d2009-10-23 15:24:08 -0700256package main
257
258import "fmt"
259
260func main() {
Andrew Gerrande07f0892012-02-14 17:02:28 +1100261 fmt.Printf("hello, world\n")
Russ Coxfb39a4d2009-10-23 15:24:08 -0700262}
Russ Coxfb39a4d2009-10-23 15:24:08 -0700263</pre>
264
265<p>
Andrew Gerrand31b0b732015-08-05 11:58:44 +1000266Then compile it with the <code>go</code> tool:
Russ Coxfb39a4d2009-10-23 15:24:08 -0700267</p>
268
Andrew Gerrande9fc5222016-01-07 10:53:07 +1100269<pre class="testUnix">
Andrew Gerrand31b0b732015-08-05 11:58:44 +1000270$ <b>go install github.com/user/hello</b>
271</pre>
272
Andrew Gerrande9fc5222016-01-07 10:53:07 +1100273<pre class="testWindows" style="display: none">
274C:\&gt; <b>go install github.com/user/hello</b>
275</pre>
276
Andrew Gerrand31b0b732015-08-05 11:58:44 +1000277<p>
Andrew Gerrande9fc5222016-01-07 10:53:07 +1100278The command above will put an executable command named <code>hello</code>
Andrew Gerrand31b0b732015-08-05 11:58:44 +1000279(or <code>hello.exe</code>) inside the <code>bin</code> directory of your workspace.
280Execute the command to see the greeting:
281</p>
282
Andrew Gerrande9fc5222016-01-07 10:53:07 +1100283<pre class="testUnix">
Andrew Gerrand31b0b732015-08-05 11:58:44 +1000284$ <b>$GOPATH/bin/hello</b>
Andrew Gerrande07f0892012-02-14 17:02:28 +1100285hello, world
286</pre>
287
Andrew Gerrande9fc5222016-01-07 10:53:07 +1100288<pre class="testWindows" style="display: none">
289C:\&gt; <b>%GOPATH%\bin\hello</b>
290hello, world
291</pre>
292
Russ Coxfb39a4d2009-10-23 15:24:08 -0700293<p>
Andrew Gerrande07f0892012-02-14 17:02:28 +1100294If you see the "hello, world" message then your Go installation is working.
Russ Coxfb39a4d2009-10-23 15:24:08 -0700295</p>
Andrew Gerrand6ab8d242010-09-16 14:01:02 +1000296
Andrew Gerrand9115a8b2012-06-13 10:33:02 +1000297<p>
Andrew Gerrand31b0b732015-08-05 11:58:44 +1000298Before rushing off to write Go code please read the
299<a href="/doc/code.html">How to Write Go Code</a> document,
300which describes some essential concepts about using the Go tools.
Russ Cox8b04cef2009-11-08 23:38:30 -0800301</p>
Andrew Gerrandf43b6d42013-09-16 11:20:07 +1000302
303
304<h2 id="uninstall">Uninstalling Go</h2>
305
306<p>
307To remove an existing Go installation from your system delete the
308<code>go</code> directory. This is usually <code>/usr/local/go</code>
309under Linux, Mac OS X, and FreeBSD or <code>c:\Go</code>
310under Windows.
311</p>
312
313<p>
314You should also remove the Go <code>bin</code> directory from your
315<code>PATH</code> environment variable.
316Under Linux and FreeBSD you should edit <code>/etc/profile</code> or
317<code>$HOME/.profile</code>.
318If you installed Go with the <a href="#osx">Mac OS X package</a> then you
319should remove the <code>/etc/paths.d/go</code> file.
320Windows users should read the section about <a href="#windows_env">setting
321environment variables under Windows</a>.
322</p>
323
324
Andrew Gerrandc497c9e2013-11-21 07:55:29 +1100325<h2 id="help">Getting help</h2>
326
327<p>
328For real-time help, ask the helpful gophers in <code>#go-nuts</code> on the
329<a href="http://freenode.net/">Freenode</a> IRC server.
330</p>
331
332<p>
333The official mailing list for discussion of the Go language is
Andrew Gerrand43ad89d2014-07-25 10:28:39 +1000334<a href="//groups.google.com/group/golang-nuts">Go Nuts</a>.
Andrew Gerrandc497c9e2013-11-21 07:55:29 +1100335</p>
336
337<p>
338Report bugs using the
Andrew Gerrand43ad89d2014-07-25 10:28:39 +1000339<a href="//golang.org/issue">Go issue tracker</a>.
Andrew Gerrandc497c9e2013-11-21 07:55:29 +1100340</p>