install.html 9.36 KB
Newer Older
1
<!--{
Andrew Gerrand's avatar
Andrew Gerrand committed
2
	"Title": "Getting Started",
3
	"Path":  "/doc/install"
4
}-->
Russ Cox's avatar
Russ Cox committed
5

6 7
<div class="hideFromDownload">

8
<h2 id="download">Download the Go distribution</h2>
Russ Cox's avatar
Russ Cox committed
9

10
<p>
11
<a href="https://golang.org/dl/" id="start" class="download">
12 13 14
<span class="big">Download Go</span>
<span class="desc">Click here to visit the downloads page</span>
</a>
Russ Cox's avatar
Russ Cox committed
15 16
</p>

Russ Cox's avatar
Russ Cox committed
17
<p>
18
<a href="https://golang.org/dl/" target="_blank">Official binary
19
distributions</a> are available for the FreeBSD (release 8-STABLE and above),
20
Linux, Mac OS X (10.8 and above), and Windows operating systems and
21 22
the 32-bit (<code>386</code>) and 64-bit (<code>amd64</code>) x86 processor
architectures.
23 24 25 26
</p>

<p>
If a binary distribution is not available for your combination of operating
27
system and architecture, try
28 29
<a href="/doc/install/source">installing from source</a> or
<a href="/doc/install/gccgo">installing gccgo instead of gc</a>.
30 31
</p>

32

33
<h2 id="requirements">System requirements</h2>
34

35
<p>
36 37 38 39 40
Go binary distributions 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>.
41 42 43 44
</p>

<table class="codetable" frame="border" summary="requirements">
<tr>
45 46 47
<th align="center">Operating system</th>
<th align="center">Architectures</th>
<th align="center">Notes</th>
48 49
</tr>
<tr><td colspan="3"><hr></td></tr>
50 51
<tr><td>FreeBSD 8-STABLE or later</td> <td>amd64, 386</td> <td>Debian GNU/kFreeBSD not supported</td></tr>
<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>
53
<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 55 56
</table>

<p>
57
<sup>&#8224;</sup>A C compiler is required only if you plan to use
58 59 60 61 62
<a href="/cmd/cgo">cgo</a>.<br/>
<sup>&#8225;</sup>You only need to install the command line tools for
<a href="http://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.
63 64
</p>

65 66
</div><!-- hideFromDownload -->

67

68
<h2 id="install">Install the Go tools</h2>
Russ Cox's avatar
Russ Cox committed
69

70
<p>
Andrew Gerrand's avatar
Andrew Gerrand committed
71
If you are upgrading from an older version of Go you must
72
first <a href="#uninstall">remove the existing version</a>.
73 74
</p>

75 76
<div id="tarballInstructions">

77
<h3 id="tarball">Linux, Mac OS X, and FreeBSD tarballs</h3>
78

Russ Cox's avatar
Russ Cox committed
79
<p>
80
<a href="https://golang.org/dl/">Download the archive</a>
81 82
and extract it into <code>/usr/local</code>, creating a Go tree in
<code>/usr/local/go</code>. For example:
Russ Cox's avatar
Russ Cox committed
83 84 85
</p>

<pre>
86
tar -C /usr/local -xzf <span class="downloadFilename">go$VERSION.$OS-$ARCH.tar.gz</span>
Russ Cox's avatar
Russ Cox committed
87 88
</pre>

89
<p class="hideFromDownload">
90
Choose the archive file appropriate for your installation.
Andrew Gerrand's avatar
Andrew Gerrand committed
91 92
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>.
93 94
</p>

95 96 97
<p>
(Typically these commands must be run as root or through <code>sudo</code>.)
</p>
98

Russ Cox's avatar
Russ Cox committed
99
<p>
100 101 102
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>:
Russ Cox's avatar
Russ Cox committed
103 104 105
</p>

<pre>
106
export PATH=$PATH:/usr/local/go/bin
Russ Cox's avatar
Russ Cox committed
107 108
</pre>

Oling Cat's avatar
Oling Cat committed
109
<h4 id="tarball_non_standard">Installing to a custom location</h4>
110 111 112 113

<p>
The Go binary distributions assume they will be installed in
<code>/usr/local/go</code> (or <code>c:\Go</code> under Windows),
Oling Cat's avatar
Oling Cat committed
114
but it is possible to install the Go tools to a different location.
115 116 117 118 119
In this case you must set the <code>GOROOT</code> environment variable
to point to the directory in which it was installed.
</p>

<p>
120 121
For example, if you installed Go to your home directory you should add
commands like the following to <code>$HOME/.profile</code>:
122 123 124
</p>

<pre>
125
export GOROOT=$HOME/go1.X
126 127 128 129 130 131 132 133
export PATH=$PATH:$GOROOT/bin
</pre>

<p>
<b>Note</b>: <code>GOROOT</code> must be set only when installing to a custom
location.
</p>

134 135 136 137
</div><!-- tarballInstructions -->

