Set up and maintain Go projects
Install Air and Run a Go App with Live Reload
Install Air for Go live reload, run an app under ./cmd/server, and check that a watched source change reaches the restarted process.

Air handles the local rebuild-and-restart loop while you edit a Go application. The important setup choice is what it builds: if your main package lives at ./cmd/server, building the project root may target the wrong package. Air is for development live reload, not production hot deployment.
Install Air
From an existing Go project, install Air using the air-verse module path:
go install github.com/air-verse/air@latest
If your shell cannot find air afterward, add the Go bin directory to its PATH:
export PATH="$PATH:$(go env GOPATH)/bin"
That export applies to the current shell. If a new terminal cannot find air, add it to your shell’s startup configuration and open another terminal. For help setting up Go itself, see Install the Go Toolchain and Configure PATH, GOROOT, and GOPATH on Linux, macOS, and Windows. The @latest command does not pin a particular Air release for this walkthrough.
Generate a configuration from the project root
From the root of an existing Go project, run:
air init
This creates .air.toml with default settings. Air looks for that file in the current directory when you start it. Use either of these commands from the same project root:
air
Or, to select the file explicitly:
air -c .air.toml
These are alternative ways to start Air, not successive steps. Inspect the generated file before relying on its defaults. It gives you a starting point for the Air installation you have, but you still need to check that its build and run behavior matches your project’s layout.
Check what Air watches and builds
A useful reload loop has two jobs. Air must notice an edit to a file that matters, then build the intended application and start the resulting executable. A working watcher cannot compensate for a build command pointed at the wrong main package. Likewise, a correct build command is little help if the file you edit is outside the watcher’s scope.
Review the watch choices present in your generated .air.toml against the files you actually edit. Include relevant source files and, if your application uses them, templates that should trigger a rebuild. Check whether generated output or unrelated directories are watched unnecessarily, and whether a directory containing source you expect to edit is excluded. Make changes in the generated file rather than replacing it with a copied configuration from another Air installation. Then inspect its build and run settings against the location of your main package.
Build a main package under ./cmd/server
There is also a command-line route for specifying the build command and executable without a config file. For a project whose main package is under ./cmd/server, run this from the project root without .air.toml in that directory:
mkdir -p bin
air --build.cmd "go build -o bin/api ./cmd/server" --build.entrypoint "./bin/api"
Create bin first so the build command has a directory for its output. Here, the build command targets the project-relative ./cmd/server directory and writes bin/api; the entrypoint names the executable Air should start. This is an illustrative command: change the package path and executable path to match your project. It is an alternative to editing the generated configuration, not a set of .air.toml keys to copy into it. If you already ran air init while exploring that route, set the generated file aside before trying the no-config command. Do not assume this command and an existing config combine into the setup you intended.
Verify the reload loop
Start Air from the project root using one route. Wait for the initial build to complete and the application to start. Edit and save a Go file within the watcher’s scope, preferably one whose effect you can observe, such as an existing HTTP response or startup message. Look for another build and restart. Then request the changed endpoint or read the new startup output. A file-change notification alone does not establish that the new process is serving your change.
If air is not found, check PATH. If the build fails or targets the wrong package, compare the build command with your actual main package and fix the build error. If an edit produces no rebuild, compare that file’s location with the watch scope and exclusions in the generated configuration. If Air rebuilds but the behavior stays the same, check which application you started and whether the edited code affects the output you are inspecting.


Comments
No comments yet.