Download the latest installer from go. http://golang.org/dl/
Using Homebrew:
brew update
brew install go
Download the latest installer from go. http://golang.org/dl/
Download the latest installer from go. http://golang.org/dl/
Using APT
sudo apt-get update
sudo apt-get install golang
Note: This can leave you with an old version of go as they don't update the package manager as timely as they should
The GOPATH environment variable specifies the location of your workspace. It is likely the only environment variable you'll need to set when developing Go code.
To get started, create a workspace directory and set GOPATH accordingly. Your workspace can be located wherever you like, but we'll use $HOME/go in this document. Note that this must not be the same path as your Go installation.
NOTE: This is only necessary if the method of installation used above did NOT do this.
mkdir $HOME/go
export GOPATH=$HOME/go
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: It's very likely you will need to reboot for this variable to take effect.
For convenience, add the workspace's bin subdirectory to your PATH:
NOTE: If you used an installer, you typically do not need to do this step.
export PATH=$PATH:$GOPATH/bin
Go to the Control Panel > System > Advanced Tab > Environment Variables.
Under System variables, select "Path" from the box, and click "edit". Add ;C:\Go\bin
to the value and click ok.
Check that Go is installed correctly by building a simple program, as follows.
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.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
Go has the ability to import remote packages via revision control systems with the go get
command. To ensure that you can retrieve any remote package, be sure to install the following rcs software to your system.
go vet
and go doc
are now part of the go.tools sub repo:
golang.org/doc/go1.2#go_tools_godoc
To get go vet
and go doc
, from a console run:
go get code.google.com/p/go.tools/cmd/godoc
go get code.google.com/p/go.tools/cmd/vet
Troubleshooting
If you are on a mac and getting permission denied and used the package installer to install go, you may need to run this command to get the tools installed:
sudo chown -R $USER /usr/local/go