Air for Go: Complete Guide with Examples

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

What is Air and why is it needed?

\n\n

Air is a powerful utility for Go developers that provides live reload (hot reload) for applications. If you have ever written web applications in Go, you know how tedious it is to manually stop the server (Ctrl+C), recompile the project (go build), and start it again each time. Air automates this process: it monitors changes in your project's source code and automatically rebuilds and restarts the application whenever a file is saved.

\n\n

Air was created by the Cosmos team (formerly known as Tendermint) and is written in Go itself. It is not a library in the classical sense (you do not import it into your code), but rather a command-line tool that runs alongside your application.

\n\n

Why is Air needed?

\n
    \n
  • Accelerates development: saves minutes spent on manual recompilation.
  • \n
  • Convenience: just save a file — and the server restarts automatically.
  • \n
  • Supports any Go project: works with web servers, CLI utilities, Telegram bots, and any other applications.
  • \n
  • Flexible configuration: you can configure folder ignoring, delays, additional commands, and much more.
  • \n
\n\n

Air is especially useful when developing web applications on frameworks like Gin, Echo, Fiber, or the standard net/http, where every edit requires a server restart.

\n\n

Installing Air

\n\n

Air can be installed in several ways. Choose the one most suitable for your system.

\n\n

Method 1: Installation via go install (recommended)

\n

The simplest way is to use the standard Go package manager. Make sure you have Go version 1.16 or higher installed.

\n
go install github.com/air-verse/air@latest
\n

After this, the air binary will be placed in the $GOPATH/bin directory (usually ~/go/bin). Make sure this directory is added to the PATH environment variable.

\n\n

Method 2: Installation via Homebrew (macOS / Linux)

\n

If you are using macOS or Linux with Homebrew, installation is trivial:

\n
brew install air
\n\n

Method 3: Installation via script (Linux / macOS / WSL)

\n

You can use the installation script:

\n
curl -sSfL https://raw.githubusercontent.com/air-verse/air/master/install.sh | sh -s
\n\n

Method 4: Installation via Docker

\n

For those who prefer Docker:

\n
docker run -it --rm -v "$PWD":/app -w /app cosmtrek/air
\n\n

Verifying installation

\n

After installation, verify that Air works:

\n
air -v
\n

You should see the utility version, for example: v1.52.3

\n\n

Quick start with a code example

\n\n

Let's create a simple web application in Go and set up live reload for it using Air.

\n\n

Step 1: Create a new project

\n
mkdir my-air-app\ncd my-air-app\ngo mod init my-air-app
\n\n

Step 2: Write a simple HTTP server

\n

Create a file main.go:

\n
package main\n\nimport (\n    "fmt"\n    "net/http"\n)\n\nfunc main() {\n    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {\n        fmt.Fprintf(w, "Hello, Air! Current time: %s", time.Now().Format("15:04:05"))\n    })\n\n    fmt.Println("Server started on http://localhost:8080")\n    http.ListenAndServe(":8080", nil)\n}
\n\n

Step 3: Initialize Air configuration

\n
air init
\n

This command creates a .air.toml file in the project root with default settings. You can edit it later to suit your needs.

\n\n

Step 4: Run Air

\n
air
\n

You will see output, by

Recommendations