1、查看删除旧版本

  1. ll -a /usr/local/go
  2. rm -rf /usr/local/go

2、下载安装新版本

  1. mkdir backup
  2. cd backup
  3. wget https://golang.google.cn/dl/go1.15.1.linux-amd64.tar.gz
  4. sudo tar -zxf go1.15.1.linux-amd64.tar.gz -C /usr/local

3、配置

  1. sudo mkdir /usr/lib/gopath
  2. sudo vim /etc/profile
  3. source /etc/profile
  1. #golang config
  2. export GO111MODULE=on
  3. export GOPROXY=https://goproxy.cn,direct
  4. #export GOPROXY=https://goproxy.io,direct
  5. export GOROOT=/usr/local/go
  6. export GOPATH=/usr/lib/gopath
  7. export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

4、测试

  1. go version
  2. vim hello.go
  3. go run hello.go
  1. package main
  2. import "fmt"
  3. func main() {
  4. fmt.Printf("Hello, world!\n")
  5. }

参考:

centos 7 安装golang1.14.4

centos下安装golang环境