-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.html
332 lines (255 loc) · 9.78 KB
/
install.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
<!--{
"Title": "Getting Started",
"Path": "/doc/install"
}-->
<div class="hideFromDownload">
<h2 id="download">Download the Go distribution</h2>
<p>
<a href="/dl/" id="start" class="download">
<span class="big">Download Go</span>
<span class="desc">Click here to visit the downloads page</span>
</a>
</p>
<p>
<a href="/dl/" target="_blank">Official binary
distributions</a> are available for the FreeBSD (release 10-STABLE and above),
Linux, macOS (10.10 and above), and Windows operating systems and
the 32-bit (<code>386</code>) and 64-bit (<code>amd64</code>) x86 processor
architectures.
</p>
<p>
If a binary distribution is not available for your combination of operating
system and architecture, try
<a href="/doc/install/source">installing from source</a> or
<a href="/doc/install/gccgo">installing gccgo instead of gc</a>.
</p>
<h2 id="requirements">System requirements</h2>
<p>
Go <a href="/dl/">binary distributions</a> are available for these supported operating systems and architectures.
Please ensure your system meets these requirements before proceeding.
If your OS or architecture is not on the list, you may be able to
<a href="/doc/install/source">install from source</a> or
<a href="/doc/install/gccgo">use gccgo instead</a>.
</p>
<table class="codetable" frame="border" summary="requirements">
<tr>
<th align="center">Operating system</th>
<th align="center">Architectures</th>
<th align="center">Notes</th>
</tr>
<tr><td colspan="3"><hr></td></tr>
<tr><td>FreeBSD 10.3 or later</td> <td>amd64, 386</td> <td>Debian GNU/kFreeBSD not supported</td></tr>
<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>
<tr><td>macOS 10.10 or later</td> <td>amd64</td> <td>use the clang or gcc<sup>†</sup> that comes with Xcode<sup>‡</sup> for <code>cgo</code> support</td></tr>
<tr><td>Windows 7, Server 2008R2 or later</td> <td>amd64, 386</td> <td>use MinGW gcc<sup>†</sup>. No need for cygwin or msys.</td></tr>
</table>
<p>
<sup>†</sup>A C compiler is required only if you plan to use
<a href="/cmd/cgo">cgo</a>.<br/>
<sup>‡</sup>You only need to install the command line tools for
<a href="https://developer.apple.com/Xcode/">Xcode</a>. If you have already
installed Xcode 4.3+, you can install it from the Components tab of the
Downloads preferences panel.
</p>
</div><!-- hideFromDownload -->
<h2 id="install">Install the Go tools</h2>
<p>
If you are upgrading from an older version of Go you must
first <a href="#uninstall">remove the existing version</a>.
</p>
<div id="tarballInstructions">
<h3 id="tarball">Linux, macOS, and FreeBSD tarballs</h3>
<p>
<a href="/dl/">Download the archive</a>
and extract it into <code>/usr/local</code>, creating a Go tree in
<code>/usr/local/go</code>. For example:
</p>
<pre>
tar -C /usr/local -xzf <span class="downloadFilename">go$VERSION.$OS-$ARCH.tar.gz</span>
</pre>
<p class="hideFromDownload">
Choose the archive file appropriate for your installation.
For instance, if you are installing Go version 1.2.1 for 64-bit x86 on Linux,
the archive you want is called <code>go1.2.1.linux-amd64.tar.gz</code>.
</p>
<p>
(Typically these commands must be run as root or through <code>sudo</code>.)
</p>
<p>
Add <code>/usr/local/go/bin</code> to the <code>PATH</code> environment
variable. You can do this by adding this line to your <code>/etc/profile</code>
(for a system-wide installation) or <code>$HOME/.profile</code>:
</p>
<pre>
export PATH=$PATH:/usr/local/go/bin
</pre>
<p>
<b>Note</b>: changes made to a <code>profile</code> file may not apply until the
next time you log into your computer.
To apply the changes immediately, just run the shell commands directly
or execute them from the profile using a command such as
<code>source $HOME/.profile</code>.
</p>
</div><!-- tarballInstructions -->
<div id="darwinPackageInstructions">
<h3 id="macos"><div id="osx"></div>macOS package installer</h3>
<p>
<a href="/dl/">Download the package file</a>,
open it, and follow the prompts to install the Go tools.
The package installs the Go distribution to <code>/usr/local/go</code>.
</p>
<p>
The package should put the <code>/usr/local/go/bin</code> directory in your
<code>PATH</code> environment variable. You may need to restart any open
Terminal sessions for the change to take effect.
</p>
</div><!-- darwinPackageInstructions -->
<div id="windowsInstructions">
<h3 id="windows">Windows</h3>
<p class="hideFromDownload">
The Go project provides two installation options for Windows users
(besides <a href="/doc/install/source">installing from source</a>):
a zip archive that requires you to set some environment variables and an
MSI installer that configures your installation automatically.
</p>
<div id="windowsInstallerInstructions">
<h4 id="windows_msi">MSI installer</h4>
<p>
Open the <a href="/dl/">MSI file</a>
and follow the prompts to install the Go tools.
By default, the installer puts the Go distribution in <code>c:\Go</code>.
</p>
<p>
The installer should put the <code>c:\Go\bin</code> directory in your
<code>PATH</code> environment variable. You may need to restart any open
command prompts for the change to take effect.
</p>
</div><!-- windowsInstallerInstructions -->
<div id="windowsZipInstructions">
<h4 id="windows_zip">Zip archive</h4>
<p>
<a href="/dl/">Download the zip file</a> and extract it into the directory of your choice (we suggest <code>c:\Go</code>).
</p>
<p>
Add the <code>bin</code> subdirectory of your Go root (for example, <code>c:\Go\bin</code>) to your <code>PATH</code> environment variable.
</p>
</div><!-- windowsZipInstructions -->
<h4 id="windows_env">Setting environment variables under Windows</h4>
<p>
Under Windows, you may set environment variables through the "Environment
Variables" button on the "Advanced" tab of the "System" control panel. Some
versions of Windows provide this control panel through the "Advanced System
Settings" option inside the "System" control panel.
</p>
</div><!-- windowsInstructions -->
<h2 id="testing">Test your installation</h2>
<p>
Check that Go is installed correctly by setting up a workspace
and building a simple program, as follows.
</p>
<p>
Create your <a href="code.html#Workspaces">workspace</a> directory,
<code class="testUnix">$HOME/go</code><code class="testWindows">%USERPROFILE%\go</code>.
(If you'd like to use a different directory,
you will need to <a href="https://golang.org/wiki/SettingGOPATH">set the <code>GOPATH</code> environment variable</a>.)
</p>
<p>
Next, make the directory <code class="testUnix">src/hello</code><code class="testWindows">src\hello</code> inside your workspace,
and in that directory create a file named <code>hello.go</code> that looks like:
</p>
<pre>
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}
</pre>
<p>
Then build it with the <code>go</code> tool:
</p>
<pre class="testUnix">
$ <b>cd $HOME/go/src/hello</b>
$ <b>go build</b>
</pre>
<pre class="testWindows">
C:\> <b>cd %USERPROFILE%\go\src\hello</b>
C:\Users\Gopher\go\src\hello> <b>go build</b>
</pre>
<p>
The command above will build an executable named
<code class="testUnix">hello</code><code class="testWindows">hello.exe</code>
in the directory alongside your source code.
Execute it to see the greeting:
</p>
<pre class="testUnix">
$ <b>./hello</b>
hello, world
</pre>
<pre class="testWindows">
C:\Users\Gopher\go\src\hello> <b>hello</b>
hello, world
</pre>
<p>
If you see the "hello, world" message then your Go installation is working.
</p>
<p>
You can run <code>go</code> <code>install</code> to install the binary into
your workspace's <code>bin</code> directory
or <code>go</code> <code>clean</code> <code>-i</code> to remove it.
</p>
<p>
Before rushing off to write Go code please read the
<a href="/doc/code.html">How to Write Go Code</a> document,
which describes some essential concepts about using the Go tools.
</p>
<h2 id="extra_versions">Installing extra Go versions</h2>
<p>
It may be useful to have multiple Go versions installed on the same machine, for
example, to ensure that a package's tests pass on multiple Go versions.
Once you have one Go version installed, you can install another (such as 1.10.7)
as follows:
</p>
<pre>
$ go get golang.org/dl/go1.10.7
$ go1.10.7 download
</pre>
<p>
The newly downloaded version can be used like <code>go</code>:
</p>
<pre>
$ go1.10.7 version
go version go1.10.7 linux/amd64
</pre>
<p>
All Go versions available via this method are listed on
<a href="https://godoc.org/golang.org/dl#pkg-subdirectories">the download page</a>.
You can find where each of these extra Go versions is installed by looking
at its <code>GOROOT</code>; for example, <code>go1.10.7 env GOROOT</code>.
To uninstall a downloaded version, just remove its <code>GOROOT</code> directory
and the <code>goX.Y.Z</code> binary.
</p>
<h2 id="uninstall">Uninstalling Go</h2>
<p>
To remove an existing Go installation from your system delete the
<code>go</code> directory. This is usually <code>/usr/local/go</code>
under Linux, macOS, and FreeBSD or <code>c:\Go</code>
under Windows.
</p>
<p>
You should also remove the Go <code>bin</code> directory from your
<code>PATH</code> environment variable.
Under Linux and FreeBSD you should edit <code>/etc/profile</code> or
<code>$HOME/.profile</code>.
If you installed Go with the <a href="#macos">macOS package</a> then you
should remove the <code>/etc/paths.d/go</code> file.
Windows users should read the section about <a href="#windows_env">setting
environment variables under Windows</a>.
</p>
<h2 id="help">Getting help</h2>
<p>
For help, see the <a href="/help/">list of Go mailing lists, forums, and places to chat</a>.
</p>
<p>
Report bugs either by running “<b><code>go</code> <code>bug</code></b>”, or
manually at the <a href="https://golang.org/issue">Go issue tracker</a>.
</p>