Get Started with Go
This guide will help you install Go and run your first program in just a few minutes.Install Go
Download and install Go from the official website:Visit go.dev/doc/install and follow the installation instructions for your operating system:You should see output showing your Go version, like
- macOS: Download the
.pkginstaller or use Homebrew:brew install go - Linux: Download the tarball and extract to
/usr/local - Windows: Download the
.msiinstaller
go version go1.22.0 darwin/arm64.Create Your First Program
Let’s start with the classic “Hello World” program. Create a file named Every Go program starts with a
hello-world.go:hello-world.go
package declaration. Programs start running in the main package’s main() function. The fmt package provides formatted I/O functions like Println.Run Your Program
Go makes it easy to run programs directly without a separate compile step:You should see:
The
go run command compiles and runs your program in one step, perfect for development and testing.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
- Official Go Documentation - Comprehensive Go documentation
- Go Tour - Interactive introduction to Go
- Go Playground - Run Go code in your browser
- Effective Go - Best practices and idioms