github.com/fjballest/golang@v0.0.0-20151209143359-e4c5fe594ca8/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="https://golang.org/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="https://golang.org/dl/" target="_blank">Official binary
    19  distributions</a> are available for the FreeBSD (release 8-STABLE and above),
    20  Linux, Mac OS X (10.7 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 binary distributions 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 8-STABLE or later</td> <td>amd64</td> <td>Debian GNU/kFreeBSD not supported</td></tr>
    51  <tr><td>Linux 2.6.23 or later with glibc</td> <td>amd64, 386, arm</td> <td>CentOS/RHEL 5.x not supported; install from source for ARM</td></tr>
    52  <tr><td>Mac OS X 10.7 or later</td> <td>amd64</td> <td>use the clang or gcc<sup>&#8224;</sup> that comes with Xcode<sup>&#8225;</sup></td></tr>
    53  <tr><td>Windows XP 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><code>gcc</code> 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="https://golang.org/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  <h4 id="tarball_non_standard">Installing to a custom location</h4>
   110  
   111  <p>
   112  The Go binary distributions assume they will be installed in
   113  <code>/usr/local/go</code> (or <code>c:\Go</code> under Windows),
   114  but it is possible to install the Go tools to a different location.
   115  In this case you must set the <code>GOROOT</code> environment variable
   116  to point to the directory in which it was installed.
   117  </p>
   118  
   119  <p>
   120  For example, if you installed Go to your home directory you should add the
   121  following commands to <code>$HOME/.profile</code>:
   122  </p>
   123  
   124  <pre>
   125  export GOROOT=$HOME/go
   126  export PATH=$PATH:$GOROOT/bin
   127  </pre>
   128  
   129  <p>
   130  <b>Note</b>: <code>GOROOT</code> must be set only when installing to a custom
   131  location.
   132  </p>
   133  
   134  </div><!-- tarballInstructions -->
   135  
   136  <div id="darwinPackageInstructions">
   137  
   138  <h3 id="osx">Mac OS X package installer</h3>
   139  
   140  <p>
   141  <a href="https://golang.org/dl/">Download the package file</a>,
   142  open it, and follow the prompts to install the Go tools.
   143  The package installs the Go distribution to <code>/usr/local/go</code>.
   144  </p>
   145  
   146  <p>
   147  The package should put the <code>/usr/local/go/bin</code> directory in your
   148  <code>PATH</code> environment variable. You may need to restart any open
   149  Terminal sessions for the change to take effect.
   150  </p>
   151  
   152  </div><!-- darwinPackageInstructions -->
   153  
   154  <div id="windowsInstructions">
   155  
   156  <h3 id="windows">Windows</h3>
   157  
   158  <p class="hideFromDownload">
   159  The Go project provides two installation options for Windows users
   160  (besides <a href="/doc/install/source">installing from source</a>):
   161  a zip archive that requires you to set some environment variables and an
   162  MSI installer that configures your installation automatically.
   163  </p>
   164  
   165  <div id="windowsInstallerInstructions">
   166  
   167  <h4 id="windows_msi">MSI installer</h4>
   168  
   169  <p>
   170  Open the <a href="https://golang.org/dl/">MSI file</a>
   171  and follow the prompts to install the Go tools.
   172  By default, the installer puts the Go distribution in <code>c:\Go</code>.
   173  </p>
   174  
   175  <p>
   176  The installer should put the <code>c:\Go\bin</code> directory in your
   177  <code>PATH</code> environment variable. You may need to restart any open
   178  command prompts for the change to take effect.
   179  </p>
   180  
   181  </div><!-- windowsInstallerInstructions -->
   182  
   183  <div id="windowsZipInstructions">
   184  
   185  <h4 id="windows_zip">Zip archive</h4>
   186  
   187  <p>
   188  <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>).
   189  </p>
   190  
   191  <p>
   192  If you chose a directory other than <code>c:\Go</code>,
   193  you must set the <code>GOROOT</code> environment variable to your chosen path.
   194  </p>
   195  
   196  <p>
   197  Add the <code>bin</code> subdirectory of your Go root (for example, <code>c:\Go\bin</code>) to your <code>PATH</code> environment variable.
   198  </p>
   199  
   200  </div><!-- windowsZipInstructions -->
   201  
   202  <h4 id="windows_env">Setting environment variables under Windows</h4>
   203  
   204  <p>
   205  Under Windows, you may set environment variables through the "Environment
   206  Variables" button on the "Advanced" tab of the "System" control panel. Some
   207  versions of Windows provide this control panel through the "Advanced System
   208  Settings" option inside the "System" control panel.
   209  </p>
   210  
   211  </div><!-- windowsInstructions -->
   212  
   213  
   214  <h2 id="testing">Test your installation</h2>
   215  
   216  <p>
   217  Check that Go is installed correctly by setting up a workspace
   218  and building a simple program, as follows.
   219  </p>
   220  
   221  <p>
   222  Create a directory to contain your <a href="code.html#Workspaces">workspace</a>,
   223  <code>$HOME/work</code> for example, and set the <code>GOPATH</code> environment
   224  variable to point to that location.
   225  </p>
   226  
   227  <pre>
   228  $ <b>export GOPATH=$HOME/work</b>
   229  </pre>
   230  
   231  <p>
   232  You should put the above command in your shell startup script
   233  (<code>$HOME/.profile</code> for example) or, if you use Windows,
   234  follow the <a href="#windows_env">instructions above</a> to set the
   235  <code>GOPATH</code> environment variable on your system.
   236  </p>
   237  
   238  <p>
   239  Next, make the directories <code>src/github.com/user/hello</code> inside your
   240  workspace (if you use GitHub, substitute your user name for <code>user</code>),
   241  and inside the <code>hello</code> directory create a file named <code>hello.go</code>
   242  with the following contents:
   243  </p>
   244  
   245  <pre>
   246  package main
   247  
   248  import "fmt"
   249  
   250  func main() {
   251      fmt.Printf("hello, world\n")
   252  }
   253  </pre>
   254  
   255  <p>
   256  Then compile it with the <code>go</code> tool:
   257  </p>
   258  
   259  <pre>
   260  $ <b>go install github.com/user/hello</b>
   261  </pre>
   262  
   263  <p>
   264  The above command will put an executable command named <code>hello</code> 
   265  (or <code>hello.exe</code>) inside the <code>bin</code> directory of your workspace.
   266  Execute the command to see the greeting:
   267  </p>
   268  
   269  <pre>
   270  $ <b>$GOPATH/bin/hello</b>
   271  hello, world
   272  </pre>
   273  
   274  <p>
   275  If you see the "hello, world" message then your Go installation is working.
   276  </p>
   277  
   278  <p>
   279  Before rushing off to write Go code please read the
   280  <a href="/doc/code.html">How to Write Go Code</a> document,
   281  which describes some essential concepts about using the Go tools.
   282  </p>
   283  
   284  
   285  <h2 id="uninstall">Uninstalling Go</h2>
   286  
   287  <p>
   288  To remove an existing Go installation from your system delete the
   289  <code>go</code> directory. This is usually <code>/usr/local/go</code>
   290  under Linux, Mac OS X, and FreeBSD or <code>c:\Go</code>
   291  under Windows.
   292  </p>
   293  
   294  <p>
   295  You should also remove the Go <code>bin</code> directory from your
   296  <code>PATH</code> environment variable.
   297  Under Linux and FreeBSD you should edit <code>/etc/profile</code> or
   298  <code>$HOME/.profile</code>.
   299  If you installed Go with the <a href="#osx">Mac OS X package</a> then you
   300  should remove the <code>/etc/paths.d/go</code> file.
   301  Windows users should read the section about <a href="#windows_env">setting
   302  environment variables under Windows</a>.
   303  </p>
   304  
   305  
   306  <h2 id="help">Getting help</h2>
   307  
   308  <p>
   309  For real-time help, ask the helpful gophers in <code>#go-nuts</code> on the
   310  <a href="http://freenode.net/">Freenode</a> IRC server.
   311  </p>
   312  
   313  <p>
   314  The official mailing list for discussion of the Go language is
   315  <a href="//groups.google.com/group/golang-nuts">Go Nuts</a>.
   316  </p>
   317  
   318  <p>
   319  Report bugs using the
   320  <a href="//golang.org/issue">Go issue tracker</a>.
   321  </p>