Go Basics: Compiling and running Go programs

Join the AI Workshop to learn more about AI and how it can be applied to web development. Next cohort February 1st, 2026

The AI-first Web Development BOOTCAMP cohort starts February 24th, 2026. 10 weeks of intensive training and hands-on projects.


This tutorial continues what we did in how to create your first Go program.

Open a terminal in the hello folder and run the program using

go run hello.go

Screen Shot 2022-07-28 at 12.18.23.png

Our program ran successfully, and it printed “Hello, World!” to the terminal!

The go run tool first compiles and then runs the program specified.

You can create a binary using go build:

go build hello.go

This will create a hello file that’s a binary you can execute:

Screen Shot 2022-07-28 at 12.19.50.png

In the introduction I mentioned Go is portable.

Now you can distribute this binary and everyone can run the program as-is, because the binary is already packaged for execution.

The program will run on the same architecture we built it on.

We can create a different binary for a different architecture using the GOOS and GOARCH environment variables, like this:

GOOS=windows GOARCH=amd64 go build hello.go

This will create a hello.exe executable for 64-bit Windows machines:

Screen Shot 2022-07-28 at 15.36.55.png

Setup for 64-bit macOS (Intel or Apple Silicon) is GOOS=darwin GOARCH=amd64 and Linux is GOOS=linux GOARCH=amd64.

This is one of the best features of Go.

Lessons in this unit:

0: Introduction
1: Introduction to Go
2: Your first Go program
3: ▶︎ Compiling and running Go programs
4: Variables and types
5: Operators
6: Strings
7: Arrays
8: Slices
9: Maps
10: Visualize your local Git contributions with Go
11: Use Go to get a list of repositories from GitHub
12: Building a CLI command with Go: cowsay
13: Go CLI tutorial: fortune clone
14: Build a Command Line app with Go: lolcat