跳到主要内容

Linux 安装 Go 配置环境变量

· 阅读需 1 分钟
素明诚
Full stack development

下载

wget https://studygolang.com/dl/golang/go1.22.4.linux-amd64.tar.gz

解压

sudo tar -C /usr/local -xzf go1.22.4.linux-amd64.tar.gz

bash

nano ~/.bashrc

# Go 环境变量设置
export GOROOT=/usr/local/go
export GOPATH=/usr/local/go-env
export GOPROXY=https://goproxy.cn,direct
export PATH=$PATH:/usr/local/go/bin

source ~/.bashrc

zsh

nano ~/.zshrc

# Go 环境变量设置
export GOROOT=/usr/local/go
export GOPATH=/usr/local/go-env
export GOPROXY=https://goproxy.cn,direct
export PATH=$PATH:/usr/local/go/bin

source ~/.zshrc

测试

检查 Go 语言的版本和环境变量

go version
go env

通过包管理器安装

sudo apt install golang-go