Writing Your First Go Program
Create a file named hello.go. In Go, the filename typically reflects the purpose of the program. Here, we use hello.go for our Hello World example.
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
Hello, World!
Compiling the Program
Open a terminal where your hello.go file is saved and run the following command:
go build hello.go
What happens during compilation?
The go build command compiles the Go source code:
- Parses your
.go source file written in Go syntax.
- Compiles it to machine code.
- Generates an executable named
hello (or hello.exe on Windows).
This binary is now ready to be executed.
Running the Program
To run the compiled program, use the following command in your terminal:
./hello
What happens during execution?
The system loads and runs your Go binary:
- Execution begins from the
main() function.
fmt.Println prints Hello, World! to the console.
Hello, World!
You’ve now compiled and executed your first Go program — an essential first step in learning the Go language.

About the authorMallikarjuna Mallisetty
General programming
Mallikarjuna shares practical programming tutorials and foundational concepts designed to help developers learn by building and experimenting.
View LinkedIn profile ↗