command module
v1.51.0 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2024 License: GPL-3.0 Imports: 9 Imported by: 7


☁ Air - Live reload for Go apps

Go Codacy Badge Go Report Card codecov


English | 简体中文 | 繁體中文


When I started developing websites in Go and using gin framework, it was a pity that gin lacked a live-reloading function. So I searched around and tried fresh, it seems not much flexible, so I intended to rewrite it better. Finally, Air's born. In addition, great thanks to pilu, no fresh, no air :)

Air is yet another live-reloading command line utility for developing Go applications. Run air in your project root directory, leave it alone, and focus on your code.

Note: This tool has nothing to do with hot-deploy for production.


  • Colorful log output
  • Customize build or any command
  • Support excluding subdirectories
  • Allow watching new directories after Air started
  • Better building process
Overwrite specify configuration from arguments

Support air config fields as arguments:

If you want to config build command and run command, you can use like the following command without the config file:

air --build.cmd "go build -o bin/api cmd/run.go" --build.bin "./bin/api"

Use a comma to separate items for arguments that take a list as input:

air --build.cmd "go build -o bin/api cmd/run.go" --build.bin "./bin/api" --build.exclude_dir "templates,build"


With go 1.22 or higher:

go install
# binary will be $(go env GOPATH)/bin/air
curl -sSfL | sh -s -- -b $(go env GOPATH)/bin

# or install it into ./bin/
curl -sSfL | sh -s

air -v
# binary will be /usr/local/bin/air
curl -sSfL | sh

# to put to a custom path
curl -sSfL | PREFIX=/tmp sh

Please pull this docker image cosmtrek/air.

docker/podman run -it --rm \
    -w "<PROJECT>" \
    -e "air_wd=<PROJECT>" \
    -v $(pwd):<PROJECT> \
    -c <CONF>
Docker/Podman .${SHELL}rc

if you want to use air continuously like a normal app, you can create a function in your ${SHELL}rc (bash,zsh,etc...)

air() {
  podman/docker run -it --rm \
    -w "$PWD" -v "$PWD":"$PWD" \
    -p "$AIR_PORT":"$AIR_PORT" \ "$@"

<PROJECT> is your project path in container, eg: /go/example if you want to enter the container, Please add --entrypoint=bash.

For example

One of my project runs in docker:

docker run -it --rm \
  -w "/go/src/" \
  -v $(pwd):/go/src/ \
  -p 9090:9090 \

Another example:

cd /go/src/
AIR_PORT=8080 air -c "config.toml"

this will replace $PWD with the current directory, $AIR_PORT is the port where to publish and $@ is to accept arguments of the application itself for example -c


For less typing, you could add alias air='~/.air' to your .bashrc or .zshrc.

First enter into your project

cd /path/to/your_project

The simplest usage is run

# firstly find `.air.toml` in current directory, if not found, use defaults
air -c .air.toml

You can initialize the .air.toml configuration file to the current directory with the default settings running the following command.

air init

After this, you can just run the air command without additional arguments and it will use the .air.toml file for configuration.


For modifying the configuration refer to the air_example.toml file.

Runtime arguments

You can pass arguments for running the built binary by adding them after the air command.

# Will run ./tmp/main bench
air bench

# Will run ./tmp/main server --port 8080
air server --port 8080

You can separate the arguments passed for the air command and the built binary with -- argument.

# Will run ./tmp/main -h
air -- -h

# Will run air with custom config and pass -h argument to the built binary
air -c .air.toml -- -h
    image: cosmtrek/air
    # working_dir value has to be the same of mapped volume
    working_dir: /project-package
      - <any>:<any>
      - ENV_A=${ENV_A}
      - ENV_B=${ENV_B}
      - ENV_C=${ENV_C}
      - ./project-relative-path/:/project-package/

air -d prints all logs.

Installation and Usage for Docker users who don't want to use air image


# Choose whatever you want, version >= 1.16
FROM golang:1.22-alpine


RUN go install

COPY go.mod go.sum ./
RUN go mod download

CMD ["air", "-c", ".air.toml"]


version: "3.8"
      context: .
      # Correct the path to your Dockerfile
      dockerfile: Dockerfile
      - 8080:3000
    # Important to bind/mount your codebase dir to /app dir for live reload
      - ./:/app


"command not found: air" or "No such file or directory"
export GOPATH=$HOME/xxxxx
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
export PATH=$PATH:$(go env GOPATH)/bin <---- Confirm this line in you profile!!!
Error under wsl when ' is included in the bin

Should use \ to escape the `' in the bin. related issue: #305

Question: how to do hot compile only and do not run anything?


  cmd = "/usr/bin/true"


Please note that it requires Go 1.16+ since I use go mod to manage dependencies.

# Fork this project

# Clone it
mkdir -p $GOPATH/src/
cd $GOPATH/src/
git clone<YOUR USERNAME>/air.git

# Install dependencies
cd air
make ci

# Explore it and happy hacking!
make install

Pull requests are welcome.

# Checkout to master
git checkout master

# Add the version that needs to be released
git tag v1.xx.x

# Push to remote
git push origin v1.xx.x

# The CI will process and release a new version. Wait about 5 min, and you can fetch the latest version

Star History

Star History Chart


Buy Me A Coffee

Give huge thanks to lots of supporters. I've always been remembering your kindness.


GNU General Public License v3.0


The Go Gopher

There is no documentation for this package.


Path Synopsis
Package runner …
Package runner …

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL