1、查看删除旧版本
ll -a /usr/local/go
rm -rf /usr/local/go
2、下载安装新版本
mkdir backup
cd backup
wget https://golang.google.cn/dl/go1.15.1.linux-amd64.tar.gz
sudo tar -zxf go1.15.1.linux-amd64.tar.gz -C /usr/local
3、配置
sudo mkdir /usr/lib/gopath
sudo vim /etc/profile
source /etc/profile
#golang config
export GO111MODULE=on
export GOPROXY=https://goproxy.cn,direct
#export GOPROXY=https://goproxy.io,direct
export GOROOT=/usr/local/go
export GOPATH=/usr/lib/gopath
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
4、测试
go version
vim hello.go
go run hello.go
package main
import "fmt"
func main() {
fmt.Printf("Hello, world!\n")
}
参考: