安装最新版如1.10.3
brew install go
unlink
brew unlink go
安装1.9.3
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/4ba973d04d167a990524f3d52c128c0c843d1931/Formula/go.rb
如何找到版本对应的rb
brew info go
得到rb地址拷贝到浏览器如
https://github.com/Homebrew/homebrew-core/commits/master/Formula/go.rb
找到对应版本,点击后面commit号,点击view,点击raw即可获取最终地址。
写个shell脚本顺便切换 GOROOT
#GOROOT should be an existing link
GOROOT=$GOROOT
ls $GOROOT
V=$1
echo "Switching to go $V"
brew unlink go
brew switch go $V
echo "Switching GOROOT"
rm $GOROOT
ln -s /usr/local/Cellar/go/$V/libexec $GOROOT
切换使用
switchgo.sh 1.9.3