Installing Airflow
Airflow can be installed several ways depending on your goal: a quick pip install for local experimentation, a Docker Compose stack for a more production-like local environment, or a managed service like Astronomer, MWAA, or Cloud Composer for production. Because Airflow has many optional dependencies (providers for AWS, GCP, Postgres, and so on), the Apache project publishes constraint files pinned to specific Python versions to keep installs reproducible — installing without them is one of the most common sources of dependency conflicts.
Cricket analogy: Picking an install method is like choosing how to prepare for a match: a quick pip install is like a casual net session in your backyard, while the Docker Compose stack is like training at a full BCCI-certified academy with proper pitches and equipment.
Installation Methods
For local development, the simplest path is a virtual environment plus a pip install using the official constraints URL, which pins every dependency to a version known to work with your chosen Airflow and Python versions. For a more realistic setup that includes the scheduler, webserver, and a Postgres metadata database running as separate containers, the official docker-compose.yaml from the Airflow documentation is the standard starting point — it spins up all the core services with one command and is what most tutorials and this course assume you're using.
Cricket analogy: A pip install is like practicing solo throw-downs in your yard, while docker-compose is like a full intra-squad match with fielders, umpires, and a scoreboard — closer to the real thing.
# Option A: local pip install with constraints
python3 -m venv airflow-venv
source airflow-venv/bin/activate
AIRFLOW_VERSION=2.9.3
PYTHON_VERSION="$(python3 -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}"
# Option B: Docker Compose (recommended for this course)
curl -LfO 'https://airflow.apache.org/docs/apache-airflow/2.9.3/docker-compose.yaml'
mkdir -p ./dags ./logs ./plugins ./config
echo -e "AIRFLOW_UID=$(id -u)" > .env
docker compose up airflow-init
docker compose up -dInitializing the Metadata Database
Airflow stores all of its state — DAG definitions metadata, task instance history, connections, variables, and user accounts — in a metadata database, usually Postgres or MySQL in production (SQLite only for the quickest local trials, since it can't handle the LocalExecutor's parallelism). Before Airflow can run anything, you must initialize this database with airflow db init or, on newer versions, airflow db migrate, which creates the schema, and typically create an admin user with airflow users create so you can log into the web UI.
Cricket analogy: Initializing the metadata DB is like the scorer setting up a fresh scorebook before a Test match starts — every run, wicket, and over needs a structured place to be recorded before play begins.
Never use SQLite with the LocalExecutor or CeleryExecutor in anything beyond a throwaway trial. SQLite only supports one writer at a time, so concurrent task writes will cause database locking errors. Switch to Postgres (or MySQL) as soon as you move past airflow standalone on a laptop.
Verifying Your Installation
Once services are up, visit localhost:8080 and log in with the admin credentials you created; you should see the DAGs list view with a handful of example DAGs (unless you disabled load_examples in airflow.cfg). A healthy install shows the scheduler and webserver both reporting green/healthy status in the UI's admin health panel, and the example DAG example_bash_operator should be triggerable and complete successfully within a minute or two.
Cricket analogy: Checking the health panel is like a pitch inspection before a match — the umpires walk the pitch and declare it fit for play before a ball is bowled.
- Airflow can be installed via pip with official constraint files, via Docker Compose, or through a managed service like MWAA or Cloud Composer.
- Constraint files pin dependency versions to avoid conflicts between Airflow's many optional provider packages.
- The official docker-compose.yaml spins up the scheduler, webserver, and Postgres metadata DB together — the recommended path for learning.
- Airflow's metadata database must be initialized with
airflow db migratebefore anything can run. - SQLite is only safe for the most trivial trials; Postgres or MySQL are required once you use LocalExecutor or CeleryExecutor.
- An admin user is created with
airflow users createto log into the web UI. - A healthy install shows green scheduler/webserver status and lets you successfully trigger the example DAGs.
Practice what you learned
1. Why does the official Airflow pip install command reference a constraints file?
2. Which database backend should NOT be used once you run tasks concurrently with the LocalExecutor?
3. What command is used to initialize or upgrade the Airflow metadata database schema on modern Airflow versions?
4. What is included in the official Airflow docker-compose.yaml stack?
5. What port does the Airflow webserver default to when running the standard docker-compose setup?
Was this page helpful?
You May Also Like
What Is Apache Airflow?
An introduction to Apache Airflow as a platform for programmatically authoring, scheduling, and monitoring workflows defined as code.
The Airflow Architecture
How Airflow's scheduler, webserver, executor, and metadata database work together to parse, schedule, and execute your DAGs.
The Airflow UI
A guided tour of the Airflow web interface, from the DAGs list and Grid view to task logs, Connections, and Variables.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics
ProgrammingPowerShell Study Notes
Programming · 30 topics