2015/01/17

Setup Go in Windows and Mac

Some notes on how to setup the computer to get started with go language. Very simple notes. Installation notes for Mac are at the end

On Windows

  1. Installed it via the msi installer from the downloads page
  2. Open the command line (cmd.exe) and check everything is fine
    > go version
    go version go1.4 windows/386
    Go installer sets up GOROOT (although I think it is not needed to define it explicitly since the go tool can find it)
    > echo %GOROOT%
    C:\Go\
    
    We can also check other variables
    > go env GOOS
    windows
    
    > go env GOARCH
    386
    

  3. The only environment variable that needs to be set is GOPATH

    Add GOPATH as a new User Environment Variable, its value should be somewhere we are going to put all our go code, also it should not be the same as GOROOT .
    > echo %GOPATH%
    C:\Users\GuillermoIgnacio\Documents\go
    
    As explained in the docs, GOPATH directory needs to have 3 directories in it: src, pkg and bin
    cd %GOPATH%
    mkdir src
    mkdir pkg
    mkdir bin
    
  4. Optionally, we could add GOPATH\bin to our PATH so we can run executables easier after each time we use the install command: go install something

On Mac OS X

  1. Install it via homebrew
    brew install go
    
  2. Create a workspace. (The workspace is a directory with 3 subdirectories src, pkg and bin) so we can set $GOPATH variable in the next step. I created inside ~/Documents directory
    cd ~/Documents
    mkdir goworkspace
    cd goworkspace
    mkdir src
    mkdir pkg
    mkdir bin
    
  3. Set $GOPATH in ~/.bash_profile. Optionally we can add bin
    # Go stuff                                                                                                          
    export GOPATH="${HOME}/Documents/goworkspace"
    export PATH=$PATH:"${GOPATH}/bin"
    
  4. Also get go vet and go doc
    go get golang.org/x/tools/cmd/vet
    go get golang.org/x/tools/cmd/godoc
    
Done!. Now I am ready to start with hello world or a little library :)

0 comments :