blob: f17dce5bdd4c82e800e82abc21bd9e5ea045740d [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 Bonventre3810f5b2018-01-19 22:47:23 -050011<a href="/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>
Andrew Bonventre3810f5b2018-01-19 22:47:23 -050018<a href="/dl/" target="_blank">Official binary
Mikio Harae76ae8a2017-08-19 13:46:48 +090019distributions</a> are available for the FreeBSD (release 10-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>
Andrew Bonventre3810f5b2018-01-19 22:47:23 -050036Go <a href="/dl/">binary distributions</a> are available for these supported operating systems and architectures.
Russ Cox54575632015-08-18 11:15:15 -040037Please 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>
Mikio Harae76ae8a2017-08-19 13:46:48 +090050<tr><td>FreeBSD 10.3 or later</td> <td>amd64, 386</td> <td>Debian GNU/kFreeBSD not supported</td></tr>
Brad Fitzpatrick25de52e2017-06-29 19:44:07 +000051<tr valign='top'><td>Linux 2.6.23 or later with glibc</td> <td>amd64, 386, arm, arm64,<br>s390x, ppc64le</td> <td>CentOS/RHEL 5.x not supported.<br>Install from source for other libc.</td></tr>
52<tr><td>macOS 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>
53<tr><td>Windows XP SP2 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>
Andrew Bonventre3810f5b2018-01-19 22:47:23 -050080<a href="/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>
Russ Cox74628a82016-11-30 14:56:58 -0500120For example, if you installed Go to your home directory you should add
121commands like the following to <code>$HOME/.profile</code>:
Andrew Gerrandc497c9e2013-11-21 07:55:29 +1100122</p>
123
124<pre>
Russ Cox74628a82016-11-30 14:56:58 -0500125export GOROOT=$HOME/go1.X
Andrew Gerrandc497c9e2013-11-21 07:55:29 +1100126export 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>
Andrew Bonventre3810f5b2018-01-19 22:47:23 -0500141<a href="/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>
Andrew Bonventre3810f5b2018-01-19 22:47:23 -0500170Open the <a href="/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>
Andrew Bonventre3810f5b2018-01-19 22:47:23 -0500188<a href="/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>
Russ Cox74628a82016-11-30 14:56:58 -0500222Create your <a href="code.html#Workspaces">workspace</a> directory,
223<code class="testUnix">$HOME/go</code><code class="testWindows">%USERPROFILE%\go</code>.
224(If you'd like to use a different directory,
Jaana Burcu Doganecbf9082017-02-02 11:39:02 -0800225you will need to <a href="https://golang.org/wiki/SettingGOPATH">set the <code>GOPATH</code> environment variable</a>.)
Andrew Gerrand31b0b732015-08-05 11:58:44 +1000226</p>
227
228<p>
Russ Cox74628a82016-11-30 14:56:58 -0500229Next, make the directory <code>src/hello</code> inside your workspace,
230and in that directory create a file named <code>hello.go</code> that looks like:
Russ Coxfb39a4d2009-10-23 15:24:08 -0700231</p>
232
233<pre>
Russ Coxfb39a4d2009-10-23 15:24:08 -0700234package main
235
236import "fmt"
237
238func main() {
Andrew Gerrande07f0892012-02-14 17:02:28 +1100239 fmt.Printf("hello, world\n")
Russ Coxfb39a4d2009-10-23 15:24:08 -0700240}
Russ Coxfb39a4d2009-10-23 15:24:08 -0700241</pre>
242
243<p>
Russ Cox74628a82016-11-30 14:56:58 -0500244Then build it with the <code>go</code> tool:
Russ Coxfb39a4d2009-10-23 15:24:08 -0700245</p>
246
Andrew Gerrande9fc5222016-01-07 10:53:07 +1100247<pre class="testUnix">
Brad Fitzpatrickd51046b2016-12-21 20:48:09 +0000248$ <b>cd $HOME/go/src/hello</b>
Russ Cox74628a82016-11-30 14:56:58 -0500249$ <b>go build</b>
Andrew Gerrand31b0b732015-08-05 11:58:44 +1000250</pre>
251
Jaana Burcu Doganb842c9a2017-01-10 11:25:14 -0800252<pre class="testWindows">
Brad Fitzpatrickd51046b2016-12-21 20:48:09 +0000253C:\&gt; <b>cd %USERPROFILE%\go\src\hello</b>
Russ Cox74628a82016-11-30 14:56:58 -0500254C:\Users\Gopher\go\src\hello&gt; <b>go build</b>
Andrew Gerrande9fc5222016-01-07 10:53:07 +1100255</pre>
256
Andrew Gerrand31b0b732015-08-05 11:58:44 +1000257<p>
Russ Cox74628a82016-11-30 14:56:58 -0500258The command above will build an executable named
259<code class="testUnix">hello</code><code class="testWindows">hello.exe</code>
260in the directory alongside your source code.
261Execute it to see the greeting:
Andrew Gerrand31b0b732015-08-05 11:58:44 +1000262</p>
263
Andrew Gerrande9fc5222016-01-07 10:53:07 +1100264<pre class="testUnix">
Russ Cox74628a82016-11-30 14:56:58 -0500265$ <b>./hello</b>
Andrew Gerrande07f0892012-02-14 17:02:28 +1100266hello, world
267</pre>
268
Jaana Burcu Doganb842c9a2017-01-10 11:25:14 -0800269<pre class="testWindows">
Russ Cox74628a82016-11-30 14:56:58 -0500270C:\Users\Gopher\go\src\hello&gt; <b>hello</b>
Andrew Gerrande9fc5222016-01-07 10:53:07 +1100271hello, world
272</pre>
273
Russ Coxfb39a4d2009-10-23 15:24:08 -0700274<p>
Andrew Gerrande07f0892012-02-14 17:02:28 +1100275If you see the "hello, world" message then your Go installation is working.
Russ Coxfb39a4d2009-10-23 15:24:08 -0700276</p>
Andrew Gerrand6ab8d242010-09-16 14:01:02 +1000277
Andrew Gerrand9115a8b2012-06-13 10:33:02 +1000278<p>
Russ Cox74628a82016-11-30 14:56:58 -0500279You can run <code>go</code> <code>install</code> to install the binary into
280your workspace's <code>bin</code> directory
281or <code>go</code> <code>clean</code> to remove it.
282</p>
283
284<p>
Andrew Gerrand31b0b732015-08-05 11:58:44 +1000285Before rushing off to write Go code please read the
286<a href="/doc/code.html">How to Write Go Code</a> document,
287which describes some essential concepts about using the Go tools.
Russ Cox8b04cef2009-11-08 23:38:30 -0800288</p>
Andrew Gerrandf43b6d42013-09-16 11:20:07 +1000289
290
291<h2 id="uninstall">Uninstalling Go</h2>
292
293<p>
294To remove an existing Go installation from your system delete the
295<code>go</code> directory. This is usually <code>/usr/local/go</code>
296under Linux, Mac OS X, and FreeBSD or <code>c:\Go</code>
297under Windows.
298</p>
299
300<p>
301You should also remove the Go <code>bin</code> directory from your
302<code>PATH</code> environment variable.
303Under Linux and FreeBSD you should edit <code>/etc/profile</code> or
304<code>$HOME/.profile</code>.
305If you installed Go with the <a href="#osx">Mac OS X package</a> then you
306should remove the <code>/etc/paths.d/go</code> file.
307Windows users should read the section about <a href="#windows_env">setting
308environment variables under Windows</a>.
309</p>
310
311
Andrew Gerrandc497c9e2013-11-21 07:55:29 +1100312<h2 id="help">Getting help</h2>
313
314<p>
Brad Fitzpatrickd51046b2016-12-21 20:48:09 +0000315 For help, see the <a href="/help/">list of Go mailing lists, forums, and places to chat</a>.
Andrew Gerrandc497c9e2013-11-21 07:55:29 +1100316</p>
317
318<p>
Brad Fitzpatrickd51046b2016-12-21 20:48:09 +0000319 Report bugs either by running “<b><code>go</code> <code>bug</code></b>”, or
320 manually at the <a href="https://golang.org/issue">Go issue tracker</a>.
Andrew Gerrandc497c9e2013-11-21 07:55:29 +1100321</p>