DEV Community

Jingtian Zhang
Jingtian Zhang

Posted on

go config on mac

it is kinda painful to configure go and its tools on vscode on mac for the first time and second time (if you did not record what you did for the first time ...).

here are steps

  1. install golang using brew
brew install go

Enter fullscreen mode Exit fullscreen mode
  1. check the following commands
go env      // check go env vars
which go    // check which go
brew info go  // very useful info here

Enter fullscreen mode Exit fullscreen mode

till here everything should work fine, but I used oh-my-zsh (which is just based on zsh, so you just need to configure stuff on .zshrc file), so I configure my .zshrc file

cd 
nano ~/.zshrc
Enter fullscreen mode Exit fullscreen mode
#GOROOT
export GOROOT=/opt/homebrew/Cellar/go/1.17.5/libexec

#GOPATH WORKSPACE
export GOPATH=$HOME/go

#GOROOT BIN
export PATH=$PATH:$GOROOT/bin

#GOPATH BIN
export PATH=$PATH:$GOPATH/bin

Enter fullscreen mode Exit fullscreen mode

you see that GOROOT info can be found from the previous step brew info go, and do not forget to add libexec after it, so it will become whatever I show above.

till here I decide to download a golang project and enter vscode to edit some go files, but I notice there are missing go-tools to install, and somehow they keep reporting errors

  1. timeout error (I am in China, so I need to configure a proxy for that)
  2. not found error (go tools not found issue explained below), can also check here

you can fix it by

mkdir -p $GOPATH/src/golang.org/x/

Enter fullscreen mode Exit fullscreen mode

and cd into this directory and :

git clone https://github.com/golang/tools.git

Enter fullscreen mode Exit fullscreen mode

after this go tools can be successfully implemented, and then you can go back to vscode and follow the popup and click install or install all to install go tools, and they should be good

Top comments (0)