Hello World in Go

Write your first Go program that prints Hello, World to the terminal, then compare your solution with a complete, tested example.

Level
Easy
Estimated time
10 min
Concepts covered
fmt, package main

Every Go journey starts with a program that prints a message to the terminal. In this exercise you write the classic “Hello, World!” and get to know the structure that every Go program shares.

Statement

Write a complete Go program that prints exactly one line to the terminal: the text Hello, World! followed by a newline.

Constraints:

  • The file must be a valid package main containing a func main.
  • Use the fmt package to print.
  • Print nothing else, no extra spaces or lines.

Example

This program takes no input. When you run it, it must produce this output:

Hello, World!

Starter code

package main

import "fmt"

func main() {
	// Print "Hello, World!" here.
}

Hints

Hint 1

The fmt package is already imported. Look for a function that prints a value and adds the newline for you.

Hint 2

fmt.Println writes its argument followed by a newline. In Go, text is written between double quotes.

Hint 3

Call fmt.Println("Hello, World!") inside main. That single line is the whole program body.

Solution

Show the solution
package main

import "fmt"

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

package main tells Go that this file builds an executable, and func main is the entry point that runs when you start the program. fmt.Println prints its argument to standard output and appends a newline, so the terminal shows Hello, World! on its own line.

Common mistakes:

  • Forgetting the package main line or naming the package something else, so the program cannot be run directly.
  • Using single quotes '...'. In Go, single quotes are for a single rune; text values use double quotes.
  • Removing the import "fmt" line, which makes fmt.Println undefined.

Ready for the details behind this program? Read Your first Go program.

Search

Search runs entirely in your browser.