- Install GVM
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)Place this line in ~/.zshrc or ~/.bashrc to source the GVM directory
[[ -s "$HOME/.gvm/scripts/gvm" ]] && source "$HOME/.gvm/scripts/gvm"Reopen your terminal or run source $HOME/.gvm/scripts/gvm
- Install Go
gvm install go1.4- Tell GVM which Go version to use
gvm use go1.4Read about the Go command from the Go documentation: https://golang.org/doc/articles/go_command.html
- Set your $GOPATH accordingly.
mygocan be whatever name you wish to choose for your workspace
$ mkdir $HOME/mygo
$ export GOPATH=$HOME/mygo- Run your first program
$ mkdir -p $GOPATH/src/github.com/user
$ mkdir $GOPATH/src/github.com/user/hello
$ cd $GOPATH/src/github.com/user/helloNext, create a file named hello.go inside the hello directory, containing the following Go code.
package main
import "fmt"
func main() {
fmt.Printf("Hello, world.\n")
}Now you can build and install that program with the go tool:
$ go installThis command builds the hello command, producing an executable binary. It then installs that binary to the workspace's bin directory as hello
$ $GOPATH/bin/hello
Hello, world.Once you have added $GOPATH/bin to your PATH, just type the binary name:
$ hello
Hello, world.