Hello World
Create a file
Save this as hello.go. Executable programs use package main and a main function.
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
Run without a binary
go run compiles and executes in one step—ideal while learning.
go run hello.go
Build a binary
go build creates an executable you can run directly.
go build -o hello hello.go
./hello
Read the pieces
package mainmarks an executable programimport "fmt"brings in formatting helpersfmt.Printlnwrites a line to standard output- Go files use the
.goextension
Comments
One comment per signed-in account. Comments are saved with this page’s URL.