Skip to main content
  1. Tutorials/

Hello World in Go: Your First Program

··3 mins

What You’ll Learn #

In this tutorial, you’ll write the classic “Hello World” program in Go - a simple program that displays “Hello World” on the screen. This is traditionally the first program written when learning any new programming language, and it’s the perfect way to verify your Go installation and understand the basic structure of a Go program.

Let’s write your first Go program step by step! 🚀

If you don’t have Golang installed, visit the official Go website and install the version appropriate for your operating system.


Golang “Hello World” program #

Create hello-world directory #

It is a good practice that each new project has its own directory.

Save the following program as main.go in the hello-world directory #

package main

import "fmt"

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

Run your program #

$ go run hello-world/main.go

Output

Hello World!

Congratulations! You have just created your first program in Go 🚀.


How Golang “Hello World” program works #

package main

In Go, every program starts with a package declaration. A package is a collection of source files used to organize related code into a single unit. We are declaring a package called main here because we will need to declare the main() function, which can only be declared in a package named main.

import "fmt"

Next, we have the package import statement. In our program, the fmt package has been imported and will be used in the main() function to print the “Hello World” text to the standard output (your screen).

func main() {
    //...
}

The func main() starts the definition of the main() function. The main() is a special function that is executed first when the program starts. As you already know, the main() function in Go should always be declared in the main package.

fmt.Println("Hello World!")

The main() calls the Println() function of the fmt package. After starting the program, it prints the passed argument (our text “Hello World!”) to the standard output together with a new line.


Common Mistakes #

When writing your first Go program, watch out for these common pitfalls:

1. Wrong package name

package hello  // ❌ Wrong - main() requires package main

The main() function must be in a package named main, otherwise your program won’t compile.

2. Missing or incorrect imports

import fmt  // ❌ Wrong - missing quotes
import "fmt"  // ✅ Correct

3. Incorrect function name

func Main() {  // ❌ Wrong - capital M won't be recognized
    fmt.Println("Hello World!")
}

Go is case-sensitive. The entry point must be main() with a lowercase ’m'.

4. Forgetting to save the file

Make sure to save your main.go file before running go run!


Now that you’ve written your first Go program, explore these related tutorials:


Tested with Go 1.25+ | Last verified: December 2025

Congratulations on writing your first Go program! 🎉