Setting Up Go
Setting up your Go environment
Section titled “Setting up your Go environment”Setting up TypeScript requires Node.js, npm (or another package manager), and tsc. Go has a single, unified toolchain — you install Go once and get everything: the compiler, formatter, test runner, and module manager.
Installing Go
Section titled “Installing Go”Download the official installer from go.dev/dl. After installation, verify with:
go version# go version go1.22.0 darwin/arm64Go installs to /usr/local/go by default. The GOPATH (workspace directory, defaults to ~/go) is where downloaded modules and installed binaries live. You rarely need to think about it — go mod handles everything.
The Go CLI vs the Node/npm CLI
Section titled “The Go CLI vs the Node/npm CLI”Every Node.js developer knows node, npm, and tsc. Go consolidates all of these into the single go command.
# TypeScript / Node.js toolchainnode index.js # run a filenpx ts-node src/index.ts # run TypeScript directlytsc # compile TypeScriptnpm install # install dependenciesnpm run build # run a build scriptnpx <tool> # run a package binary# Go toolchain (all one command)go run main.go # compile + run in one stepgo run . # run the current packagego build -o myapp . # compile to a binarygo mod init github.com/you/myapp # init a new modulego get github.com/gin-gonic/gin # add a dependencygo install tool@latest # install a CLI tool globallygo run vs go build
Section titled “go run vs go build”go run is your development loop — it compiles and executes in one step, like ts-node or npx tsx. Use it while developing. go build produces a standalone binary you can deploy. There is no separate “watch mode” built in, but tools like air provide live reload.
# TypeScript development loopnpx ts-node src/index.ts # compile + run (dev)tsc && node dist/index.js # compile then run (CI/prod)npx tsx watch src/index.ts # watch mode# Go development loopgo run . # compile + run (dev)go build -o ./bin/app . && ./bin/app # compile then run# air # watch mode (third-party)go mod init — the equivalent of npm init
Section titled “go mod init — the equivalent of npm init”When you start a new Go project, you initialize a module with go mod init. This creates a go.mod file — the Go equivalent of package.json.
# TypeScriptnpm init -y# creates package.json with name, version, deps
# then add a dependency:npm install express# updates package.json + creates package-lock.json# Gogo mod init github.com/yourname/myapp# creates go.mod
# then add a dependency:go get github.com/gin-gonic/gin# updates go.mod + creates go.sum (like package-lock.json)go install — global CLI tools
Section titled “go install — global CLI tools”npm install -g installs a CLI tool globally. go install does the same — it compiles the module and places the binary in $GOPATH/bin (add this to your PATH).
# TypeScript: global CLI toolsnpm install -g typescriptnpm install -g prettiernpx create-react-app myapp# Go: global CLI toolsgo install golang.org/x/tools/gopls@latest # LSP servergo install github.com/air-verse/air@latest # live reloadgo install github.com/golangci/golangci-lint/cmd/golangci-lint@latestPlayground
Section titled “Playground”This is a setup lesson — the Playground is less meaningful here (there is nothing to install in the browser), but you can use the playground on the next lesson (Hello World) to run your first complete Go program.