Today I bring a short article about the Go version manager gvm. Without further ado, let's start the installation.

Install

If you are using mac, mac needs to install xcode-select first. Students who have not installed it can execute the installation according to the following commands. I will not explain too much here.

xcode-select --install
brew update
brew install mercurial

According to the instructions on github, we download gvm-installer according to the command line for installation. Students who have problems with terminal execution can also go to the gvm-installer [1] page for clone installation.

$bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
Cloning from https://github.com/moovweb/gvm.git to /Users/admin/.gvm
Created profile for existing install of Go at "/opt/homebrew/Cellar/go/1.18.1/libexec"
Installed GVM v1.0.22

Please restart your terminal session or to get started right away run
 `source /Users/admin/.gvm/scripts/gvm`

Next, in order to make gvm take effect, you need to execute the source /Users/admin/.gvm/scripts/gvmcommand prompted above. After the execution, you can use gvm in the new terminal to switch the version of control go.

use

Once installed, let's take a brief look at some of the functions supported by gvm. Now you can call the help option of gvm.

$gvm help
Usage: gvm [command]

Description:
  GVM is the Go Version Manager

Commands:
  version    - print the gvm version number # 查看gvm的版本
  get        - gets the latest code (for debugging) # 获取最新的代码(一般为了调试)
  use        - select a go version to use (--default to set permanently) # 选择使用的Go版本 (--default 可以永久设置)
  diff       - view changes to Go root # 查看Go root中的变更
  help       - display this usage text 
  implode    - completely remove gvm # 完全删除 gvm 和所有已安装的 Go 版本和包
  install    - install go versions # 安装某个版本的Go
  uninstall  - uninstall go versions # 卸载某个版本的Go
  cross      - install go cross compilers # 安装跨平台Go编译器
  linkthis   - link this directory into GOPATH # 将项目路径链接到GOPATH中
  list       - list installed go versions # 罗列已经安装的Go版本列表
  listall    - list available versions # 罗列可用的Go版本
  alias      - manage go version aliases # 管理Go版本别名
  pkgset     - manage go packages sets # 管理Go包的设置
  pkgenv     - edit the environment for a package set # 编辑Go包集合的环境

Simple use of gvm

First gvm listalllook at the current Go version list through the command, as follows, the list is too long, here the version list of Go1-15 is omitted, it can be seen that the latest Go1.19 beta and several rc versions. Then let's do an example by downloading the rc version of Go1.19.

$gvm listall

gvm gos (available)

   go1
   ...
   go1.16
   go1.16beta1
   go1.16rc1
   go1.16.1
   go1.16.2
   go1.16.3
   go1.16.4
   go1.16.5
   go1.16.6
   go1.16.7
   go1.16.8
   go1.16.9
   go1.16.10
   go1.16.11
   go1.16.12
   go1.16.13
   go1.16.14
   go1.16.15
   go1.17
   go1.17beta1
   go1.17rc1
   go1.17rc2
   go1.17.1
   go1.17.2
   go1.17.3
   go1.17.4
   go1.17.5
   go1.17.6
   go1.17.7
   go1.17.8
   go1.17.9
   go1.17.10
   go1.17.11
   go1.17.12
   go1.18
   go1.18beta1
   go1.18beta2
   go1.18rc1
   go1.18.1
   go1.18.2
   go1.18.3
   go1.18.4
   go1.19beta1
   go1.19rc1
   go1.19rc2
   release.r56
   release.r57
   release.r58
   release.r59
   release.r60
   release.r57.1
   release.r57.2
   release.r58.1
   release.r58.2
   release.r60.1
   release.r60.2
   release.r60.3

Install a Go version

Let's take a look at the current version of Go. Xiaotu uses the version of go1.18.1 here.

$go version
go version go1.18.1 darwin/arm64

Install an rc1 version of the latest Go1.19.

$gvm install go1.19rc1
Installing go1.19rc1...
 * Compiling...
go1.19rc1 successfully installed!

version switch

Next, let's switch the downloaded go version, which gvm use versioncan be switched by using it here.

$gvm use go1.19rc1
Now using version go1.19rc1

How to switch permanently? If you add --defaultit, you can set it permanently. You can execute it by creating a new terminal to go versionverify whether the Go version is completely switched.

$gvm use go1.19rc1 --default
Now using version go1.19rc1

Then we use to go versioncheck the currently used Go version, it seems that the switch is successful. Then you can switch Go versions back and forth freely. Especially useful when debugging problematic code with different Go versions.

$go version
go version go1.19rc1 darwin/arm64

Upgrade Troubleshooting

If the status of the gvm file is disordered or other problems occur during the Go upgrade, you can rm -rf ~/.gvmdelete gvm to fix the problem by executing.

summary

Today's short article mainly introduces the use of a gvm, and I hope it will be helpful to you. For more details, please refer to gvm [2] . In addition, the webmaster wrote an article about upgrading the Go version before, mainly talking about the use of goup [ 3] to manage the Go version. Xiaotu will not be introduced here, 😆, interested students can check and finally found a tool that I like to install and manage the Go version .

References

[1]

gvm-installer: https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer

[2]

gvm: https://github.com/moovweb/gvm

[3]

goup: https://github.com/owenthereal/goup


Recommended in the past

picture

My name is polarisxu. I graduated from Peking University with a master's degree. I have worked in well-known Internet companies such as 360 and have more than 10 years of experience in technology development and architecture! In 2012, I came into contact with the Go language and created the Go language Chinese website! Author of " Go Language Programming Journey ", open source book " Go Language Standard Library ", etc.

Insist on exporting technologies (including Go, Rust and other technologies), workplace experience and entrepreneurial insights! Welcome to follow "polarisxu" to grow together! Also welcome to add my WeChat friends to communicate: gopherstudio