beginner getting started

Hello, World! — Your First Go Program

Write, compile, and run your first Go program. Understand the basic structure of a Go file: package main, imports, and the func main entry point.

hello-world basics

Writing Hello, World

Create a file called main.go:

package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}

Running the Program

Terminal window
go run main.go

Output:

Hello, World!

Understanding Each Line

package main

Every Go file starts with a package declaration. The main package is special — it tells Go that this is an executable program, not a library.

import "fmt"

The import keyword brings in packages from the standard library or third-party modules. fmt stands for “format” and provides functions for formatted I/O.

func main()

This is the entry point of every Go program. When you run your program, Go looks for this function inside package main and starts execution there.

fmt.Println()

Println prints a line to standard output, followed by a newline character.

Compiling to a Binary

Terminal window
# Build a binary
go build -o hello
# Run the binary
./hello # Linux/macOS
hello.exe # Windows

The go build command compiles your code into a standalone binary. No runtime or virtual machine required — just a single executable file.

Go’s Philosophy in Action

Even in this tiny program, you can see key Go design principles:

  • Explicit imports — No magic, everything you use is declared
  • Simple syntax — No semicolons, no classes, no inheritance
  • Opinionated formatting — Run go fmt to auto-format your code

Try It Yourself

  1. Change the message to print your name
  2. Print multiple lines using multiple fmt.Println() calls
  3. Use fmt.Print() instead and notice the difference (no newline)

Next Step

Now let’s dive into basic types and variables in Go.