> For the complete documentation index, see [llms.txt](https://pshizhsysu.gitbook.io/golang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pshizhsysu.gitbook.io/golang/goyu-yan-huan-jing-an-zhuang.md).

# 环境安装

## 安装介质

安装包下载地址： <https://golang.org/dl/>

支持系统：

| 操作系统    | 安装包                          |
| ------- | ---------------------------- |
| centos  | go1.10.2.linux-amd64.tar.gz  |
| windows | go1.10.2.windows-amd64.zip   |
| MacOS   | go1.10.2.darwin-amd64.tar.gz |

## Centos

1、下载安装介质

下载二进制包 `go1.10.2.linux-amd64.tar.gz`

2、解压

解压二进制包到`/usr/local`目录下，解压后在`/usr/local`目录下会多出一个`go`目录

```
tar -C /usr/local -xzvf go1.10.2.linux-amd64.tar.gz
```

3、设置环境变量

首先创建环境`GOROOT`，值设为`/usr/local/go`；然后把`$GOROOT/bin`加入到环境变量`PATH`中去。\
具体操作为，在`/etc/profile`尾部添加如下两行

```
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
```

然后执行如下命令，使环境变量生效

```
source /etc/profile
```

4、验证

执行以下命令，查看go版本信息

```
$ go version
go version go1.10.2 linux/amd64
```

## Windows

1、下载安装介质

下载最新版本的go安装包，有.msi和.zip两种格式，.msi是安装版，.zip是绿色版，这里我们选择 zip

2、解压安装包

把zip包解压到 `D:\GreenSoftware` 目录下，此时在go的根目录就是 `D:\GreenSoftware\go`

3、创建环境变量GOROOT

添加环境变量GOROOT，值设为 `D:\GreenSoftware\go`

4、 添加GOROOT到Path中

把`D:\GreenSoftware\go\bin`路径添加到Path中，即在Path的后面添加 `;%GOROOT%\bin`

5、 验证

执行以下命令，查看go的版本信息

```
E:\> go version
go version go1.10.1 windows/amd64
```

### MacOS

1、下载

下载archive类型的压缩包`go1.10.2.darwin-amd64.tar.gz`

2、解压

把上面的包解压到`/usr/local`目录下，解压后在`/usr/local`下便会多出一个`go`目录

```
sudo tar -C /usr/local -xzvf go1.10.2.darwin-amd64.tar.gz
```

3、设置环境变量

首先创建环境`GOROOT`，值设为`/usr/local/go`；然后把`$GOROOT/bin`加入到环境变量`PATH`中去。\
具体操作为，在`~/.profile`尾部添加如下两行

```
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
```

然后执行如下命令，使环境变量生效

```
source ~/.profile
```

4、验证

执行以下命令，查看go版本信息

```
$ go version
go version go1.10.2 linux/amd64
```

### Reference

\[1] <https://golang.org/doc/install>


---

# 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:

```
GET https://pshizhsysu.gitbook.io/golang/goyu-yan-huan-jing-an-zhuang.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
