Getting Started with Go
📋 Jump to TakeawaysMost languages need a runtime, a package manager, a build tool, and a config file before you can say hello. Go gives you one command and one binary. That's it. No node_modules, no virtualenv, no JVM. Just a single executable you can drop on any machine and run.
Go is compiled, statically typed, and garbage collected. It compiles to a single binary with no runtime dependencies. Concurrency is built into the language.
Installing Go
Download from go.dev. Verify your installation (as of April 2026, the latest stable version is 1.26):
// Terminal
// $ go version
// go version go1.26.0 linux/amd64Hello World
package main
import "fmt"
func main() {
fmt.Println("Hello, World!") // Hello, World!
}Every Go program starts in package main with a func main() entry point. The fmt package handles formatted I/O.
go run vs go build
go run compiles and executes in one step. go build creates a reusable binary.
go run main.go # compile + run immediately
go build main.go # creates ./main binary
./main # run the binaryPackages
Every Go file belongs to a package. The main package is special: it produces an executable. All other packages are importable code that other programs can use.
Exported vs Unexported
In Go, naming controls visibility. If a name starts with an uppercase letter, it's exported (visible to other packages). Lowercase means unexported (only accessible within the same package). This applies to everything: functions, types, variables, constants, struct fields.
fmt.Println() // Println is exported from the fmt package
math.Pi // Pi is exported from the math packageImports
Single import:
import "fmt"Grouped imports (preferred):
import (
"fmt"
"strings"
)Modules
You can run a single main.go with go run and it works fine. No setup needed. But the moment you want to use external packages or split your code across multiple files, Go needs a module.
A module is just a go.mod file that says "this is a project" and tracks its dependencies. Initialize one with go mod init:
go mod init github.com/yourname/myprojectFor learning and small scripts, you can skip this. For anything real, start with go mod init.
fmt Package Basics
package main
import "fmt"
func main() {
fmt.Println("plain output") // plain output
fmt.Printf("Hello, %s!\n", "Go") // Hello, Go!
fmt.Printf("Number: %d\n", 42) // Number: 42
s := fmt.Sprintf("formatted: %v", true)
fmt.Println(s) // formatted: true
}Println adds a newline. Printf uses format verbs (%s, %d, %v). Sprintf returns a formatted string instead of printing.
Key Takeaways
- Go is compiled, statically typed, and garbage collected
go runexecutes directly;go buildcreates a binary- Every program needs
package mainandfunc main() - Use grouped imports with parentheses
go mod initcreates a module for dependency managementfmt.Println,fmt.Printf, andfmt.Sprintfare your core output tools