gvm - Go版本管理神器

版本管理基本成了各个语言的标配,最有名的自然是 nodejsnvmgvm 其实也是借鉴学习 nvm 开发的一款工具; 直接放上仓库链接 https://github.com/moovweb/gvm

安装:

    bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
    # 如果使用的zsh可以替换为:
    zsh < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)

    # 注意不同系统下有一些依赖:
    # Mac
    xcode-select --install
    brew update
    brew install mercurial
    # Ubunt
    sudo apt-get install curl git mercurial make binutils bison gcc build-essential
    # Redhat/Centos
    sudo yum install curl
    sudo yum install git
    sudo yum install make
    sudo yum install bison
    sudo yum install gcc
    sudo yum install glibc-devel

基本使用:

    > gvm
    Usage: gvm [command]

    Description:
    GVM is the Go Version Manager

    Commands:
    version    - print the gvm version number 
    get        - gets the latest code (for debugging)
    use        - select a go version to use (--default to set permanently)
    diff       - view changes to Go root
    help       - display this usage text
    implode    - completely remove gvm
    install    - install go versions
    uninstall  - uninstall go versions
    cross      - install go cross compilers
    linkthis   - link this directory into GOPATH
    list       - list installed go versions
    listall    - list available versions
    alias      - manage go version aliases
    pkgset     - manage go packages sets
    pkgenv     - edit the environment for a package set
    # 常用命令
    gvm listall # 查看所有可以安装的版本
    gvm install go1.20 # 安装go1.20版本
    gvm use go1.20  # 使用go1.20版本,注意打开新的终端使路径生效

注意事项

  1. 首次安装Go1.5+版本需要安装有Go1.4以下版本

Go1.5 后实现了自编译,即用Go语言实现了Golang编译器,所以Go1.5以后的版本安装需要有Go环境,才能编译Go的源码,所以要先安装下Go1.4版本

  1. Go高版本安装时可能会依赖使用低1~2版本的Go环境编译最新版,例如当我电脑没有安装Go1.17时,直接安装Go1.20会提示需要Go1.17环境,安装之即可 Building Go cmd/dist using /usr/local/Cellar/go/1.16/libexec. (go1.16 darwin/amd64) found packages main (build.go) and building_Go_requires_Go_1_17_13_or_later (notgo117.go) in /Users/ipanda/.gvm/gos/go1.20/src/cmd/dist

Posts in this Series