install.html 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <!--{
  2. "Title": "Getting Started",
  3. "Path": "/doc/install"
  4. }-->
  5. <div class="hideFromDownload">
  6. <h2 id="download">Download the Go distribution</h2>
  7. <p>
  8. <a href="https://golang.org/dl/" id="start" class="download">
  9. <span class="big">Download Go</span>
  10. <span class="desc">Click here to visit the downloads page</span>
  11. </a>
  12. </p>
  13. <p>
  14. <a href="https://golang.org/dl/" target="_blank">Official binary
  15. distributions</a> are available for the FreeBSD (release 8-STABLE and above),
  16. Linux, Mac OS X (10.8 and above), and Windows operating systems and
  17. the 32-bit (<code>386</code>) and 64-bit (<code>amd64</code>) x86 processor
  18. architectures.
  19. </p>
  20. <p>
  21. If a binary distribution is not available for your combination of operating
  22. system and architecture, try
  23. <a href="/doc/install/source">installing from source</a> or
  24. <a href="/doc/install/gccgo">installing gccgo instead of gc</a>.
  25. </p>
  26. <h2 id="requirements">System requirements</h2>
  27. <p>
  28. Go <a href="https://golang.org/dl/">binary distributions</a> are available for these supported operating systems and architectures.
  29. Please ensure your system meets these requirements before proceeding.
  30. If your OS or architecture is not on the list, you may be able to
  31. <a href="/doc/install/source">install from source</a> or
  32. <a href="/doc/install/gccgo">use gccgo instead</a>.
  33. </p>
  34. <table class="codetable" frame="border" summary="requirements">
  35. <tr>
  36. <th align="center">Operating system</th>
  37. <th align="center">Architectures</th>
  38. <th align="center">Notes</th>
  39. </tr>
  40. <tr><td colspan="3"><hr></td></tr>
  41. <tr><td>FreeBSD 9.3 or later</td> <td>amd64, 386</td> <td>Debian GNU/kFreeBSD not supported</td></tr>
  42. <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>
  43. <tr><td>macOS 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>
  44. <tr><td>Windows XP SP2 or later</td> <td>amd64, 386</td> <td>use MinGW gcc<sup>&#8224;</sup>. No need for cygwin or msys.</td></tr>
  45. </table>
  46. <p>
  47. <sup>&#8224;</sup>A C compiler is required only if you plan to use
  48. <a href="/cmd/cgo">cgo</a>.<br/>
  49. <sup>&#8225;</sup>You only need to install the command line tools for
  50. <a href="http://developer.apple.com/Xcode/">Xcode</a>. If you have already
  51. installed Xcode 4.3+, you can install it from the Components tab of the
  52. Downloads preferences panel.
  53. </p>
  54. </div><!-- hideFromDownload -->
  55. <h2 id="install">Install the Go tools</h2>
  56. <p>
  57. If you are upgrading from an older version of Go you must
  58. first <a href="#uninstall">remove the existing version</a>.
  59. </p>
  60. <div id="tarballInstructions">
  61. <h3 id="tarball">Linux, Mac OS X, and FreeBSD tarballs</h3>
  62. <p>
  63. <a href="https://golang.org/dl/">Download the archive</a>
  64. and extract it into <code>/usr/local</code>, creating a Go tree in
  65. <code>/usr/local/go</code>. For example:
  66. </p>
  67. <pre>
  68. tar -C /usr/local -xzf <span class="downloadFilename">go$VERSION.$OS-$ARCH.tar.gz</span>
  69. </pre>
  70. <p class="hideFromDownload">
  71. Choose the archive file appropriate for your installation.
  72. For instance, if you are installing Go version 1.2.1 for 64-bit x86 on Linux,
  73. the archive you want is called <code>go1.2.1.linux-amd64.tar.gz</code>.
  74. </p>
  75. <p>
  76. (Typically these commands must be run as root or through <code>sudo</code>.)
  77. </p>
  78. <p>
  79. Add <code>/usr/local/go/bin</code> to the <code>PATH</code> environment
  80. variable. You can do this by adding this line to your <code>/etc/profile</code>
  81. (for a system-wide installation) or <code>$HOME/.profile</code>:
  82. </p>
  83. <pre>
  84. export PATH=$PATH:/usr/local/go/bin
  85. </pre>
  86. <h4 id="tarball_non_standard">Installing to a custom location</h4>
  87. <p>
  88. The Go binary distributions assume they will be installed in
  89. <code>/usr/local/go</code> (or <code>c:\Go</code> under Windows),
  90. but it is possible to install the Go tools to a different location.
  91. In this case you must set the <code>GOROOT</code> environment variable
  92. to point to the directory in which it was installed.
  93. </p>
  94. <p>
  95. For example, if you installed Go to your home directory you should add
  96. commands like the following to <code>$HOME/.profile</code>:
  97. </p>
  98. <pre>
  99. export GOROOT=$HOME/go1.X
  100. export PATH=$PATH:$GOROOT/bin
  101. </pre>
  102. <p>
  103. <b>Note</b>: <code>GOROOT</code> must be set only when installing to a custom
  104. location.
  105. </p>
  106. </div><!-- tarballInstructions -->
  107. <div id="darwinPackageInstructions">
  108. <h3 id="osx">Mac OS X package installer</h3>
  109. <p>
  110. <a href="https://golang.org/dl/">Download the package file</a>,
  111. open it, and follow the prompts to install the Go tools.
  112. The package installs the Go distribution to <code>/usr/local/go</code>.
  113. </p>
  114. <p>
  115. The package should put the <code>/usr/local/go/bin</code> directory in your
  116. <code>PATH</code> environment variable. You may need to restart any open
  117. Terminal sessions for the change to take effect.
  118. </p>
  119. </div><!-- darwinPackageInstructions -->
  120. <div id="windowsInstructions">
  121. <h3 id="windows">Windows</h3>
  122. <p class="hideFromDownload">
  123. The Go project provides two installation options for Windows users
  124. (besides <a href="/doc/install/source">installing from source</a>):
  125. a zip archive that requires you to set some environment variables and an
  126. MSI installer that configures your installation automatically.
  127. </p>
  128. <div id="windowsInstallerInstructions">
  129. <h4 id="windows_msi">MSI installer</h4>
  130. <p>
  131. Open the <a href="https://golang.org/dl/">MSI file</a>
  132. and follow the prompts to install the Go tools.
  133. By default, the installer puts the Go distribution in <code>c:\Go</code>.
  134. </p>
  135. <p>
  136. The installer should put the <code>c:\Go\bin</code> directory in your
  137. <code>PATH</code> environment variable. You may need to restart any open
  138. command prompts for the change to take effect.
  139. </p>
  140. </div><!-- windowsInstallerInstructions -->
  141. <div id="windowsZipInstructions">
  142. <h4 id="windows_zip">Zip archive</h4>
  143. <p>
  144. <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>).
  145. </p>
  146. <p>
  147. If you chose a directory other than <code>c:\Go</code>,
  148. you must set the <code>GOROOT</code> environment variable to your chosen path.
  149. </p>
  150. <p>
  151. Add the <code>bin</code> subdirectory of your Go root (for example, <code>c:\Go\bin</code>) to your <code>PATH</code> environment variable.
  152. </p>
  153. </div><!-- windowsZipInstructions -->
  154. <h4 id="windows_env">Setting environment variables under Windows</h4>
  155. <p>
  156. Under Windows, you may set environment variables through the "Environment
  157. Variables" button on the "Advanced" tab of the "System" control panel. Some
  158. versions of Windows provide this control panel through the "Advanced System
  159. Settings" option inside the "System" control panel.
  160. </p>
  161. </div><!-- windowsInstructions -->
  162. <h2 id="testing">Test your installation</h2>
  163. <p>
  164. Check that Go is installed correctly by setting up a workspace
  165. and building a simple program, as follows.
  166. </p>
  167. <p>
  168. Create your <a href="code.html#Workspaces">workspace</a> directory,
  169. <code class="testUnix">$HOME/go</code><code class="testWindows">%USERPROFILE%\go</code>.
  170. (If you'd like to use a different directory,
  171. you will need to <a href="https://golang.org/wiki/SettingGOPATH">set the <code>GOPATH</code> environment variable</a>.)
  172. </p>
  173. <p>
  174. Next, make the directory <code>src/hello</code> inside your workspace,
  175. and in that directory create a file named <code>hello.go</code> that looks like:
  176. </p>
  177. <pre>
  178. package main
  179. import "fmt"
  180. func main() {
  181. fmt.Printf("hello, world\n")
  182. }
  183. </pre>
  184. <p>
  185. Then build it with the <code>go</code> tool:
  186. </p>
  187. <pre class="testUnix">
  188. $ <b>cd $HOME/go/src/hello</b>
  189. $ <b>go build</b>
  190. </pre>
  191. <pre class="testWindows">
  192. C:\&gt; <b>cd %USERPROFILE%\go\src\hello</b>
  193. C:\Users\Gopher\go\src\hello&gt; <b>go build</b>
  194. </pre>
  195. <p>
  196. The command above will build an executable named
  197. <code class="testUnix">hello</code><code class="testWindows">hello.exe</code>
  198. in the directory alongside your source code.
  199. Execute it to see the greeting:
  200. </p>
  201. <pre class="testUnix">
  202. $ <b>./hello</b>
  203. hello, world
  204. </pre>
  205. <pre class="testWindows">
  206. C:\Users\Gopher\go\src\hello&gt; <b>hello</b>
  207. hello, world
  208. </pre>
  209. <p>
  210. If you see the "hello, world" message then your Go installation is working.
  211. </p>
  212. <p>
  213. You can run <code>go</code> <code>install</code> to install the binary into
  214. your workspace's <code>bin</code> directory
  215. or <code>go</code> <code>clean</code> to remove it.
  216. </p>
  217. <p>
  218. Before rushing off to write Go code please read the
  219. <a href="/doc/code.html">How to Write Go Code</a> document,
  220. which describes some essential concepts about using the Go tools.
  221. </p>
  222. <h2 id="uninstall">Uninstalling Go</h2>
  223. <p>
  224. To remove an existing Go installation from your system delete the
  225. <code>go</code> directory. This is usually <code>/usr/local/go</code>
  226. under Linux, Mac OS X, and FreeBSD or <code>c:\Go</code>
  227. under Windows.
  228. </p>
  229. <p>
  230. You should also remove the Go <code>bin</code> directory from your
  231. <code>PATH</code> environment variable.
  232. Under Linux and FreeBSD you should edit <code>/etc/profile</code> or
  233. <code>$HOME/.profile</code>.
  234. If you installed Go with the <a href="#osx">Mac OS X package</a> then you
  235. should remove the <code>/etc/paths.d/go</code> file.
  236. Windows users should read the section about <a href="#windows_env">setting
  237. environment variables under Windows</a>.
  238. </p>
  239. <h2 id="help">Getting help</h2>
  240. <p>
  241. For help, see the <a href="/help/">list of Go mailing lists, forums, and places to chat</a>.
  242. </p>
  243. <p>
  244. Report bugs either by running “<b><code>go</code> <code>bug</code></b>”, or
  245. manually at the <a href="https://golang.org/issue">Go issue tracker</a>.
  246. </p>