Golang 筆記
  • Introduction
  • 安裝Golang
    • 本地編譯與安裝第三方套件
    • 第一個 GO 程式
    • export 與 import
    • 使用 go mod
  • 基本工具
  • DataBase操作
    • MySQL
    • 使用 ORM
    • MongoDB
  • 基本語法
    • Variable
    • BSON
    • JSON
    • 時間相關
    • Interface
    • Error
    • 型別
    • 字串
    • defer
    • panic, recover
    • Channel 與Goroutine
      • 讀寫鎖
      • for select 與 for range
      • UnBuffered channel 與 Buffered channel
    • Function
    • pointer
    • regExp
    • fmt
    • Make vs New
    • struct
    • Array, Slice 陣列
    • map
  • 核心模組
    • Reflect
    • File
    • Signal
    • BuiltIn
    • Sync
    • IO
    • Sort
    • http
    • crypto
    • context
  • 第三方模組
    • Dom Parser
    • gin 框架
    • Websocket
    • Iris框架
      • 讀取 Body 資料
      • 相關範例
    • Fiber 框架
    • 自動重啟 server 工具
    • go-jwt
  • 測試
  • 原始碼解析
  • 常見問題
    • 資料存取不正確
    • Data races
Powered by GitBook
On this page
  • 使用 1.11 版本後的不需要設置 GOPATH, GOROOT
  • Windows
  • MacOS
  • Linux

Was this helpful?

安裝Golang

PreviousIntroductionNext本地編譯與安裝第三方套件

Last updated 2 years ago

Was this helpful?

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

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

Windows

到此頁面下載並安裝

建議安裝路徑預設選為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

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

1.到此下載頁面下載安裝檔案:

https://golang.org/dl/
https://golang.org/dl/