gvm 配置
有了 gvm,Go 版本切换轻松自如。

A directional sign that I liked whilst in Southampton.  Sometimes it is the simple things that catch our eye. Photo by Nick Fewings on Unsplash

不知道从什么时候开始,Go 的版本也越来越多,多到我们针对不同的项目只能指定对应的 Go 版本才能正常运行。

今天推荐的就是 gvm 来管理本地多个 Go 语言版本。

Go Version Manager

  • Install/Uninstall Go versions with gvm install [tag] where tag is “60.3”, “go1”, “weekly.2011-11-08”, or “tip”
  • List added/removed files in GOROOT with gvm diff
  • Manage GOPATHs with gvm pkgset [create/use/delete] [name]. Use --local as name to manage repository under local path (/path/to/repo/.gvm_local).
  • List latest release tags with gvm listall. Use --all to list weekly as well.
  • Cache a clean copy of the latest Go source for multiple version installs.
  • Link project directories into GOPATH

安装 gvm

第一次安装 gvm 的前提时是系统先有一个 Go 版本。如果系统没有,我们可以先安装一个。

brew install go

通过命令安装 gvm:

bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)

注意:在执行之前可能需要安装:bison

安装 Go

现在安装 Go 版本就简单了多,可以根据需要安装对应的版本,如 1.23:

gvm install go1.23

我们可以看看系统上都有哪些 Go 版本。

❯ which go
/usr/local/go/bin/go
❯ go version
go version go1.24.1 darwin/arm64
❯ gvm list

gvm gos (installed)

   go1.23
   system
// 切换 Go 版本
❯ gvm use go1.23 --default
Now using version go1.23
❯ go version
go version go1.23.0 darwin/arm64
❯ which go
/Users/**/.gvm/gos/go1.23/bin/go

卸载 gvm

如题:

gvm implode

Mac OS X Requirements

按官方的说法,Mac 系统还需要安装下面几个插件。

xcode-select --install
brew update
brew install mercurial

因为本人一直使用 Mac 系统,所以所有的笔记都是基于 Mac 环境而言的。


最后修改于 2025-03-31