背景
在 MAC 上把 Go 版本升级到1.13后, 在终端上执行 go 命令体现得比拟奇怪,很不习惯, 想回滚到之前稳固版本。
解决
Go 版本的升降级算是一件也比拟麻烦的事件了,1.12版本之前,装置完 Go 之后, 须要配置 GOROOT 和 GOPATH 等, 跟之前一堆 Go 管理工具像 glide 和 vendor 有得一拼(还好当初官网 go modules 逐步将包治理入口也做了收敛)。
这里收集和整顿了 Go 版本升降级的两个办法。
办法一
装置想要的 Go 版本, 并做链接
查看以后 Go 版本:
$ go versiongo version go1.13 darwin/amd64
通过 Homebrew 装置想要的 Go 版本, 版本列表详见:Homebrew Formulae/go
$ brew install go@1.12Updating Homebrew...==> Auto-updated Homebrew!Updated 2 taps (homebrew/core and homebrew/cask).==> Updated Formulaeopenssl@1.1 ✔==> Downloading https://homebrew.bintray.com/bottles/go@1.12-1.12.9.mojave.bottle.tar.gzAlready downloaded: /Users/username/Library/Caches/Homebrew/downloads/6392e5d3faa67a6132d43699cf470ecc764ba42f38cce8cdccb785c587b8bda8--go@1.12-1.12.9.mojave.bottle.tar.gz==> Pouring go@1.12-1.12.9.mojave.bottle.tar.gz==> Caveatsgo@1.12 is keg-only, which means it was not symlinked into /usr/local,because this is an alternate version of another formula.If you need to have go@1.12 first in your PATH run: echo 'export PATH="/usr/local/opt/go@1.12/bin:$PATH"' >> ~/.zshrc==> Summary /usr/local/Cellar/go@1.12/1.12.9: 9,819 files, 452.8MB
勾销链接以后装置的 Go 版本:
$ brew unlink goUnlinking /usr/local/Cellar/go/1.13... 3 symlinks removed
链接到自定义的 Go 版本:
$ brew link --force go@1.12Linking /usr/local/Cellar/go@1.12/1.12.9... 3 symlinks createdIf you need to have this software first in your PATH instead consider running: echo 'export PATH="/usr/local/opt/go@1.12/bin:$PATH"' >> ~/.zshrc
因为通过 Homebrew 装置特定版本的包并不会做主动链接, 所有须要须要通过
--force
手动链接。查看是否装置降级(或降级)胜利:
$ go versiongo version go1.12.9 darwin/amd64
办法二(举荐)
在 Github 上找到一个 Go 版本的降级脚本:update-golang, 能够轻松地拉取和装置新的 Go 版本,根本不会对系统配置做什么批改, 同时提供 remove
办法, 一键卸载 Go 环境。
装置指定版本的 Go:
$ sudo RELEASE=1.13 ./update-golang.sh
卸载 Go 环境:
$ sudo ./update-golang.sh remove
其余食用形式, 查看 README 文档