> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/di-40-zhang-kai-fa-huan-jing/di-40.6-jie-go-kai-fa-huan-jing.md).

# 40.6 Go 开发环境

Go 语言由谷歌公司（Google）开发，是一种原生支持并发的编程语言。

本节在 FreeBSD 上配置 Go 语言开发环境，包括工具链安装与版本设置。

## 安装 Go

使用 pkg 安装：

```sh
# pkg install go
```

或者使用 Ports 安装：

```sh
# cd /usr/ports/lang/go/
# make install clean
```

> **注意**
>
> 本节中 Go 版本号 `go1.25.10` 为撰写时的 Ports 版本。请根据当前 FreeBSD Ports 中可用的最新 Go 版本调整，可通过 `pkg search go` 查询可用版本。

安装成功后，查看已安装 Go 语言的版本信息：

```sh
$ go version
go version go1.25.10 freebsd/amd64
```

## 为美好的世界献上祝福

新建文本文件 `helloWorld.go`，添加如下内容：

```go
package main // 声明 main 包，程序入口包必须为 main

import "fmt" // 引入 fmt 包用于格式化输出

func main() { // 主函数，程序入口
	fmt.Println("Hello, World!") // 输出“Hello, World!”到控制台
}
```

保存后，在终端执行下列命令即可运行程序：

```sh
$ go run helloWorld.go
Hello, World!
```

## JetBrains GoLand IDE

使用 pkg 安装 JetBrains GoLand IDE：

```sh
# pkg install jetbrains-goland
```

或者使用 Ports 安装：

```sh
# cd /usr/ports/devel/jetbrains-goland/
# make install clean
```

![JetBrains GoLand IDE 界面示例](/files/F7NsuJkaHh0pE2k6jKrD)

## 参考文献

* Go Project. Effective Go\[EB/OL]. \[2026-04-17]. <https://go.dev/doc/effective_go>. Go 语言官方最佳实践文档，介绍惯用写法与并发模式。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/di-40-zhang-kai-fa-huan-jing/di-40.6-jie-go-kai-fa-huan-jing.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
