Installing Go is a very simple process, but if you want the entire set of tools, it can be more complicated.
We wil cover just the basic installation in this quick start guide.
Go can run natively on most operating systems, including Windows, Mac, and Linux.
The quickest way to install on the mac is to use HomeBrew
.
If you don't have HomeBrew
you can install it easily with this line:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Once it is insatlled, simply run these commands:
brew update
brew install go
You can download installers for all operating systems (Including Mac), including Windows, here:
Go requires you to set the GOPATH
for the compiler to work properly.
mkdir $HOME/go
export GOPATH=$HOME/go
In depth details on `GOPATH can be found https://code.google.com/p/go-wiki/wiki/GOPATH.
From a command prompt:
mkdir "%USERPROFILE%\go"
Go to the Control Panel > System > Advanced Tab > Environment Variables.
Add a new User Variable (not a system variable)
Variable name: GOPATH Variable value: %USERPROFILE%\go
NOTE: You may need to reboot for this variable to take effect.
Ok, now it's time to create our first go program. To do so, create a file called hello.go
with your
preferred text editor, and add the following content:
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}
To run it, use the following command:
$ go run hello.go
hello, world
If you see the "hello, world" message then your Go installation is working.
NOTE: This was taken directly from golang.org/doc/install
Congratulations, you can now write more Go code!