<div id="darwinPackageInstructions">

Andrew Gerrand's avatar
Andrew Gerrand committed
138
<h3 id="osx">Mac OS X package installer</h3>
Russ Cox's avatar
Russ Cox committed
139 140

<p>
141
<a href="https://golang.org/dl/">Download the package file</a>,
142
open it, and follow the prompts to install the Go tools.
143
The package installs the Go distribution to <code>/usr/local/go</code>.
Russ Cox's avatar
Russ Cox committed
144 145 146
</p>

<p>
147 148 149
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.
Russ Cox's avatar
Russ Cox committed
150 151
</p>

152 153 154 155
</div><!-- darwinPackageInstructions -->

<div id="windowsInstructions">

156 157
<h3 id="windows">Windows</h3>

158
<p class="hideFromDownload">
159 160
The Go project provides two installation options for Windows users
(besides <a href="/doc/install/source">installing from source</a>):
161
a zip archive that requires you to set some environment variables and an
162
MSI installer that configures your installation automatically.
163 164
</p>

165 166
<div id="windowsInstallerInstructions">

167
<h4 id="windows_msi">MSI installer</h4>
168

Russ Cox's avatar
Russ Cox committed
169
<p>
170
Open the <a href="https://golang.org/dl/">MSI file</a>
171 172
and follow the prompts to install the Go tools.
By default, the installer puts the Go distribution in <code>c:\Go</code>.
173 174 175
</p>

<p>
176 177 178
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.
Russ Cox's avatar
Russ Cox committed
179 180
</p>

181 182 183 184
</div><!-- windowsInstallerInstructions -->

<div id="windowsZipInstructions">

185 186
<h4 id="windows_zip">Zip archive</h4>

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 190 191
</p>

<p>
192 193
If you chose a directory other than <code>c:\Go</code>,
you must set the <code>GOROOT</code> environment variable to your chosen path.
194 195 196
</p>

<p>
197
Add the <code>bin</code> subdirectory of your Go root (for example, <code>c:\Go\bin</code>) to your <code>PATH</code> environment variable.
198 199
</p>

200 201
</div><!-- windowsZipInstructions -->

202 203 204 205 206 207 208 209 210
<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>

211 212
</div><!-- windowsInstructions -->

213

214
<h2 id="testing">Test your installation</h2>
Russ Cox's avatar
Russ Cox committed
215 216

<p>
217 218 219 220 221
Check that Go is installed correctly by setting up a workspace
and building a simple program, as follows.
</p>

<p>
222 223 224 225 226
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 set the <code>GOPATH</code> environment variable;
see <a href="code.html#Workspaces">How to Write Go Code</a> for details.)
227 228 229
</p>

<p>
230 231
Next, make the directory <code>src/hello</code> inside your workspace,
and in that directory create a file named <code>hello.go</code> that looks like:
Russ Cox's avatar
Russ Cox committed
232 233 234 235 236 237 238 239
</p>

<pre>
package main

import "fmt"

func main() {
240
    fmt.Printf("hello, world\n")
Russ Cox's avatar
Russ Cox committed
241 242 243 244
}
</pre>

<p>
245
Then build it with the <code>go</code> tool:
Russ Cox's avatar
Russ Cox committed
246 247
</p>

248
<pre class="testUnix">
249
$ <b>cd $HOME/go/src/hello</b>
250
$ <b>go build</b>
251 252
</pre>

Jaana Burcu Dogan's avatar
Jaana Burcu Dogan committed
253
<pre class="testWindows">
254
C:\&gt; <b>cd %USERPROFILE%\go\src\hello</b>
255
C:\Users\Gopher\go\src\hello&gt; <b>go build</b>
256 257
</pre>

Russ Cox's avatar
Russ Cox committed
258
<p>
259 260 261 262
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:
Russ Cox's avatar
Russ Cox committed
263
</p>
Andrew Gerrand's avatar
Andrew Gerrand committed
264

265
<pre class="testUnix">
266
$ <b>./hello</b>
267 268
hello, world
</pre>
Russ Cox's avatar
Russ Cox committed
269

Jaana Burcu Dogan's avatar
Jaana Burcu Dogan committed
270
<pre class="testWindows">
271
C:\Users\Gopher\go\src\hello&gt; <b>hello</b>
272 273 274
hello, world
</pre>

Russ Cox's avatar
Russ Cox committed
275
<p>
276
If you see the "hello, world" message then your Go installation is working.
Russ Cox's avatar
Russ Cox committed
277 278
</p>

279 280 281 282 283 284
<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> to remove it.
</p>

Russ Cox's avatar
Russ Cox committed
285
<p>
286 287 288
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.
289
</p>
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312


<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, Mac OS X, 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="#osx">Mac OS X 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>


313 314 315
<h2 id="help">Getting help</h2>

<p>
316
  For help, see the <a href="/help/">list of Go mailing lists, forums, and places to chat</a>.
317 318 319
</p>

<p>
320 321
  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>.
322
</p>