Install Go

brew install go

Setup Workspace

It’s considered best practice to use $HOME/go location for your workspace, so let’s do that!

mkdir -p $HOME/go/{bin,src,pkg}

We created two important folders bin and src that’ll be used for GO

Setup Environment

You have to to add to .bashrc or .zshrc (if you’re using zsh) with the following environment variables. (vi ~/.bashrc or vi ~/.zshrc)

export GOPATH=$HOME/go
export GOROOT="$(brew --prefix golang)/libexec"
export PATH="$PATH:${GOPATH}/bin:${GOROOT}/bin"
reload the settings with source $HOME/.bashrc (or .zshrc )

Thats all!

How to uninstall a old Go version?

I had some trouble with old installation of Go. Therefore I have to to delete first the old version before installing with brew.

If you have installed from source:

rm -rf /usr/local/go
rm -rf $(echo $GOPATH)

Then, remove all entries related to go i.e. GOROOT, GOPATH from ~/.bash_profile or .zshrc and run

source ~/.bash_profile