ubuntu22.04.1LTS/debian11安装golang最新版本 其他linux系统通用
#ubuntu22.04.1LTS安装golang最新版本 其他linux系统通用
不建议 直接用自带的包管理器安装,后续维护会麻烦一点点
#获取最新版本golang
https://golang.google.cn/dl/
截止2022.10.11 最新稳定版本是 1.9.2
截止2022.12.01 最新稳定版本是 1.9.3
plaintext
cd ~
wget -c https://golang.google.cn/dl/go1.19.3.linux-amd64.tar.gz
tar -zxf go1.*.tar.gz -C /opt/
rm go1.*linux-amd64.tar.gz
cd /opt/
mkdir /opt/gopath
# 修改环境变量
nano /etc/profile #或者 ~/.profile
在文末添加
plaintext
export GO111MODULE=on
export GOROOT=/opt/go
export GOPATH=/opt/gopath
#export GOPROXY=https://goproxy.io,direct
#export GOPROXY=https://proxy.golang.com.cn,direct
export GOPROXY=https://goproxy.cn
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
更新生效 查看go情况
plaintext
source /etc/profile
go env
#其他问题
source会提示 /etc/profile (line 5): Unsupported use of '='. In fish, please use 'set PATH "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"'.
这个是 fish的问题,用bash 就好了