# 安裝Golang

## 使用 1.11 版本後的不需要設置 GOPATH, GOROOT

因為已經有 go mod，解決之前專案都必須放在 GOPATH 的問題。

## Windows

到此頁面下載並安裝<https://golang.org/dl/>

建議安裝路徑預設選為C:\go

之後安裝程式會自動添加PATH變數 `C:\go\bin`

1.接著我們要添加一個變數`GOROOT`

```
setx goroot C:\go
```

2.再來設定`GOPATH`

```
setx gopath C:\Go\gopathfold
```

GOPATH為之後用來放專案的路徑 未來通常會有三個目錄`src、bin、pkg`

`src`放原始碼（比如：.go .c .h .s等）

`pkg` 存放編譯後生成的文件（比如：.a）

`bin` 存放編譯後生成的可執行文件

> 可以輸入go env 來查看目前Go 的相關環境路徑與變量

## MacOS

1.到此下載頁面下載安裝檔案：<https://golang.org/dl/>

2.之後一樣新增`GOPATH`

```
export GOPATH=/Users/...
```

更新 Go 版本：

重新下載 pkg 安裝即可，會自動覆蓋。

## Linux

```
wget -c https://dl.google.com/go/go1.14.2.linux-amd64.tar.gz -O - | sudo tar -xz -C /usr/local

vim ~/.profile
export PATH=$PATH:/usr/local/go/bin

source ~/.profile
```


---

# Agent Instructions: 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://easonwang.gitbook.io/golang/an-zhuang-golang.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.
