• go版本升降级


    背景

    在 MAC 上把 Go 版本升级到1.13后, 在终端上执行 go 命令表现得比较奇怪,很不习惯, 想回滚到之前稳定版本。

    解决

    Go 版本的升降级算是一件也比较麻烦的事情了,1.12版本之前,安装完 Go 之后, 需要配置 GOROOT 和 GOPATH 等, 跟之前一堆 Go 管理工具像 glide 和 vendor 有得一拼(还好现在官方 go modules 逐渐将包管理入口也做了收敛)。

    这里收集和整理了 Go 版本升降级的两个方法。

    方法一

    安装想要的 Go 版本, 并做链接

    1. 检查当前 Go 版本:

      $ go version
      go version go1.13 darwin/amd64
    2. 通过 Homebrew 安装想要的 Go 版本, 版本列表详见:Homebrew Formulae/go

      $ brew install go@1.12
      Updating Homebrew...
      ==> Auto-updated Homebrew!
      Updated 2 taps (homebrew/core and homebrew/cask).
      ==> Updated Formulae
      openssl@1.1 ✔
      ==> Downloading https://homebrew.bintray.com/bottles/go@1.12-1.12.9.mojave.bottle.tar.gz
      Already 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
      ==> Caveats
      go@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
    3. 取消链接当前安装的 Go 版本:

      $ brew unlink go
      Unlinking /usr/local/Cellar/go/1.13... 3 symlinks removed
    4. 链接到自定义的 Go 版本:

      $ brew link --force go@1.12
      Linking /usr/local/Cellar/go@1.12/1.12.9... 3 symlinks created
      
      If 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 手动链接。

    5. 检查是否安装降级(或升级)成功:

      $ go version
      go 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 文档

     
  • 相关阅读:
    sublimetext ruby 插件
    [C]goto statement, rarely been used. Deprecated???
    [C]union
    [C] Struct Test
    [C,Java,Python]Command Line Argument: argv, argc, sys.argv, args
    [Python]**otherInfo, *other
    [C]parameterized macros 带参数的宏
    [C]指针与结构变量
    [C]结构变量传递给函数
    [C]结构变量数组array of structure varibles
  • 原文地址:https://www.cnblogs.com/joker1937/p/15881133.html
Copyright © 2020-2023  润新知