Your First Go Program
A free lesson from Swipe Coding · Go, level 2 · updated October 2026
By the Swipe team, founded by Colin · how we make lessons
Every Go program starts with the same basic shape: a package declaration, any imports the file needs, and a function called main where execution begins. Here's the smallest complete Go program you can write.
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}package main is a package declaration — it tells the Go compiler which package this file belongs to. The special name main is what marks a file as producing a runnable program instead of a reusable library, and a package named main must contain a function called main(), which is exactly where the program starts running.
The package name ____ tells the Go compiler that a file is meant to produce a runnable program, not a reusable library.
import "fmt" brings in a package from Go's standard library so you can use the functions inside it, like fmt.Println. Go requires every package you import to actually be used somewhere in the file — if you import a package and never reference it, the compiler treats that as an error and refuses to build the program at all.
What happens if you import a package in Go but never use it anywhere in the file?
import "fmt"
func main() {
// fmt is never referenced anywhere in here
}To actually run this file, you use the go command from a terminal. go run hello.go compiles and runs the program in a single step, which is perfect while you're learning. go build hello.go instead produces a standalone executable file you can run directly, without needing Go installed on whatever machine runs it afterward.
go run hello.go
In Go, you can compile and run a program in a single command using go run, without a separate build step of your own.
Keep your streak going in Swipe Coding
Swipe through every level of Go on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.
Get the Swipe apps →