---
title: "Install Go and run your first program"
slug: "hello-go"
description: "Install Go, create a module and run a first program with go run. You see what package main and func main do and how go run differs from go build."
published: "2026-12-03"
updated: "2026-12-03"
canonical: "https://aifree.dev/courses/learn-go/hello-go"
---

# Install Go and run your first program

How do you get from nothing to a running Go program?

## Predict

```go
package main

import "fmt"

func main() {
	fmt.Println("Hello")
	fmt.Println("Go", "world")
}
```

What does this program print?

- HelloGo world
- Hello on one line, then Go world on the next
- Hello Go world on one line

Answer: Hello on one line, then Go world on the next — Println writes its operands separated by a space and ends with a newline, once per call.

Output:

```
Hello
Go world
```

Two calls, two lines. The second call joins its two operands with a space.

## Install Go

Download the installer for your system from **go.dev/dl** and run it. Then open a new terminal and type `go version`. It prints the installed version, which tells you the install worked. The Go command is the one tool you use for everything in this course: it runs, builds and tests your code.

## Make a module

A **module** is a folder of Go code with a `go.mod` file. Create it with `go mod init example/hello`; the name is the module path. Then `go run .` builds the program in the current folder and runs it. `go build` compiles the program and leaves an executable file, but does not run it.

## A first program with Println and Printf

```go
package main

import "fmt"

func main() {
	name := "Ada"
	age := 36
	fmt.Println("Hello, Go")
	fmt.Printf("%s is %d years old\n", name, age)
}
```

Output:

```
Hello, Go
Ada is 36 years old
```

`Printf` fills `%s` with a string and `%d` with an integer, in order. `\n` ends the line, because Printf adds none.

Playground: https://go.dev/play/p/pB6YyEr17F5

## What package main means

The first line, `package main`, says this code builds into a program. `func main()` is the function Go calls first. `import "fmt"` makes the `fmt` package available; its name comes before the dot, as in `fmt.Println`. A file that does not start with a package clause is not valid Go.

## Say it back

In your own words: what is the difference between go run and go build?

Our sentence: `go run` compiles the program and starts it right away; `go build` only compiles it and leaves an executable file you start yourself.

## Mission (8 min)

Install Go, check the version, make a hello folder with a module in it, write the first program into main.go and run it.

```sh
go version
mkdir hello && cd hello
go mod init example/hello
go run .
```

## Common questions

### How do I install Go?

Download the installer for your operating system from go.dev/dl, run it, then open a new terminal and type go version. If it prints a version number, Go is installed and ready. You do not need an editor plugin or extra tools for the first lessons: a plain text editor and a terminal are enough to write, run and change small programs.

### What is a Go module?

A module is a folder of Go code described by a go.mod file, which records the module path and the modules the code depends on. You create one with go mod init and a name such as example/hello. Once the file exists, commands like go run . and go build work from that folder without further setup.

### What is the difference between go run and go build?

The go run command compiles your program and starts it at once, which is handy while you learn or test an idea. The go build command compiles the program and leaves an executable file in the folder, without running it. Use build when you want to keep or share the compiled program, and run when you only want the result.

## Sources

- https://go.dev/doc/install (read 2026-12-03)
- https://go.dev/doc/tutorial/getting-started (read 2026-12-03)
- https://pkg.go.dev/cmd/go (read 2026-12-03)

Measured with go1.27.4 darwin/arm64 on 2026-12-03.
