首页 > 技术文章 > centos7安装go1.73

chengqiang521 2021-11-01 15:22 原文

centos7安装go1.73

解压go包

tar -zxf go1.17.linux-amd64.tar.gz -C /usr/local

配置环境变量,vim指令编辑 /etc/profile

vim /etc/profile

在/etc/profile文件末尾添加以下配置,输入 :wq保存

#golang config
export GOROOT=/usr/local/go 
export GOPATH=/data/gopath
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

创建 /data/gopath文件夹,个人比较习惯把常用的放在data文件夹下,也可以自行调整,如:/home/gopath

mkdir /data/gopath

使换将变量配置生效,并查看golang的版本

source /etc/profile
go version

设置代理环境变量,再拉去golang.org的时候就不需要墙了。注意GO1.13及之后支持direct的写法

go env -w GOPROXY=https://goproxy.cn,direct

推荐阅读