Go 1 cheatsheet

Go 1: Setup and running

6 common Go 1 tasks.

Check the Go version

Print the installed Go toolchain version.

go version

Show Go environment settings

Print one environment setting, here the module cache and workspace location.

go env GOPATH GOMODCACHE

Start a module

Create a go.mod file. Use the path where the module will be published as its name.

go mod init example.com/myapp

Run the program

Compile and run the main package in the current folder.

go run .

Build a binary

Compile the package into an executable named myapp.

go build -o myapp .

Install a command-line tool

Build and install a program from a module into your Go bin folder.

go install golang.org/x/tools/cmd/goimports@latest

Was this page helpful?