Install Brew (skip if you already did)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Add HomeBrew to PATH (skip if you already did, I am using zsh)
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
Update & Install Go
brew update&& brew install golang
Test Installed Go
go version
That’s it!
(As of GO 1.11, you don’t need to setup workspace anymore)
(Obsolete) 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
(Obsolete) Setup Environment
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"