Go Toolchain

The Go CLI provides a powerful set of tools for managing your code lifecycle.

go run

Compiles and runs a package immediately. It’s perfect for testing, scripting, and local development. It does not save a binary in your directory.

go run main.go

go build

Compiles your code into a single, statically linked executable. This binary can be shipped to other machines without needing the Go toolchain installed.

go build
./myproject

go install

Compiles the package and moves the binary to your GOBIN directory (usually ~/go/bin). This allows you to run the program as a global command from anywhere on your machine.

go install
myproject // run globally

go get

Downloads a remote module and adds it as a dependency to your go.mod file.

go get github.com/username/package

go mod init

Initializes a new module in the current directory.

go mod init github.com/username/myproject