github.com/yukk001/go1.10.8@v0.0.0-20190813125351-6df2d3982e20/doc/install.html (about)

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