Beginner Fundamentals

Installing Go

Before writing Go code, you need the Go toolchain installed. It includes the compiler and helpful commands like go run and go build.

Install

Download the installer for your system from the official site and follow the steps. To check that it works, open a terminal and run:

// In your terminal:
// go version
// Example output: go version go1.22.0 darwin/amd64

Minimal program

Create a file named main.go:

package main

import "fmt"

func main() {
    fmt.Println("Go is installed!")
}

Run it

Use go run to compile and execute in one step, great while developing:

// go run main.go

Build it

Use go build to produce a standalone executable you can ship:

// go build main.go
// This creates a binary you can run directly:
// ./main

The built binary needs no extra runtime, which makes deployment simple.