Go Overview & Environment Setup

Why Go was created, its design philosophy, installing the Go toolchain, understanding GOPATH and module mode, and writing your first Go program.

BeginnerUpdated 2026-10-3079K views

Why Go Exists

Google created Go in 2009 to solve three pain points: slow C++/Java compiles, unwieldy dependency management, and the complexity of concurrent programming. Go compiles to a single static binary, has a tiny keyword set (25), garbage collection, and goroutines that make concurrency a language-level feature rather than a library afterthought.

  • Cloud-native pedigree: Docker, Kubernetes, Terraform, etcd are all written in Go.
  • Fast compilation: large projects build in seconds.
  • Simple concurrency: goroutines and channels are built into the language.

Installing the Toolchain

# 下载安装包(go.dev/dl)后验证
go version       # go1.23+

# Linux 包管理器
sudo apt install golang-go

# 环境变量(默认即可,需要自定义时再改)
go env GOPATH
go env GOMODCACHE
Modern Go is module-based: every project has a go.mod and lives anywhere on disk. GOPATH mode is only for very old code.

First Program

mkdir hello && cd hello
go mod init example.com/hello   # 生成 go.mod
go get github.com/gin-gonic/gin # 添加依赖
go build                         # 编译为当前平台二进制
go run .                         # 直接运行
package main

import "fmt"

func main() {
    fmt.Println("Hello, BackendWiki!")
}
  • main package + func main is the entry point.
  • Unreferenced imports are a compile error — keep imports tidy.
  • gofmt / gofmt -w formats code; there is one canonical style, no formatting debates.

Friends & Partners