Skip to content

Setting Up Go

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.

Download the official installer from go.dev/dl. After installation, verify with:

Terminal window
go version
# go version go1.22.0 darwin/arm64

Go 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.

Every Node.js developer knows node, npm, and tsc. Go consolidates all of these into the single go command.

TypeScript
# TypeScript / Node.js toolchain
node index.js # run a file
npx ts-node src/index.ts # run TypeScript directly
tsc # compile TypeScript
npm install # install dependencies
npm run build # run a build script
npx <tool> # run a package binary
Go
# Go toolchain (all one command)
go run main.go # compile + run in one step
go run . # run the current package
go build -o myapp . # compile to a binary
go mod init github.com/you/myapp # init a new module
go get github.com/gin-gonic/gin # add a dependency
go install tool@latest # install a CLI tool globally

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
# TypeScript development loop
npx 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
# Go development loop
go 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.

TypeScript
# TypeScript
npm init -y
# creates package.json with name, version, deps
# then add a dependency:
npm install express
# updates package.json + creates package-lock.json
Go
# Go
go 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)

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
# TypeScript: global CLI tools
npm install -g typescript
npm install -g prettier
npx create-react-app myapp
Go
# Go: global CLI tools
go install golang.org/x/tools/gopls@latest # LSP server
go install github.com/air-verse/air@latest # live reload
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest

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.

What is the Go equivalent of running `ts-node src/index.ts`?
What file does `go mod init` create?
Where does `go install` place compiled binaries?
What is go.sum equivalent to in the Node.js ecosystem?