
How to write Hello, World! in Go
How to write Hello, World! in Go êŽë š
Now weâre ready to create our first Go program!
Itâs a programmer's tradition to make the first program print the âHello, World!â string to the terminal when itâs run. So weâll do that first, and then weâll explain how we did it.
Maybe you have a folder in your home directory where you keep all your coding projects and tests.
In there, create a new folder, for example call it hello
.
In there, create a hello.go
file (you can name it as you want).
Add this content:
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}

This is your first Go program!
Letâs analyze this line by line.
package main
We organize Go programs in packages.
Each .go
file first declares which package it is part of.
A package can be composed by multiple files, or just one file.
A program can contain multiple packages.
The main
package is the entry point of the program and identifies an executable program.
import "fmt"
We use the import
keyword to import a package.
fmt
is a built-in package provided by Go that provides input/output utility functions.
We have a large standard library (std
) ready to use that we can use for anything from network connectivity to math, crypto, image processing, filesystem access, and more.
You can read about all the features that this fmt
package provides on the official documentation (fmt
).
func main() {
}
Here we declare the main()
function.
Whatâs a function? Weâll see more about them later, but in the meantime letâs say a function is a block of code thatâs assigned a name, and contains some instructions.
The main
function is special because whatâs where the program starts.
In this simple case we just have one function - the program starts with that and then ends.
fmt.Println("Hello, World!")
This is the content of the function we defined.
We call the Println()
function defined in the fmt
package we previously imported, passing a string as a parameter.
This function, according to the docs (fmt
) "formats according to a format specifier and writes to standard outputâ.
Take a look at the docs because they are great. They even have examples you can run:

We use the âdotâ syntax fmt.Println()
to specify that the function is provided by that package.
After the code executes the main
function, it has nothing else to do and the execution ends.