在Ubuntu22.04系统上配置Golang环境

Jeffrey Zhu Lv1

下载Golang

Golang官方网站

选择对应版本进行下载,可本地下载再拷贝到服务器或者使用wget

这里我们选择go1.25.5 amd64版本

1
wget https://golang.google.cn/dl/go1.25.5.linux-amd64.tar.gz

解压

1
tar -xvf go1.25.5.linux-amd64.tar.gz
1
2
zhuzy2024@computemachine:~/workspace/HuaweiFinanceProject$ ls
go go1.25.5.linux-amd64.tar.gz

配置环境

移动到/usr/local目录

1
sudo mv go /usr/local
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 打开环境变量配置文件
vim ~/.bashrc

# 粘贴以下内容
export GOROOT=/usr/local/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH

# 建议再增加以下两项配置
# 1.13之后的版本都是用mod了,所以gopath指定个地方就可以了,三方依赖会下载到那里
export GOPATH=/go
# 配置国内镜像,下载依赖速度会很快
export GOPROXY=https://mirrors.aliyun.com/goproxy/,direct

# 保存关闭后刷新一下即可
source ~/.bashrc

# 建议打开gomod开关
go env -w GO111MODULE=on

检查安装

终端输入go,出现以下字符则安装成功

1
2
3
4
5
6
Go is a tool for managing Go source code.

Usage:

go <command> [arguments]
...
  • Title: 在Ubuntu22.04系统上配置Golang环境
  • Author: Jeffrey Zhu
  • Created at : 2025-12-21 23:13:42
  • Updated at : 2025-12-21 23:23:36
  • Link: http://www.jeffreyzhu.me/2025/12/21/在Ubuntu22-04系统上配置Golang环境/
  • License: This work is licensed under CC BY-NC-SA 4.0.
Comments
On this page
在Ubuntu22.04系统上配置Golang环境