Skip to main content
  1. Blog/

Install Go on Mac with Brew

·1 min
Christian Köhler
Author
Christian Köhler
Home Automation, IoT, Cloud, DevOps, 3D Printers

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

That’s all!

How to uninstall an old Go version?
#

I had some trouble with an old installation of Go. Therefore I had 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