go 安装/版本切换

1. go 安装/版本切换

1.1. 安装 go1.17

今天发现一个新方法可以在同一台机器上安装 go 的不同版本:

$ go get golang.org/dl/go1.17
$ go1.17 download
$ go1.17 version

1.2. brew 安装

我们先使用命令来查找一下 go 版本

brew search go

这是终端会显示所有的查询结果, 这里因为要安装 go1.12, 所以执行以下命令进行安装。

brew install go@1.12

安装成功后, 进行链接以下就可以了。

brew link go@1.12 --force

至此安装结束, 终端输入 go version 进行验证。

1.2.1. brew link unlink

This process would likely apply to other Homebrew formula also.

First search for your desired package:

brew search go

You should get a list of results that include the below. Not “go” is very unspecific so you may get a lot of results:

==> Formulae
go ✔
go@1.10
go@1.11
go@1.9

Then install the desired version:

brew install go@1.10

Remember that you can have more than one package installed at the same time, but you cannot have them all available at the same time. So if you have the latest/generic go package already installed you need to unlink it first:

brew unlink go

And then you can link a different version:

brew link go@1.10

In some cases you may need to link them with the --force and --overwrite options:

brew link --force --overwrite go@1.10

1.3. 版本切换

1.3.1. bash 环境切换

我一般采用这种方法,简单可控:

# Set the GOPROXY environment variable
export GOPRIVATE=gitlab.xxx.com/*
export GOPROXY=https://goproxy.cn,direct

# export GOROOT=/opt/go
export GOROOT=/opt/go1.17.9
export GOBIN=$GOROOT/bin
export GOPATH=/Users/mac/Downloads/project/ent

export GOALL=$GOROOT:$GOBIN:$GOPATH

export PATH=$PATH:$GOALL
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

云满笔记

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值