Install Go and run your first program
Learn Go · Beginner · 8 min
How do you get from nothing to a running Go program?
1Guess
package main import "fmt" func main() { fmt.Println("Hello") fmt.Println("Go", "world") }2Read
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.3Read
Make a module
A module is a folder of Go code with a
go.modfile. Create it withgo mod init example/hello; the name is the module path. Thengo run .builds the program in the current folder and runs it.go buildcompiles the program and leaves an executable file, but does not run it.4Code
A first program with Println and Printf
1 / 2package main import "fmt" func main() { name := "Ada" age := 36 fmt.Println("Hello, Go") fmt.Printf("%s is %d years old\n", name, age) }Read the program. What will it print?
5Read
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 thefmtpackage available; its name comes before the dot, as infmt.Println. A file that does not start with a package clause is not valid Go.6Say it back
7Mission · 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.
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
Published Dec 3, 2026 · Updated Dec 3, 2026