Install Go on Mac (with homebrew)

Jim Kang
1 min readJan 2, 2020

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"

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.

Extra: Go Version Manager (GVM)

If you wish To run multiple version of go, you might want to install this (ref here)

bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)

List All Go Version

gvm listall

Use GVM to install GO (pick a version from above list)

gvm install go1.16.2
gvm use go1.16.2 [--default]

--

--

Jim Kang

love writing bit sized programming memo, acoustic guitarist, proud daddy of 5 and great listener (to my kids)