This content originally appeared on DEV Community and was authored by Jingtian Zhang
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
- install golang using brew
brew install go
- check the following commands
go env // check go env vars
which go // check which go
brew info go // very useful info here
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
#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
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
- timeout error (I am in China, so I need to configure a proxy for that)
- 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/
and cd into this directory and :
git clone https://github.com/golang/tools.git
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
This content originally appeared on DEV Community and was authored by Jingtian Zhang
Jingtian Zhang | Sciencx (2022-02-08T13:38:01+00:00) go config on mac. Retrieved from https://www.scien.cx/2022/02/08/go-config-on-mac/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.