| <!--{ | |
| "Title": "Getting Started", | |
| "Path": "/doc/install" | |
| }--> | |
| <div class="hideFromDownload"> | |
| <h2 id="download">Download the Go distribution</h2> | |
| <p> | |
| <a href="https://golang.org/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="https://golang.org/dl/" target="_blank">Official binary | |
| distributions</a> are available for the FreeBSD (release 8-STABLE and above), | |
| Linux, Mac OS X (10.7 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 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>. | |
| </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 8-STABLE or later</td> <td>amd64</td> <td>Debian GNU/kFreeBSD not supported</td></tr> | |
| <tr><td>Linux 2.6.23 or later with glibc</td> <td>amd64, 386, arm</td> <td>CentOS/RHEL 5.x not supported</td></tr> | |
| <tr><td>Mac OS X 10.7 or later</td> <td>amd64</td> <td>use the clang or gcc<sup>†</sup> that comes with Xcode<sup>‡</sup></td></tr> | |
| <tr><td>Windows XP 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><code>gcc</code> 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="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. | |
| </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, Mac OS X, and FreeBSD tarballs</h3> | |
| <p> | |
| <a href="https://golang.org/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> | |
| <h4 id="tarball_non_standard">Installing to a custom location</h4> | |
| <p> | |
| The Go binary distributions assume they will be installed in | |
| <code>/usr/local/go</code> (or <code>c:\Go</code> under Windows), | |
| but it is possible to install the Go tools to a different location. | |
| In this case you must set the <code>GOROOT</code> environment variable | |
| to point to the directory in which it was installed. | |
| </p> | |
| <p> | |
| For example, if you installed Go to your home directory you should add the | |
| following commands to <code>$HOME/.profile</code>: | |
| </p> | |
| <pre> | |
| export GOROOT=$HOME/go | |
| export PATH=$PATH:$GOROOT/bin | |
| </pre> | |
| <p> | |
| <b>Note</b>: <code>GOROOT</code> must be set only when installing to a custom | |
| location. | |
| </p> | |
| </div><!-- tarballInstructions --> | |
| <div id="darwinPackageInstructions"> | |
| <h3 id="osx">Mac OS X package installer</h3> | |
| <p> | |
| <a href="https://golang.org/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="https://golang.org/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="https://golang.org/dl/">Download the zip file</a> and extract it into the directory of your choice (we suggest <code>c:\Go</code>). | |
| </p> | |
| <p> | |
| If you chose a directory other than <code>c:\Go</code>, | |
| you must set the <code>GOROOT</code> environment variable to your chosen path. | |
| </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 a directory to contain your <a href="code.html#Workspaces">workspace</a>, | |
| <code class="testUnix">$HOME/work</code> | |
| <code class="testWindows" style="display: none">%HOME%\work</code> | |
| for example, and set the <code>GOPATH</code> environment | |
| variable to point to that location. | |
| </p> | |
| <pre class="testUnix"> | |
| $ <b>export GOPATH=$HOME/work</b> | |
| </pre> | |
| <pre class="testWindows" style="display: none"> | |
| C:\> <b>set GOPATH=%HOME%\work</b> | |
| </pre> | |
| <p> | |
| <span class="testUnix"> | |
| You should put the above command in your shell startup script | |
| (<code>$HOME/.profile</code> for example). | |
| </span> | |
| <span class="testWindows"> | |
| On Windows, follow the <a href="#windows_env">instructions above</a> to set the | |
| <code>GOPATH</code> environment variable on your system. | |
| </span> | |
| </p> | |
| <p> | |
| Next, make the directories <code>src/github.com/user/hello</code> inside your | |
| workspace (if you use GitHub, substitute your user name for <code>user</code>), | |
| and inside the <code>hello</code> directory create a file named <code>hello.go</code> | |
| with the following contents: | |
| </p> | |
| <pre> | |
| package main | |
| import "fmt" | |
| func main() { | |
| fmt.Printf("hello, world\n") | |
| } | |
| </pre> | |
| <p> | |
| Then compile it with the <code>go</code> tool: | |
| </p> | |
| <pre class="testUnix"> | |
| $ <b>go install github.com/user/hello</b> | |
| </pre> | |
| <pre class="testWindows" style="display: none"> | |
| C:\> <b>go install github.com/user/hello</b> | |
| </pre> | |
| <p> | |
| The command above will put an executable command named <code>hello</code> | |
| (or <code>hello.exe</code>) inside the <code>bin</code> directory of your workspace. | |
| Execute the command to see the greeting: | |
| </p> | |
| <pre class="testUnix"> | |
| $ <b>$GOPATH/bin/hello</b> | |
| hello, world | |
| </pre> | |
| <pre class="testWindows" style="display: none"> | |
| C:\> <b>%GOPATH%\bin\hello</b> | |
| hello, world | |
| </pre> | |
| <p> | |
| If you see the "hello, world" message then your Go installation is working. | |
| </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="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> | |
| <h2 id="help">Getting help</h2> | |
| <p> | |
| For real-time help, ask the helpful gophers in <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="//groups.google.com/group/golang-nuts">Go Nuts</a>. | |
| </p> | |
| <p> | |
| Report bugs using the | |
| <a href="//golang.org/issue">Go issue tracker</a>. | |
| </p> |