blob: 6bff75c5a06ac60649f29be63de7fdca852562bb [file] [log] [blame]
Brent Austinba3052e2015-04-21 16:08:23 -07001<!--{
2 "Title": "Getting Started",
3 "Path": "/doc/install"
4}-->
5
Dan Willemsen09eb3b12015-09-16 14:34:17 -07006<div class="hideFromDownload">
7
Brent Austinba3052e2015-04-21 16:08:23 -07008<h2 id="download">Download the Go distribution</h2>
9
10<p>
Dan Willemsen09eb3b12015-09-16 14:34:17 -070011<a href="https://golang.org/dl/" id="start" class="download">
Brent Austinba3052e2015-04-21 16:08:23 -070012<span class="big">Download Go</span>
13<span class="desc">Click here to visit the downloads page</span>
14</a>
15</p>
16
17<p>
18<a href="https://golang.org/dl/" target="_blank">Official binary
Dan Willemsen09eb3b12015-09-16 14:34:17 -070019distributions</a> are available for the FreeBSD (release 8-STABLE and above),
Dan Willemsend4b81d32016-08-16 14:40:48 -070020Linux, Mac OS X (10.8 and above), and Windows operating systems and
Dan Willemsen09eb3b12015-09-16 14:34:17 -070021the 32-bit (<code>386</code>) and 64-bit (<code>amd64</code>) x86 processor
22architectures.
Brent Austinba3052e2015-04-21 16:08:23 -070023</p>
24
25<p>
26If a binary distribution is not available for your combination of operating
27system and architecture, try
28<a href="/doc/install/source">installing from source</a> or
29<a href="/doc/install/gccgo">installing gccgo instead of gc</a>.
30</p>
31
32
33<h2 id="requirements">System requirements</h2>
34
35<p>
Dan Willemsen09eb3b12015-09-16 14:34:17 -070036Go 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>.
Brent Austinba3052e2015-04-21 16:08:23 -070041</p>
42
43<table class="codetable" frame="border" summary="requirements">
44<tr>
45<th align="center">Operating system</th>
46<th align="center">Architectures</th>
47<th align="center">Notes</th>
48</tr>
49<tr><td colspan="3"><hr></td></tr>
Dan Willemsenebae3022017-01-13 23:01:08 -080050<tr><td>FreeBSD 8-STABLE or later</td> <td>amd64, 386</td> <td>Debian GNU/kFreeBSD not supported</td></tr>
51<tr><td>Linux 2.6.23 or later with glibc</td> <td>amd64, 386, arm, s390x, ppc64le</td> <td>CentOS/RHEL 5.x not supported</td></tr>
52<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>
Brent Austinba3052e2015-04-21 16:08:23 -070053<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>
54</table>
55
56<p>
Dan Willemsenebae3022017-01-13 23:01:08 -080057<sup>&#8224;</sup>A C compiler is required only if you plan to use
Brent Austinba3052e2015-04-21 16:08:23 -070058<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.
63</p>
64
Dan Willemsen09eb3b12015-09-16 14:34:17 -070065</div><!-- hideFromDownload -->
66
Brent Austinba3052e2015-04-21 16:08:23 -070067
68<h2 id="install">Install the Go tools</h2>
69
70<p>
71If you are upgrading from an older version of Go you must
72first <a href="#uninstall">remove the existing version</a>.
73</p>
74
Dan Willemsen09eb3b12015-09-16 14:34:17 -070075<div id="tarballInstructions">
76
Brent Austinba3052e2015-04-21 16:08:23 -070077<h3 id="tarball">Linux, Mac OS X, and FreeBSD tarballs</h3>
78
79<p>
80<a href="https://golang.org/dl/">Download the archive</a>
81and extract it into <code>/usr/local</code>, creating a Go tree in
82<code>/usr/local/go</code>. For example:
83</p>
84
85<pre>
Dan Willemsen09eb3b12015-09-16 14:34:17 -070086tar -C /usr/local -xzf <span class="downloadFilename">go$VERSION.$OS-$ARCH.tar.gz</span>
Brent Austinba3052e2015-04-21 16:08:23 -070087</pre>
88
Dan Willemsen09eb3b12015-09-16 14:34:17 -070089<p class="hideFromDownload">
Brent Austinba3052e2015-04-21 16:08:23 -070090Choose the archive file appropriate for your installation.
91For 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>.
93</p>
94
95<p>
96(Typically these commands must be run as root or through <code>sudo</code>.)
97</p>
98
99<p>
100Add <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>:
103</p>
104
105<pre>
106export PATH=$PATH:/usr/local/go/bin
107</pre>
108
109<h4 id="tarball_non_standard">Installing to a custom location</h4>
110
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),
114but it is possible to install the Go tools to a different location.
115In 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>
Dan Willemsenebae3022017-01-13 23:01:08 -0800120For example, if you installed Go to your home directory you should add
121commands like the following to <code>$HOME/.profile</code>:
Brent Austinba3052e2015-04-21 16:08:23 -0700122</p>
123
124<pre>
Dan Willemsenebae3022017-01-13 23:01:08 -0800125export GOROOT=$HOME/go1.X
Brent Austinba3052e2015-04-21 16:08:23 -0700126export 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
Dan Willemsen09eb3b12015-09-16 14:34:17 -0700134</div><!-- tarballInstructions -->
135
136<div id="darwinPackageInstructions">
137
Brent Austinba3052e2015-04-21 16:08:23 -0700138<h3 id="osx">Mac OS X package installer</h3>
139
140<p>
141<a href="https://golang.org/dl/">Download the package file</a>,
142open it, and follow the prompts to install the Go tools.
143The package installs the Go distribution to <code>/usr/local/go</code>.
144</p>
145
146<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>
151
Dan Willemsen09eb3b12015-09-16 14:34:17 -0700152</div><!-- darwinPackageInstructions -->
153
154<div id="windowsInstructions">
155
Brent Austinba3052e2015-04-21 16:08:23 -0700156<h3 id="windows">Windows</h3>
157
Dan Willemsen09eb3b12015-09-16 14:34:17 -0700158<p class="hideFromDownload">
Brent Austinba3052e2015-04-21 16:08:23 -0700159The Go project provides two installation options for Windows users
160(besides <a href="/doc/install/source">installing from source</a>):
161a zip archive that requires you to set some environment variables and an
162MSI installer that configures your installation automatically.
163</p>
164
Dan Willemsen09eb3b12015-09-16 14:34:17 -0700165<div id="windowsInstallerInstructions">
166
Brent Austinba3052e2015-04-21 16:08:23 -0700167<h4 id="windows_msi">MSI installer</h4>
168
169<p>
170Open the <a href="https://golang.org/dl/">MSI file</a>
171and follow the prompts to install the Go tools.
172By 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.
179</p>
180
Dan Willemsen09eb3b12015-09-16 14:34:17 -0700181</div><!-- windowsInstallerInstructions -->
182
183<div id="windowsZipInstructions">
184
Brent Austinba3052e2015-04-21 16:08:23 -0700185<h4 id="windows_zip">Zip archive</h4>
186
187<p>
188<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>).
189</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
Dan Willemsen09eb3b12015-09-16 14:34:17 -0700200</div><!-- windowsZipInstructions -->
201
Brent Austinba3052e2015-04-21 16:08:23 -0700202<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
Dan Willemsen09eb3b12015-09-16 14:34:17 -0700211</div><!-- windowsInstructions -->
212
Brent Austinba3052e2015-04-21 16:08:23 -0700213
214<h2 id="testing">Test your installation</h2>
215
216<p>
Dan Willemsen09eb3b12015-09-16 14:34:17 -0700217Check that Go is installed correctly by setting up a workspace
218and building a simple program, as follows.
Brent Austinba3052e2015-04-21 16:08:23 -0700219</p>
220
221<p>
Dan Willemsenebae3022017-01-13 23:01:08 -0800222Create 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,
225you will need to set the <code>GOPATH</code> environment variable;
226see <a href="code.html#Workspaces">How to Write Go Code</a> for details.)
Dan Willemsen09eb3b12015-09-16 14:34:17 -0700227</p>
228
229<p>
Dan Willemsenebae3022017-01-13 23:01:08 -0800230Next, make the directory <code>src/hello</code> inside your workspace,
231and in that directory create a file named <code>hello.go</code> that looks like:
Brent Austinba3052e2015-04-21 16:08:23 -0700232</p>
233
234<pre>
235package main
236
237import "fmt"
238
239func main() {
240 fmt.Printf("hello, world\n")
241}
242</pre>
243
244<p>
Dan Willemsenebae3022017-01-13 23:01:08 -0800245Then build it with the <code>go</code> tool:
Brent Austinba3052e2015-04-21 16:08:23 -0700246</p>
247
Dan Willemsen38f2dba2016-07-08 14:54:35 -0700248<pre class="testUnix">
Dan Willemsenebae3022017-01-13 23:01:08 -0800249$ <b>cd $HOME/go/src/hello</b>
250$ <b>go build</b>
Dan Willemsen09eb3b12015-09-16 14:34:17 -0700251</pre>
252
Dan Willemsenb57d8522017-01-19 15:07:53 -0800253<pre class="testWindows">
Dan Willemsenebae3022017-01-13 23:01:08 -0800254C:\&gt; <b>cd %USERPROFILE%\go\src\hello</b>
255C:\Users\Gopher\go\src\hello&gt; <b>go build</b>
Dan Willemsen38f2dba2016-07-08 14:54:35 -0700256</pre>
257
Dan Willemsen09eb3b12015-09-16 14:34:17 -0700258<p>
Dan Willemsenebae3022017-01-13 23:01:08 -0800259The command above will build an executable named
260<code class="testUnix">hello</code><code class="testWindows">hello.exe</code>
261in the directory alongside your source code.
262Execute it to see the greeting:
Dan Willemsen09eb3b12015-09-16 14:34:17 -0700263</p>
264
Dan Willemsen38f2dba2016-07-08 14:54:35 -0700265<pre class="testUnix">
Dan Willemsenebae3022017-01-13 23:01:08 -0800266$ <b>./hello</b>
Brent Austinba3052e2015-04-21 16:08:23 -0700267hello, world
268</pre>
269
Dan Willemsenb57d8522017-01-19 15:07:53 -0800270<pre class="testWindows">
Dan Willemsenebae3022017-01-13 23:01:08 -0800271C:\Users\Gopher\go\src\hello&gt; <b>hello</b>
Dan Willemsen38f2dba2016-07-08 14:54:35 -0700272hello, world
273</pre>
274
Brent Austinba3052e2015-04-21 16:08:23 -0700275<p>
276If you see the "hello, world" message then your Go installation is working.
277</p>
278
Brent Austinba3052e2015-04-21 16:08:23 -0700279<p>
Dan Willemsenebae3022017-01-13 23:01:08 -0800280You can run <code>go</code> <code>install</code> to install the binary into
281your workspace's <code>bin</code> directory
282or <code>go</code> <code>clean</code> to remove it.
283</p>
284
285<p>
Dan Willemsen09eb3b12015-09-16 14:34:17 -0700286Before rushing off to write Go code please read the
287<a href="/doc/code.html">How to Write Go Code</a> document,
288which describes some essential concepts about using the Go tools.
Brent Austinba3052e2015-04-21 16:08:23 -0700289</p>
290
291
292<h2 id="uninstall">Uninstalling Go</h2>
293
294<p>
295To remove an existing Go installation from your system delete the
296<code>go</code> directory. This is usually <code>/usr/local/go</code>
297under Linux, Mac OS X, and FreeBSD or <code>c:\Go</code>
298under Windows.
299</p>
300
301<p>
302You should also remove the Go <code>bin</code> directory from your
303<code>PATH</code> environment variable.
304Under Linux and FreeBSD you should edit <code>/etc/profile</code> or
305<code>$HOME/.profile</code>.
306If you installed Go with the <a href="#osx">Mac OS X package</a> then you
307should remove the <code>/etc/paths.d/go</code> file.
308Windows users should read the section about <a href="#windows_env">setting
309environment variables under Windows</a>.
310</p>
311
312
313<h2 id="help">Getting help</h2>
314
315<p>
Dan Willemsenebae3022017-01-13 23:01:08 -0800316 For help, see the <a href="/help/">list of Go mailing lists, forums, and places to chat</a>.
Brent Austinba3052e2015-04-21 16:08:23 -0700317</p>
318
319<p>
Dan Willemsenebae3022017-01-13 23:01:08 -0800320 Report bugs either by running “<b><code>go</code> <code>bug</code></b>”, or
321 manually at the <a href="https://golang.org/issue">Go issue tracker</a>.
Brent Austinba3052e2015-04-21 16:08:23 -0700322</p>