Hello World

View saved

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 main marks an executable program
  • import "fmt" brings in formatting helpers
  • fmt.Println writes a line to standard output
  • Go files use the .go extension

Comments

One comment per signed-in account. Comments are saved with this page’s URL.