Introduction to Go
last modified July 22, 2026
This is an introduction to the Go programming language, often referred to as Golang. Go first appeared in 2009 and was created at Google by Robert Griesemer, Rob Pike, and Ken Thompson.
Go
Go is a statically typed, compiled programming language designed for building scalable, reliable software. It has carved out a strong niche in cloud services, CLI tools, networking, and API servers.
A standout feature of Go is its compilation to a single static binary, which makes deployment trivial. Go also has fast compilation, built-in concurrency primitives (goroutines and channels), memory safety, and garbage collection.
Go installation
The recommended way to install Go on Linux is through the system package
manager. For instance, on Debian/Ubuntu we can use apt:
$ sudo apt install golang-go
On Fedora:
$ sudo dnf install golang
Package managers handle updates automatically and integrate Go into the system. However, they may provide an earlier version than the latest release.
The traditional method is to download the binary tarball from go.dev/dl/. This always provides the newest version.
$ wget https://go.dev/dl/go1.26.2.linux-amd64.tar.gz
We extract the archive to /usr/local:
$ sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.26.2.linux-amd64.tar.gz
Then we add /usr/local/go/bin to the PATH in
~/.profile or ~/.bashrc:
$ export PATH=$PATH:/usr/local/go/bin
> winget install GoLang.Go
On Windows, we can use the winget package manager.
Alternatively, we can download the MSI installer directly from go.dev/dl/ and run it. The installer automatically sets up the required environment paths.
Editor setup
A common choice for Go development is VS Code
with the Go extension, which provides code completion, syntax highlighting,
debugging, and refactoring tools. After installing VS Code, press
Ctrl+P and run:
ext install golang.Go
Alternatively, GoLand is a dedicated IDE with built-in Go support.
The Go tool
The go tool provides the standard way to fetch, build, and install Go packages and commands.
$ go version go version go1.26.2 linux/amd64
With the version option, we get the version of Go.
> go version go version go1.26.2 windows/amd64
This is the output on Windows.
| command | description |
|---|---|
go build |
compiles packages and dependencies |
go env |
prints Go environment information |
go fmt |
formats Go source code |
go get |
adds dependencies to current module |
go install |
compiles and installs packages and dependencies |
go list |
lists packages and modules |
go mod tidy |
removes unused dependencies and adds missing ones |
go run |
compiles and runs a Go program |
go version |
prints Go version |
go vet |
reports suspicious constructs in Go code |
This is a partial list of Go tool commands.
Go first example
We create our first example.
$ mkdir simple $ cd simple
We create a project directory and relocate there.
$ go mod init zetcode.com/simple
We initiate a Go module.
package main
import "fmt"
func main() {
fmt.Println("Go simple example")
}
This is a simple Go program, which prints a message to the console.
$ go run main.go Go simple example
We can compile and execute the program in one go with go run
command.
$ go build $ ls go.mod main main.go $ ./main Go simple example
We can create an executable program with go build.
$ go install $ ls ~/go/bin/ main
With the go install command, we install the binary to the special
GOPATH directory, which defaults to $HOME/go on Unix.
In the next example, we show variables, basic types, and a for loop.
package main
import (
"fmt"
"math"
)
func main() {
primes := []int{2, 3, 5, 7, 11}
for _, val := range primes {
sq := val * val
fmt.Printf("%d squared is %d\n", val, sq)
}
radius := 7.5
area := math.Pi * radius * radius
fmt.Printf("Area of circle with radius %.1f is %.2f\n", radius, area)
}
The example demonstrates a slice, a for loop with range,
a local variable, and a floating-point calculation using the math package.
Source
The Go Programming Language Specification
In this article we have introduced the Go language.
Author
List all Go tutorials.