Go 语言环境安装
Go 语言支持以下系统:
- Linux
- FreeBSD
- Mac OS X(也称为 Darwin)
- Windows
安装包下载地址为:https://go.dev/dl/。
如果打不开可以使用这个地址:https://golang.google.cn/dl/。

各个系统对应的包名:
| 安装包文件名 | 适用系统 | 处理器架构 | 系统版本要求 | 说明 |
|---|---|---|---|---|
go1.26.3.windows-amd64.msi |
Microsoft Windows | x86-64 (Intel 64-bit) | Windows 10 或更新 | Windows 64 位系统图形化安装程序 |
go1.26.3.darwin-arm64.pkg |
Apple macOS | ARM64 (Apple Silicon 64-bit) | macOS 12 或更新 | 适用于 M 系列芯片 Mac(包括你的 Mac mini 4)的安装包 |
go1.26.3.darwin-amd64.pkg |
Apple macOS | x86-64 (Intel 64-bit) | macOS 12 或更新 | 适用于搭载 Intel 处理器的老款 Mac |
go1.26.3.linux-amd64.tar.gz |
Linux | x86-64 (Intel 64-bit) | Linux 3.2 或更新 | 绝大多数 64 位 Linux 系统的压缩包 |
go1.26.3.src.tar.gz |
任意系统 | 源码 | - | Go 语言源代码包,需自行编译 |
UNIX/Linux/Mac OS X, 和 FreeBSD 安装
以下介绍了在UNIX/Linux/Mac OS X, 和 FreeBSD系统下使用源码安装方法:
1、下载二进制包:go1.4.linux-amd64.tar.gz。
2、将下载的二进制包解压至 /usr/local目录。
tar -C /usr/local -xzf go1.4.linux-amd64.tar.gz
3、将 /usr/local/go/bin 目录添加至 PATH 环境变量:
export PATH=$PATH:/usr/local/go/bin
以上只能暂时添加 PATH,关闭终端下次再登录就没有了。
我们可以编辑 ~/.bash_profile 或者 /etc/profile,并将以下命令添加该文件的末尾,这样就永久生效了:
export PATH=$PATH:/usr/local/go/bin
添加后需要执行:
source ~/.bash_profile 或 source /etc/profile
注意:MAC 系统下你可以使用 .pkg 结尾的安装包直接双击来完成安装,安装目录在 /usr/local/go/ 下。
Windows 系统下安装
Windows 下可以使用 .msi 后缀(在下载列表中可以找到该文件,如go1.4.2.windows-amd64.msi)的安装包来安装。
默认情况下 .msi 文件会安装在 c:\Go 目录下。你可以将 c:\Go\bin 目录添加到 Path 环境变量中。添加后你需要重启命令窗口才能生效。
安装测试
创建工作目录 C:\>Go_WorkSpace。
test.go 文件代码:
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
使用 go 命令执行以上代码输出结果如下:
C:\Go_WorkSpace>go run test.go Hello, World!
