GoGoPrimer
< Back to module

Getting started

Installation and first program

Head to go.dev/dl to download the installer for your platform (macOS, Windows, Linux). Once installation is done, verify it worked by opening a terminal.

go version
Should print something like `go version go1.23.0 darwin/arm64`.

Create a folder for this first program, then a `main.go` file inside it.

package main
 
import "fmt"
 
func main() {
fmt.Println("Hello, Go!")
}
Your first Go program: it prints a message to the terminal.

Two ways to run it. `go run` compiles and executes in a single command, handy during development. `go build` produces a standalone executable binary that you can distribute and run without Go installed.

go run main.go
# Hello, Go!
 
go build -o hello main.go
./hello
# Hello, Go!

Before every commit, run `gofmt -w .` (or configure your editor to do it on save): it's the official formatter, there's nothing to debate about it.

Your turn

Modify the program so it prints your first name after the greeting, on a second line.

package main
 
import "fmt"
 
func main() {
fmt.Println("Hello, Go!")
// ajoute une ligne ici
}