Getting Started - The Go Programming Language

Embed Size (px)

Citation preview

  • 7/30/2019 Getting Started - The Go Programming Language

    1/4

    Documents References Packages The Project Help Play

    Send Feedback

    Getting Started

    Download the Go distributionSystem requirementsInstall the Go tools

    FreeBSD, Linux, Mac OS X and NetBSD tarballs

    Mac OS X package installer

    Windows

    Test your installationSet up your work environmentWhat's nextCommunity resources

    Download the Go distribution

    Download GoClick here to visit the

    downloads page

    Click the link above to visit the Go project's downloads page and select the binarydistribution that matches your operating system and processor architecture.

    Official binary distributions are available for the FreeBSD, Linux, Mac OS X (SnowLeopard, Lion, and Mountain Lion), NetBSD, and Windows operating systems andthe 32-bit (386) and 64-bit (amd64) x86 processor architectures.

    If a binary distribution is not available for your combination of operating system andarchitecture you may want to try installing from source or installing gccgo instead ofgc.

    System requirements

    The gc compiler supports the following operating systems and architectures. Pleaseensure your system meets these requirements before proceeding. If your OS orarchitecture is not on the list, it's possible that gccgo might support your setup; seeSetting up and using gccgo for details.

    Operating system Architectures Notes

    FreeBSD 7 or lateramd64, 386,arm

    Debian GNU/kFreeBSD not supported;FreeBSD/ARM needs FreeBSD 10 or later

    Linux 2.6.23 or amd64, 386, CentOS/RHEL 5.x not supported; no binary

    Search

    http://golang.org/doc/install/gccgohttp://golang.org/doc/install/gccgohttp://code.google.com/p/go/downloadshttp://code.google.com/p/go/downloadshttp://code.google.com/p/go/downloadshttp://code.google.com/p/go/downloadshttp://golang.org/doc/http://golang.org/doc/http://golang.org/doc/http://golang.org/ref/http://golang.org/pkg/http://golang.org/project/http://golang.org/help/http://play.golang.org/http://golang.org/doc/http://golang.org/ref/http://golang.org/pkg/http://golang.org/project/http://golang.org/help/http://play.golang.org/http://golang.org/doc/install/gccgohttp://golang.org/doc/install/gccgohttp://golang.org/doc/install/sourcehttp://code.google.com/p/go/downloadshttp://code.google.com/p/go/downloadshttp://play.golang.org/http://golang.org/help/http://golang.org/project/http://golang.org/pkg/http://golang.org/ref/http://golang.org/doc/
  • 7/30/2019 Getting Started - The Go Programming Language

    2/4

    later with glibc arm distribution for ARM yet

    Mac OS X10.6/10.7

    amd64, 386 use the gcc that comes with Xcode

    Windows 2000 orlater

    amd64, 386 use mingw gcc; cygwin or msys is not needed

    NetBSD 6 or later amd64, 386

    gcc is required only if you plan to use cgo.You only need to install the command line tools for Xcode. If you have alreadyinstalled Xcode 4.3+, you can install it from the Components tab of the Downloadspreferences panel.

    Install the Go tools

    The Go binary distributions assume they will be installed in /usr/local/go (or c:\Gounder Windows), but it is possible to install them in a different location. If you do this,

    you will need to set the GOROOT environment variable to that directory when using theGo tools.

    For example, if you installed Go to your home directory you should add the followingcommands to $HOME/.profile:

    export GOROOT=$HOME/goexport PATH=$PATH:$GOROOT/bin

    Windows users should read the section about setting environment variables underWindows.

    FreeBSD, Linux, Mac OS X and NetBSD tarballs

    If you are upgrading from an older version of Go you must first remove the existingversion from /usr/local/go:

    rm -r /usr/local/go

    Extract the archive into /usr/local, creating a Go tree in /usr/local/go. Forexample:

    tar -C /usr/local -xzf go1.1.linux-amd64.tar.gz

    The name of the archive may differ, depending on the version of Go you areinstalling and your system's operating system and processor architecture.

    (Typically these commands must be run as root or through sudo.)

    Add /usr/local/go/bin to the PATH environment variable. You can do this by adding

    http://code.google.com/p/go/downloads/list?q=OpSys-FreeBSD+OR+OpSys-Linux+OR+OpSys-OSX+OR+OpSys-NetBSD+Type-Archivehttp://developer.apple.com/Xcode/http://golang.org/cmd/cgo
  • 7/30/2019 Getting Started - The Go Programming Language

    3/4

    this line to your /etc/profile (for a system-wide installation) or $HOME/.profile:

    export PATH=$PATH:/usr/local/go/bin

    Mac OS X package installer

    Open the package file and follow the prompts to install the Go tools. The packageinstalls the Go distribution to /usr/local/go.

    The package should put the /usr/local/go/bindirectory in your PATH environmentvariable. You may need to restart any open Terminal sessions for the change to takeeffect.

    Windows

    The Go project provides two installation options for Windows users (besides

    installing from source): a zip archive that requires you to set some environmentvariables and an experimental MSI installer that configures your installationautomatically.

    Zip archive

    Extract the zip file to the directory of your choice (we suggest c:\Go).

    If you chose a directory other than c:\Go, you must set the GOROOT environmentvariable to your chosen path.

    Add the bin subdirectory of your Go root (for example, c:\Go\bin) to your PATHenvironment variable.

    MSI installer (experimental)

    Open the MSI file and follow the prompts to install the Go tools. By default, theinstaller puts the Go distribution in c:\Go.

    The installer should put the c:\Go\bin directory in your PATH environment variable.You may need to restart any open command prompts for the change to take effect.

    Setting environment variables under Windows

    Under Windows, you may set environment variables through the "EnvironmentVariables" button on the "Advanced" tab of the "System" control panel. Someversions of Windows provide this control panel through the "Advanced SystemSettings" option inside the "System" control panel.

    Test your installation

    Check that Go is installed correctly by building a simple program, as follows.

    http://code.google.com/p/go/downloads/list?q=OpSys-Windows+Type%3DInstallerhttp://code.google.com/p/go/downloads/list?q=OpSys-Windows+Type%3DArchivehttp://golang.org/doc/install/sourcehttp://code.google.com/p/go/downloads/list?q=OpSys-OSX+Type-Installer
  • 7/30/2019 Getting Started - The Go Programming Language

    4/4

    Create a file named hello.go and put the following program in it:

    package main

    import "fmt"

    func main() {

    fmt.Printf("hello, world\n")}

    Then run it with the go tool:

    $ go run hello.gohello, world

    If you see the "hello, world" message then your Go installation is working.

    Set up your work environment

    The document How to Write Go Code explains how to set up a work environment inwhich to build and test Go code.

    What's next

    Start by taking A Tour of Go.

    Build a web application by following the Wiki Tutorial.

    Read Effective Go to learn about writing idiomatic Go code.

    For the full story, consult Go's extensive documentation.

    Subscribe to the golang-announce mailing list to be notified when a new stableversion of Go is released.

    Community resources

    For real-time help, there may be users or developers on #go-nuts on the FreenodeIRC server.

    The official mailing list for discussion of the Go language is Go Nuts.

    Bugs should be reported using the Go issue tracker.

    Build version go1.1.2.Except as noted, the content of this page is licensed under the Creative Commons Attribution 3.0

    License, and code is licensed under a BSD license.

    http://golang.org/LICENSEhttp://code.google.com/policies.html#restrictionshttp://code.google.com/p/go/issues/listhttp://groups.google.com/group/golang-nutshttp://freenode.net/http://groups.google.com/group/golang-announcehttp://golang.org/doc/http://golang.org/doc/effective_go.htmlhttp://golang.org/doc/articles/wiki/http://code.google.com/p/go-tour/http://golang.org/doc/code.html