Data Engineering Path · Airflow
Installing Airflow Locally
🚀
Setting Up Your Local Development Environment
There are several ways to install Airflow locally. The right choice depends on your experience level and what you want to accomplish.
Installation Methods Comparison
| Method | Complexity | Best For | Reproducible? |
|---|---|---|---|
| pip install | 🟢 Low | Quick learning, single-user dev | No |
| Docker Compose | 🟡 Medium | Team development, realistic setup | Yes |
| Astro CLI | 🟢 Low | Professional development | Yes |
| Helm Chart | 🔴 High | Production on Kubernetes | Yes |
Method 1: pip install (Quickest Start)
# 1. Create a virtual environment
python -m venv airflow_venv
source airflow_venv/bin/activate # On Windows: .\airflow_venv\Scripts\activate
# 2. Set the Airflow home directory
export AIRFLOW_HOME=~/airflow
# 3. Install Airflow with constraints (IMPORTANT!)
AIRFLOW_VERSION=2.10.0
PYTHON_VERSION="$(python -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')"
CONSTRAINT_URL="https://raw.githubusercontent.com/apache/airflow/constraints-${AIRFLOW_VERSION}/constraints-${PYTHON_VERSION}.txt"
pip install "apache-airflow==${AIRFLOW_VERSION}" --constraint "${CONSTRAINT_URL}"
# 4. Initialize the database
airflow db migrate
# 5. Create an admin user
airflow users create \
--username admin \
--firstname Admin \
--lastname User \
--role Admin \
--email admin@example.com \
--password admin
# 6. Start Airflow (in separate terminals)
airflow webserver --port 8080 # Terminal 1
airflow scheduler # Terminal 2
🚨 Caution
Always use constraint files when installing Airflow. Airflow has hundreds of dependencies, and without constraints, you'll get incompatible library versions. The constraint URL ensures all dependencies are compatible with your Airflow version.
Always use constraint files when installing Airflow. Airflow has hundreds of dependencies, and without constraints, you'll get incompatible library versions. The constraint URL ensures all dependencies are compatible with your Airflow version.
Method 2: Docker Compose (Recommended for Teams)
# 1. Create project directory
mkdir airflow-docker && cd airflow-docker
# 2. Download the official docker-compose.yaml
curl -LfO 'https://airflow.apache.org/docs/apache-airflow/2.10.0/docker-compose.yaml'
# 3. Create required directories
mkdir -p ./dags ./logs ./plugins ./config
# 4. Set the Airflow UID
echo -e "AIRFLOW_UID=$(id -u)" > .env
# 5. Initialize Airflow (first time only)
docker compose up airflow-init
# 6. Start all services
docker compose up -d
# 7. Access the UI
# Open http://localhost:8080
# Username: airflow
# Password: airflow
The official docker-compose.yaml includes:
| Service | Purpose |
|---|---|
airflow-webserver |
Serves the UI on port 8080 |
airflow-scheduler |
Runs the scheduler daemon |
airflow-worker |
CeleryExecutor worker |
airflow-triggerer |
Handles deferrable tasks |
postgres |
Metadata database |
redis |
Celery message broker |
flower |
Celery monitoring UI (port 5555) |
💡 Tip
Docker Compose is the recommended method for local development because it closely mirrors a production deployment. Your DAGs go in the
Docker Compose is the recommended method for local development because it closely mirrors a production deployment. Your DAGs go in the
./dags folder and are automatically synced to all containers.
Method 3: Astro CLI (Astronomer)
# 1. Install Astro CLI
curl -sSL install.astronomer.io | sudo bash
# 2. Initialize a new project
mkdir my-airflow-project && cd my-airflow-project
astro dev init
# 3. Start Airflow
astro dev start
# 4. Access the UI
# Open http://localhost:8080
# Username: admin
# Password: admin
The Astro CLI creates a clean project structure:
my-airflow-project/
├── dags/ # Your DAG files
│ └── example_dag.py
├── include/ # Supporting files
├── plugins/ # Custom plugins
├── tests/ # DAG tests
├── Dockerfile # Custom Airflow image
├── packages.txt # OS-level dependencies
├── requirements.txt # Python dependencies
└── airflow_settings.yaml # Connections & Variables
Post-Installation Verification
After installing Airflow using any method, verify your setup:
# Check Airflow version
airflow version
# Check database connection
airflow db check
# List example DAGs (should show default examples)
airflow dags list
# Test a specific DAG
airflow dags test example_bash_operator 2024-01-01