Skip to main content

Get Started with Go

This guide will help you install Go and run your first program in just a few minutes.
1

Install Go

Download and install Go from the official website:Visit go.dev/doc/install and follow the installation instructions for your operating system:
  • macOS: Download the .pkg installer or use Homebrew: brew install go
  • Linux: Download the tarball and extract to /usr/local
  • Windows: Download the .msi installer
After installation, verify Go is installed correctly:
go version
You should see output showing your Go version, like go version go1.22.0 darwin/arm64.
2

Create Your First Program

Let’s start with the classic “Hello World” program. Create a file named hello-world.go:
hello-world.go
// Our first program will print the classic "hello world"
// message. Here's the full source code.
package main

import "fmt"

func main() {
	fmt.Println("hello world")
}
Every Go program starts with a package declaration. Programs start running in the main package’s main() function. The fmt package provides formatted I/O functions like Println.
3

Run Your Program

Go makes it easy to run programs directly without a separate compile step:
go run hello-world.go
You should see:
hello world
The go run command compiles and runs your program in one step, perfect for development and testing.
4

Build an Executable (Optional)

Sometimes you’ll want to build your program into a binary executable:
go build hello-world.go
This creates an executable file named hello-world (or hello-world.exe on Windows). You can run it directly:
./hello-world
Output:
hello world

What’s Next?

Now that you can run Go programs, you’re ready to explore the language! Here are some recommended next steps:

Basic Syntax

Learn about values, variables, constants, and control flow

Functions

Explore functions, multiple return values, and closures

Data Structures

Master arrays, slices, maps, and structs

Concurrency

Dive into goroutines and channels for concurrent programming

Tips for Learning

  • Type out the examples - Don’t just copy-paste. Typing code helps build muscle memory
  • Experiment - Modify the examples to see what happens
  • Run everything - All examples are meant to be run. See the output yourself
  • Read the comments - The annotations explain important concepts and gotchas
Some examples demonstrate concurrent code with non-deterministic output order. Don’t worry if your output ordering differs slightly from the examples!

Resources

Ready to learn more? Start with the Introduction or jump into specific examples!

Build docs developers (and LLMs) love