1. 下载
- 打开官网,找到指定版本:golang.google.cn/dl/
- 使用wget拉取版本
2. 安装
- 切换到root用户
- 执行命令
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.26.1.linux-amd64.tar.gz
3. 配置环境变量
vim /etc/profile
将下面写入配置文件中去
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
4. 使环境变量配置生效
source /etc/profile
5. 设置代理
go env -w GOPROXY=https://goproxy.cn,direct
或者
go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct
go env -w GOPRIVATE=git.mycompany.com,github.com/my/private