Skip to content

Latest commit

 

History

History
74 lines (52 loc) · 1.58 KB

setup-environment.md

File metadata and controls

74 lines (52 loc) · 1.58 KB

Setting Up Your Go Environment

  1. 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

  1. Install Go
gvm install go1.4
  1. Tell GVM which Go version to use
gvm use go1.4

Read about the Go command from the Go documentation: https://golang.org/doc/articles/go_command.html

  1. Set your $GOPATH accordingly. mygo can be whatever name you wish to choose for your workspace
$ mkdir $HOME/mygo
$ export GOPATH=$HOME/mygo
  1. Run your first program
$ mkdir -p $GOPATH/src/github.com/user
$ mkdir $GOPATH/src/github.com/user/hello
$ cd $GOPATH/src/github.com/user/hello

Next, 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 install

This 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.