[Golang] Set GOPATH on MAC

INexLin
Apr 23, 2022

--

Start terminal and type bellow line to edit .bash_profile:

~/.bash_profile; open ~/.bash_profile

if you got the error :

no such file or directory or .bash_profile does not exist

follow the bellow step to create .bash_profile:

  1. Type cd~/
  2. Type touch .bash_profile to create your new file.
  3. Type ~/.bash_profile:open ~/.bash_profile again

Paste bellow code to .bash_profile then save.

#GOPATH
export GOPATH={Your go path}
#GOBIN
export GOBIN=$PATH:$GOPATH/bin
#PATH
export PATH=$PATH:$GOBIN

Back to terminal, type bellow line to reload env setting

source ~/.bash_profile

now you can type go env to check the GOPATH

--

--