Last active
September 21, 2024 12:31
-
-
Save vsouza/77e6b20520d07652ed7d to your computer and use it in GitHub Desktop.
Golang setup in Mac OSX with HomeBrew. Set `GOPATH` and `GOROOT` variables in zshell, fish or bash.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set variables in .bashrc file | |
# don't forget to change your path correctly! | |
export GOPATH=$HOME/golang | |
export GOROOT=/usr/local/opt/go/libexec | |
export PATH=$PATH:$GOPATH/bin | |
export PATH=$PATH:$GOROOT/bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set variables in .zshrc file | |
# don't forget to set path correctly! | |
export GOPATH=$HOME/golang | |
export GOROOT=/usr/local/opt/go/libexec | |
export PATH=$PATH:$GOPATH/bin | |
export PATH=$PATH:$GOROOT/bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set variables in config.fish file | |
# don't forget to set path correctly! | |
# GOLANG configurations | |
set -x GOPATH $HOME/golang | |
set -x GOROOT /usr/local/opt/go/libexec | |
set PATH $GOPATH/bin $GOROOT/bin $PATH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo "Please enter your golang path (ex: $HOME/golang) :" | |
read gopath | |
echo "Please enter your github username (ex: vsouza) :" | |
read user | |
mkdir $gopath | |
mkdir -p $gopath/src/github.com/$user | |
export GOPATH=$gopath | |
export GOROOT=/usr/local/opt/go/libexec | |
export PATH=$PATH:$GOPATH/bin | |
export PATH=$PATH:$GOROOT/bin | |
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" | |
brew update | |
brew install go | |
brew install git | |
go get golang.org/x/tools/cmd/godoc | |
go get golang.org/x/tools/cmd/vet |
better get the prefix via brew --prefix
Anyone on Apple silicon will need to instead use the updated prefix for Homebrew, i.e.
/opt/homebrew
instead of/usr/local
. The remainder of the paths will be the same.The
.zshrc
example would therefore be:# Set variables in .zshrc file # don't forget to set path correctly! export GOPATH=$HOME/golang export GOROOT=/opt/homebrew/opt/go/libexec export PATH=$PATH:$GOPATH/bin export PATH=$PATH:$GOROOT/bin
👍🏼
yeah I used go env first, and then used this as a guide to modify my .zshrc
, trusting that go env
was correct. Annoyingly GOBIN was ''
though, so I'm not 100% sure the stability of homebrew golang recipe.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@javaducky thanks man - super helpful!