LESSON · 1 OF 28

A complete Go program

A complete Go program

Here is the smallest Go program you can actually run. Paste it into a file called main.go and it works as-is:

go
package main

import "fmt"

func main() {
    fmt.Println("hello from Go")
}

Run it and it prints:

text
hello from Go

Every runnable Go program has this same shape - four parts, each required: a package line, an import line, a func main, and the code inside it. The next few nodes take these one at a time. For now, notice that this whole file is a valid program you can copy, run, and build - nothing is left out.

Spin up a fresh environment and practice live.
go · fresh machine · ready in under a minute