"README.md" did not exist on "3ba80d981685d9b0115dc7d61aef96da71f080bd"
install.html 4.71 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
<h2 id="introduction">Introduction</h2>
Russ Cox's avatar
Russ Cox committed
7

8 9 10 11
<p>
Go is an open source project with a BSD-style license.
There are two official Go compiler toolchains: the <code>gc</code> Go compiler
and the <code>gccgo</code> compiler that is part of the GNU C Compiler (GCC).
Russ Cox's avatar
Russ Cox committed
12 13
</p>

Russ Cox's avatar
Russ Cox committed
14
<p>
15 16 17
The <code>gc</code> compiler is the more mature and well-tested of the two.
This page is about installing a binary distribution of the <code>gc</code>
compiler.
Russ Cox's avatar
Russ Cox committed
18 19
</p>

20
<p>
21
For information about installing the <code>gc</code> compiler from source, see
22
<a href="/doc/install/source">Installing Go from source</a>.
23
For information about installing <code>gccgo</code>, see
24
<a href="/doc/install/gccgo">Setting up and using gccgo</a>.
25 26
</p>

27
<h2 id="download">Obtaining the Go tools</h2>
28 29

<p>
30 31 32 33
Visit the
<a href="http://code.google.com/p/go/downloads">Go project's downloads page</a>
and select the binary distribution that matches
your operating system and processor architecture.
34 35 36
</p>

<p>
37 38 39 40
Official binary distributions are available
for the FreeBSD, Linux, Mac OS X, and Windows operating systems
and the 32-bit (<code>386</code>) and 64-bit (<code>amd64</code>)
x86 processor architectures.
41
</p>
42

43 44 45
<p>
If a binary distribution is not available for your
OS/arch combination you may want to try
46 47
<a href="/doc/install/source">installing from source</a> or
<a href="/doc/install/gccgo">installing gccgo instead of gc</a>.
48 49
</p>

50
<h2 id="install">Installing the Go tools</h2>
Russ Cox's avatar
Russ Cox committed
51 52

<p>
53 54 55 56
The Go binary distributions assume they will be installed in
<code>/usr/local/go</code>, but it is possible to install them in a different
location. If you do this, you will need to set the <code>GOROOT</code>
environment variable to that directory when using the Go tools.
Andrew Gerrand's avatar
Andrew Gerrand committed
57 58
</p>

59
<p>
60 61
For example, if you installed Go to your home directory you should add the
following commands to <code>$HOME/.profile</code>:
62 63
</p>

Russ Cox's avatar
Russ Cox committed
64
<pre>
65 66
export GOROOT=$HOME/go
export PATH=$PATH:$GOROOT/bin
Russ Cox's avatar
Russ Cox committed
67 68
</pre>

69
<h3 id="freebsd_linux">FreeBSD and Linux</h3>
Russ Cox's avatar
Russ Cox committed
70

71 72 73 74 75 76 77 78 79
<p>
On FreeBSD and Linux, if you are upgrading from an older version of Go you must
first remove the existing version from <code>/usr/local/go</code>:
</p>

<pre>
rm -r /usr/local/go
</pre>

Russ Cox's avatar
Russ Cox committed
80
<p>
81
Extract the archive into <code>/usr/local</code>, creating a Go tree in
82
<code>/usr/local/go</code>:
Russ Cox's avatar
Russ Cox committed
83 84 85
</p>

<pre>
86
tar -C /usr/local -xzf go.release.go1.tar.gz
Russ Cox's avatar
Russ Cox committed
87 88
</pre>

89 90
<p>(Typically these commands must be run as root or through <code>sudo</code>.)</p>

Russ Cox's avatar
Russ Cox committed
91
<p>
92 93 94
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
95 96 97
</p>

<pre>
98
export PATH=$PATH:/usr/local/go/bin
Russ Cox's avatar
Russ Cox committed
99 100
</pre>

101
<h3 id="osx">Mac OS X</h3>
Russ Cox's avatar
Russ Cox committed
102 103

<p>
104 105
Open the <code>.pkg</code> file and follow the prompts to install the Go tools.
The package installs the Go distribution to <code>/usr/local/go</code>.
Russ Cox's avatar
Russ Cox committed
106 107 108
</p>

<p>
109 110 111
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
112 113
</p>

114 115
<h3 id="windows">Windows</h3>

Russ Cox's avatar
Russ Cox committed
116
<p>
117
<font color="red">TODO: windows installation instructions.</font>
Russ Cox's avatar
Russ Cox committed
118 119
</p>

120
<h2 id="testing">Testing your installation</h2>
Russ Cox's avatar
Russ Cox committed
121 122

<p>
123
Check that Go is installed correctly by building a simple program, as follows.
Russ Cox's avatar
Russ Cox committed
124 125
</p>

126 127
<p>
Create a file named <code>hello.go</code> and put the following program in it:
Russ Cox's avatar
Russ Cox committed
128 129 130 131 132 133 134 135
</p>

<pre>
package main

import "fmt"

func main() {
136
    fmt.Printf("hello, world\n")
Russ Cox's avatar
Russ Cox committed
137 138 139 140
}
</pre>

<p>
141
Then run it with the <code>go</code> tool:
Russ Cox's avatar
Russ Cox committed
142 143
</p>

144 145 146 147 148
<pre>
$ go run hello.go
hello, world
</pre>

Russ Cox's avatar
Russ Cox committed
149
<p>
150
If you see the "hello, world" message then your Go installation is working.
Russ Cox's avatar
Russ Cox committed
151
</p>
Andrew Gerrand's avatar
Andrew Gerrand committed
152 153 154 155

<h2 id="next">What's next</h2>

<p>
Andrew Gerrand's avatar
Andrew Gerrand committed
156
Start by taking <a href="http://code.google.com/p/go-tour/">A Tour of Go</a>
Rob Pike's avatar
Rob Pike committed
157
or reading the <a href="/doc/go_tutorial.html">Go Tutorial</a>.
Andrew Gerrand's avatar
Andrew Gerrand committed
158 159
</p>

160 161 162 163 164
<p>
For more detail about the process of building and testing Go programs
read <a href="/doc/code.html">How to Write Go Code</a>.
</p>

Andrew Gerrand's avatar
Andrew Gerrand committed
165
<p>
166 167
Build a web application by following the <a href="/doc/articles/wiki/">Wiki
Tutorial</a>.
Andrew Gerrand's avatar
Andrew Gerrand committed
168 169 170
</p>

<p>
171
Read <a href="/doc/effective_go.html">Effective Go</a> to learn about writing
Andrew Gerrand's avatar
Andrew Gerrand committed
172 173 174 175 176
idiomatic Go code.
</p>

<p>
For the full story, consult Go's extensive 
177
<a href="/doc/">documentation</a>.
Andrew Gerrand's avatar
Andrew Gerrand committed
178
</p>
Russ Cox's avatar
Russ Cox committed
179

180

181
<h2 id="community">Community resources</h2>
Russ Cox's avatar
Russ Cox committed
182 183 184 185 186 187 188 189 190 191 192 193

<p>
For real-time help, there may be users or developers on
<code>#go-nuts</code> on the <a href="http://freenode.net/">Freenode</a> IRC server.
</p>

<p>
The official mailing list for discussion of the Go language is
<a href="http://groups.google.com/group/golang-nuts">Go Nuts</a>.
</p>

<p>
194 195
Bugs should be reported using the
<a href="http://code.google.com/p/go/issues/list">Go issue tracker</a>.
196
</p>