After mastering this trick, you don’t have to worry about the management of the Go version

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 a mac, you need to install xcode-select first on the mac. Students who have not installed it can execute the installation according to the following commands. I won’t explain too much here.

xcode-select --install
brew update
brew install mercurial

According to the instructions above on github, we download gvm-installer according to the command line and install it here. Students who have problems with terminal execution can also go to the gvm-installer[1] page to perform 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 command prompted above source /Users/admin/.gvm/scripts/gvm. After the execution, you can use gvm to switch and control the version of go in the new terminal.

use

After the installation is complete, 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, the version list of Go1-15 is omitted here, it can be seen that the latest version is 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 first look at the Go version currently in use. Xiaotu uses go1.18.1 version 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 switching

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? It can be permanently set by adding it --default, and can be executed through a new terminal go versionto verify whether the Go version has been completely switched.

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

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

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

Troubleshooting upgrade issues

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

Guess you like

Origin blog.csdn.net/m0_72650596/article/details/126180470