install.html 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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="/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="/dl/" target="_blank">Official binary
  15. distributions</a> are available for the FreeBSD (release 10-STABLE and above),
  16. Linux, macOS (10.10 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="/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 10.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.10 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 7, Server 2008R2 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="https://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, macOS, and FreeBSD tarballs</h3>
  62. <p>
  63. <a href="/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. <p>
  87. <b>Note</b>: changes made to a <code>profile</code> file may not apply until the
  88. next time you log into your computer.
  89. To apply the changes immediately, just run the shell commands directly
  90. or execute them from the profile using a command such as
  91. <code>source $HOME/.profile</code>.
  92. </p>
  93. </div><!-- tarballInstructions -->
  94. <div id="darwinPackageInstructions">
  95. <h3 id="macos"><div id="osx"></div>macOS package installer</h3>
  96. <p>
  97. <a href="/dl/">Download the package file</a>,
  98. open it, and follow the prompts to install the Go tools.
  99. The package installs the Go distribution to <code>/usr/local/go</code>.
  100. </p>
  101. <p>
  102. The package should put the <code>/usr/local/go/bin</code> directory in your
  103. <code>PATH</code> environment variable. You may need to restart any open
  104. Terminal sessions for the change to take effect.
  105. </p>
  106. </div><!-- darwinPackageInstructions -->
  107. <div id="windowsInstructions">
  108. <h3 id="windows">Windows</h3>
  109. <p class="hideFromDownload">
  110. The Go project provides two installation options for Windows users
  111. (besides <a href="/doc/install/source">installing from source</a>):
  112. a zip archive that requires you to set some environment variables and an
  113. MSI installer that configures your installation automatically.
  114. </p>
  115. <div id="windowsInstallerInstructions">
  116. <h4 id="windows_msi">MSI installer</h4>
  117. <p>
  118. Open the <a href="/dl/">MSI file</a>
  119. and follow the prompts to install the Go tools.
  120. By default, the installer puts the Go distribution in <code>c:\Go</code>.
  121. </p>
  122. <p>
  123. The installer should put the <code>c:\Go\bin</code> directory in your
  124. <code>PATH</code> environment variable. You may need to restart any open
  125. command prompts for the change to take effect.
  126. </p>
  127. </div><!-- windowsInstallerInstructions -->
  128. <div id="windowsZipInstructions">
  129. <h4 id="windows_zip">Zip archive</h4>
  130. <p>
  131. <a href="/dl/">Download the zip file</a> and extract it into the directory of your choice (we suggest <code>c:\Go</code>).
  132. </p>
  133. <p>
  134. Add the <code>bin</code> subdirectory of your Go root (for example, <code>c:\Go\bin</code>) to your <code>PATH</code> environment variable.
  135. </p>
  136. </div><!-- windowsZipInstructions -->
  137. <h4 id="windows_env">Setting environment variables under Windows</h4>
  138. <p>
  139. Under Windows, you may set environment variables through the "Environment
  140. Variables" button on the "Advanced" tab of the "System" control panel. Some
  141. versions of Windows provide this control panel through the "Advanced System
  142. Settings" option inside the "System" control panel.
  143. </p>
  144. </div><!-- windowsInstructions -->
  145. <h2 id="testing">Test your installation</h2>
  146. <p>
  147. Check that Go is installed correctly by setting up a workspace
  148. and building a simple program, as follows.
  149. </p>
  150. <p>
  151. Create your <a href="code.html#Workspaces">workspace</a> directory,
  152. <code class="testUnix">$HOME/go</code><code class="testWindows">%USERPROFILE%\go</code>.
  153. (If you'd like to use a different directory,
  154. you will need to <a href="https://golang.org/wiki/SettingGOPATH">set the <code>GOPATH</code> environment variable</a>.)
  155. </p>
  156. <p>
  157. Next, make the directory <code>src/hello</code> inside your workspace,
  158. and in that directory create a file named <code>hello.go</code> that looks like:
  159. </p>
  160. <pre>
  161. package main
  162. import "fmt"
  163. func main() {
  164. fmt.Printf("hello, world\n")
  165. }
  166. </pre>
  167. <p>
  168. Then build it with the <code>go</code> tool:
  169. </p>
  170. <pre class="testUnix">
  171. $ <b>cd $HOME/go/src/hello</b>
  172. $ <b>go build</b>
  173. </pre>
  174. <pre class="testWindows">
  175. C:\&gt; <b>cd %USERPROFILE%\go\src\hello</b>
  176. C:\Users\Gopher\go\src\hello&gt; <b>go build</b>
  177. </pre>
  178. <p>
  179. The command above will build an executable named
  180. <code class="testUnix">hello</code><code class="testWindows">hello.exe</code>
  181. in the directory alongside your source code.
  182. Execute it to see the greeting:
  183. </p>
  184. <pre class="testUnix">
  185. $ <b>./hello</b>
  186. hello, world
  187. </pre>
  188. <pre class="testWindows">
  189. C:\Users\Gopher\go\src\hello&gt; <b>hello</b>
  190. hello, world
  191. </pre>
  192. <p>
  193. If you see the "hello, world" message then your Go installation is working.
  194. </p>
  195. <p>
  196. You can run <code>go</code> <code>install</code> to install the binary into
  197. your workspace's <code>bin</code> directory
  198. or <code>go</code> <code>clean</code> <code>-i</code> to remove it.
  199. </p>
  200. <p>
  201. Before rushing off to write Go code please read the
  202. <a href="/doc/code.html">How to Write Go Code</a> document,
  203. which describes some essential concepts about using the Go tools.
  204. </p>
  205. <h2 id="extra_versions">Installing extra Go versions</h2>
  206. <p>
  207. It may be useful to have multiple Go versions installed on the same machine, for
  208. example, to ensure that a package's tests pass on multiple Go versions.
  209. Once you have one Go version installed, you can install another (such as 1.10.7)
  210. as follows:
  211. </p>
  212. <pre>
  213. $ go get golang.org/dl/go1.10.7
  214. $ go1.10.7 download
  215. </pre>
  216. <p>
  217. The newly downloaded version can be used like <code>go</code>:
  218. </p>
  219. <pre>
  220. $ go1.10.7 version
  221. go version go1.10.7 linux/amd64
  222. </pre>
  223. <p>
  224. All Go versions available via this method are listed on
  225. <a href="https://godoc.org/golang.org/dl#pkg-subdirectories">the download page</a>.
  226. You can find where each of these extra Go versions is installed by looking
  227. at its <code>GOROOT</code>; for example, <code>go1.10.7 env GOROOT</code>.
  228. To uninstall a downloaded version, just remove its <code>GOROOT</code> directory
  229. and the <code>goX.Y.Z</code> binary.
  230. </p>
  231. <h2 id="uninstall">Uninstalling Go</h2>
  232. <p>
  233. To remove an existing Go installation from your system delete the
  234. <code>go</code> directory. This is usually <code>/usr/local/go</code>
  235. under Linux, macOS, and FreeBSD or <code>c:\Go</code>
  236. under Windows.
  237. </p>
  238. <p>
  239. You should also remove the Go <code>bin</code> directory from your
  240. <code>PATH</code> environment variable.
  241. Under Linux and FreeBSD you should edit <code>/etc/profile</code> or
  242. <code>$HOME/.profile</code>.
  243. If you installed Go with the <a href="#macos">macOS package</a> then you
  244. should remove the <code>/etc/paths.d/go</code> file.
  245. Windows users should read the section about <a href="#windows_env">setting
  246. environment variables under Windows</a>.
  247. </p>
  248. <h2 id="help">Getting help</h2>
  249. <p>
  250. For help, see the <a href="/help/">list of Go mailing lists, forums, and places to chat</a>.
  251. </p>
  252. <p>
  253. Report bugs either by running “<b><code>go</code> <code>bug</code></b>”, or
  254. manually at the <a href="https://golang.org/issue">Go issue tracker</a>.
  255. </p>