blob: a41c60ba6c8b205f1e763f9a9f3bebf7951933ba [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 Willemsena3223282018-02-27 19:41:43 -080011<a href="/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>
Dan Willemsena3223282018-02-27 19:41:43 -080018<a href="/dl/" target="_blank">Official binary
19distributions</a> are available for the FreeBSD (release 10-STABLE and above),
Dan Willemsenc7413322018-08-27 23:21:26 -070020Linux, macOS (10.10 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 Willemsena3223282018-02-27 19:41:43 -080036Go <a href="/dl/">binary distributions</a> are available for these supported operating systems and architectures.
Dan Willemsen09eb3b12015-09-16 14:34:17 -070037Please 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 Willemsena3223282018-02-27 19:41:43 -080050<tr><td>FreeBSD 10.3 or later</td> <td>amd64, 386</td> <td>Debian GNU/kFreeBSD not supported</td></tr>
Dan Willemsend2797482017-07-26 13:13:13 -070051<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>
Dan Willemsenc7413322018-08-27 23:21:26 -070052<tr><td>macOS 10.10 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 7, Server 2008R2 or later</td> <td>amd64, 386</td> <td>use MinGW gcc<sup>&#8224;</sup>. No need for cygwin or msys.</td></tr>
Brent Austinba3052e2015-04-21 16:08:23 -070054</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
Dan Willemsenc7413322018-08-27 23:21:26 -070060<a href="https://developer.apple.com/Xcode/">Xcode</a>. If you have already
Brent Austinba3052e2015-04-21 16:08:23 -070061installed 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
Dan Willemsenc7413322018-08-27 23:21:26 -070077<h3 id="tarball">Linux, macOS, and FreeBSD tarballs</h3>
Brent Austinba3052e2015-04-21 16:08:23 -070078
79<p>
Dan Willemsena3223282018-02-27 19:41:43 -080080<a href="/dl/">Download the archive</a>
Brent Austinba3052e2015-04-21 16:08:23 -070081and 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
Brent Austinba3052e2015-04-21 16:08:23 -0700109<p>
Dan Willemsenc7413322018-08-27 23:21:26 -0700110<b>Note</b>: changes made to a <code>profile</code> file may not apply until the
111next time you log into your computer.
112To apply the changes immediately, just run the shell commands directly
113or execute them from the profile using a command such as
114<code>source $HOME/.profile</code>.
Brent Austinba3052e2015-04-21 16:08:23 -0700115</p>
116
Dan Willemsen09eb3b12015-09-16 14:34:17 -0700117</div><!-- tarballInstructions -->
118
119<div id="darwinPackageInstructions">
120
Dan Willemsenc7413322018-08-27 23:21:26 -0700121<h3 id="macos"><div id="osx"></div>macOS package installer</h3>
Brent Austinba3052e2015-04-21 16:08:23 -0700122
123<p>
Dan Willemsena3223282018-02-27 19:41:43 -0800124<a href="/dl/">Download the package file</a>,
Brent Austinba3052e2015-04-21 16:08:23 -0700125open it, and follow the prompts to install the Go tools.
126The package installs the Go distribution to <code>/usr/local/go</code>.
127</p>
128
129<p>
130The package should put the <code>/usr/local/go/bin</code> directory in your
131<code>PATH</code> environment variable. You may need to restart any open
132Terminal sessions for the change to take effect.
133</p>
134
Dan Willemsen09eb3b12015-09-16 14:34:17 -0700135</div><!-- darwinPackageInstructions -->
136
137<div id="windowsInstructions">
138
Brent Austinba3052e2015-04-21 16:08:23 -0700139<h3 id="windows">Windows</h3>
140
Dan Willemsen09eb3b12015-09-16 14:34:17 -0700141<p class="hideFromDownload">
Brent Austinba3052e2015-04-21 16:08:23 -0700142The Go project provides two installation options for Windows users
143(besides <a href="/doc/install/source">installing from source</a>):
144a zip archive that requires you to set some environment variables and an
145MSI installer that configures your installation automatically.
146</p>
147
Dan Willemsen09eb3b12015-09-16 14:34:17 -0700148<div id="windowsInstallerInstructions">
149
Brent Austinba3052e2015-04-21 16:08:23 -0700150<h4 id="windows_msi">MSI installer</h4>
151
152<p>
Dan Willemsena3223282018-02-27 19:41:43 -0800153Open the <a href="/dl/">MSI file</a>
Brent Austinba3052e2015-04-21 16:08:23 -0700154and follow the prompts to install the Go tools.
155By default, the installer puts the Go distribution in <code>c:\Go</code>.
156</p>
157
158<p>
159The installer should put the <code>c:\Go\bin</code> directory in your
160<code>PATH</code> environment variable. You may need to restart any open
161command prompts for the change to take effect.
162</p>
163
Dan Willemsen09eb3b12015-09-16 14:34:17 -0700164</div><!-- windowsInstallerInstructions -->
165
166<div id="windowsZipInstructions">
167
Brent Austinba3052e2015-04-21 16:08:23 -0700168<h4 id="windows_zip">Zip archive</h4>
169
170<p>
Dan Willemsena3223282018-02-27 19:41:43 -0800171<a href="/dl/">Download the zip file</a> and extract it into the directory of your choice (we suggest <code>c:\Go</code>).
Brent Austinba3052e2015-04-21 16:08:23 -0700172</p>
173
174<p>
Brent Austinba3052e2015-04-21 16:08:23 -0700175Add the <code>bin</code> subdirectory of your Go root (for example, <code>c:\Go\bin</code>) to your <code>PATH</code> environment variable.
176</p>
177
Dan Willemsen09eb3b12015-09-16 14:34:17 -0700178</div><!-- windowsZipInstructions -->
179
Brent Austinba3052e2015-04-21 16:08:23 -0700180<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
Dan Willemsen09eb3b12015-09-16 14:34:17 -0700189</div><!-- windowsInstructions -->
190
Brent Austinba3052e2015-04-21 16:08:23 -0700191
192<h2 id="testing">Test your installation</h2>
193
194<p>
Dan Willemsen09eb3b12015-09-16 14:34:17 -0700195Check that Go is installed correctly by setting up a workspace
196and building a simple program, as follows.
Brent Austinba3052e2015-04-21 16:08:23 -0700197</p>
198
199<p>
Dan Willemsenebae3022017-01-13 23:01:08 -0800200Create your <a href="code.html#Workspaces">workspace</a> directory,
201<code class="testUnix">$HOME/go</code><code class="testWindows">%USERPROFILE%\go</code>.
202(If you'd like to use a different directory,
Dan Willemsend2797482017-07-26 13:13:13 -0700203you will need to <a href="https://golang.org/wiki/SettingGOPATH">set the <code>GOPATH</code> environment variable</a>.)
Dan Willemsen09eb3b12015-09-16 14:34:17 -0700204</p>
205
206<p>
Dan Willemsenebae3022017-01-13 23:01:08 -0800207Next, make the directory <code>src/hello</code> inside your workspace,
208and in that directory create a file named <code>hello.go</code> that looks like:
Brent Austinba3052e2015-04-21 16:08:23 -0700209</p>
210
211<pre>
212package main
213
214import "fmt"
215
216func main() {
Dan Willemsenc7413322018-08-27 23:21:26 -0700217 fmt.Printf("hello, world\n")
Brent Austinba3052e2015-04-21 16:08:23 -0700218}
219</pre>
220
221<p>
Dan Willemsenebae3022017-01-13 23:01:08 -0800222Then build it with the <code>go</code> tool:
Brent Austinba3052e2015-04-21 16:08:23 -0700223</p>
224
Dan Willemsen38f2dba2016-07-08 14:54:35 -0700225<pre class="testUnix">
Dan Willemsenebae3022017-01-13 23:01:08 -0800226$ <b>cd $HOME/go/src/hello</b>
227$ <b>go build</b>
Dan Willemsen09eb3b12015-09-16 14:34:17 -0700228</pre>
229
Dan Willemsenb57d8522017-01-19 15:07:53 -0800230<pre class="testWindows">
Dan Willemsenebae3022017-01-13 23:01:08 -0800231C:\&gt; <b>cd %USERPROFILE%\go\src\hello</b>
232C:\Users\Gopher\go\src\hello&gt; <b>go build</b>
Dan Willemsen38f2dba2016-07-08 14:54:35 -0700233</pre>
234
Dan Willemsen09eb3b12015-09-16 14:34:17 -0700235<p>
Dan Willemsenebae3022017-01-13 23:01:08 -0800236The command above will build an executable named
237<code class="testUnix">hello</code><code class="testWindows">hello.exe</code>
238in the directory alongside your source code.
239Execute it to see the greeting:
Dan Willemsen09eb3b12015-09-16 14:34:17 -0700240</p>
241
Dan Willemsen38f2dba2016-07-08 14:54:35 -0700242<pre class="testUnix">
Dan Willemsenebae3022017-01-13 23:01:08 -0800243$ <b>./hello</b>
Brent Austinba3052e2015-04-21 16:08:23 -0700244hello, world
245</pre>
246
Dan Willemsenb57d8522017-01-19 15:07:53 -0800247<pre class="testWindows">
Dan Willemsenebae3022017-01-13 23:01:08 -0800248C:\Users\Gopher\go\src\hello&gt; <b>hello</b>
Dan Willemsen38f2dba2016-07-08 14:54:35 -0700249hello, world
250</pre>
251
Brent Austinba3052e2015-04-21 16:08:23 -0700252<p>
253If you see the "hello, world" message then your Go installation is working.
254</p>
255
Brent Austinba3052e2015-04-21 16:08:23 -0700256<p>
Dan Willemsenebae3022017-01-13 23:01:08 -0800257You can run <code>go</code> <code>install</code> to install the binary into
258your workspace's <code>bin</code> directory
Dan Willemsenc7413322018-08-27 23:21:26 -0700259or <code>go</code> <code>clean</code> <code>-i</code> to remove it.
Dan Willemsenebae3022017-01-13 23:01:08 -0800260</p>
261
262<p>
Dan Willemsen09eb3b12015-09-16 14:34:17 -0700263Before rushing off to write Go code please read the
264<a href="/doc/code.html">How to Write Go Code</a> document,
265which describes some essential concepts about using the Go tools.
Brent Austinba3052e2015-04-21 16:08:23 -0700266</p>
267
268
Colin Crossd9c6b802019-03-19 21:10:31 -0700269<h2 id="extra_versions">Installing extra Go versions</h2>
270
271<p>
272It may be useful to have multiple Go versions installed on the same machine, for
273example, to ensure that a package's tests pass on multiple Go versions.
274Once you have one Go version installed, you can install another (such as 1.10.7)
275as follows:
276</p>
277
278<pre>
279$ go get golang.org/dl/go1.10.7
280$ go1.10.7 download
281</pre>
282
283<p>
284The newly downloaded version can be used like <code>go</code>:
285</p>
286
287<pre>
288$ go1.10.7 version
289go version go1.10.7 linux/amd64
290</pre>
291
292<p>
293All Go versions available via this method are listed on
294<a href="https://godoc.org/golang.org/dl#pkg-subdirectories">the download page</a>.
295You can find where each of these extra Go versions is installed by looking
296at its <code>GOROOT</code>; for example, <code>go1.10.7 env GOROOT</code>.
297To uninstall a downloaded version, just remove its <code>GOROOT</code> directory
298and the <code>goX.Y.Z</code> binary.
299</p>
300
301
Brent Austinba3052e2015-04-21 16:08:23 -0700302<h2 id="uninstall">Uninstalling Go</h2>
303
304<p>
305To remove an existing Go installation from your system delete the
306<code>go</code> directory. This is usually <code>/usr/local/go</code>
Dan Willemsenc7413322018-08-27 23:21:26 -0700307under Linux, macOS, and FreeBSD or <code>c:\Go</code>
Brent Austinba3052e2015-04-21 16:08:23 -0700308under Windows.
309</p>
310
311<p>
312You should also remove the Go <code>bin</code> directory from your
313<code>PATH</code> environment variable.
314Under Linux and FreeBSD you should edit <code>/etc/profile</code> or
315<code>$HOME/.profile</code>.
Dan Willemsenc7413322018-08-27 23:21:26 -0700316If you installed Go with the <a href="#macos">macOS package</a> then you
Brent Austinba3052e2015-04-21 16:08:23 -0700317should remove the <code>/etc/paths.d/go</code> file.
318Windows users should read the section about <a href="#windows_env">setting
319environment variables under Windows</a>.
320</p>
321
322
323<h2 id="help">Getting help</h2>
324
325<p>
Dan Willemsenebae3022017-01-13 23:01:08 -0800326 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 -0700327</p>
328
329<p>
Dan Willemsenebae3022017-01-13 23:01:08 -0800330 Report bugs either by running “<b><code>go</code> <code>bug</code></b>”, or
331 manually at the <a href="https://golang.org/issue">Go issue tracker</a>.
Brent Austinba3052e2015-04-21 16:08:23 -0700332</p>