How to Install Go on Mac (with homebrew)
#Go
#Golang
#homebrew
#GVM
Published on Sep 2, 2021
·1 min read
Install homebrew (skip if you already did)Link to this heading
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Update and Install GoLink to this heading
brew update && brew install golang
Setup WorkspaceLink to this heading
It’s considered good 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 EnvironmentLink to this heading
We’ll need to add to .bashrc or .zshrc (if you’re using zsh) with the following info. (Ex: nano ~/.bashrc)
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 )
Feel free to start any project (make new folder) under ~/go/src and go from there.
Bonus Point : Install Go Version Manager (GVM)Link to this heading
if you would like to run several versions of GO
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
List all GO versionsLink to this heading
gvm listall
Install specific version of GOLink to this heading
gvm install go1.16.2
Select default version of GO to useLink to this heading
gvm use go1.16.2 [--default]