How to Install Apache Airflow: Step-by-Step Guide
To install
Airflow, use the command pip install apache-airflow in your terminal. This installs the latest stable version and its dependencies so you can start creating workflows.Syntax
The basic syntax to install Airflow is using pip, Python's package manager. You run pip install apache-airflow to get the latest stable release. You can also specify extras like postgres or mysql if you want support for those databases.
pip install apache-airflow: installs core Airflowpip install apache-airflow[postgres]: adds PostgreSQL supportpip install apache-airflow[mysql]: adds MySQL support
bash
pip install apache-airflow
Example
This example shows how to install Airflow with the PostgreSQL extra and initialize the database to start using Airflow.
bash
pip install apache-airflow[postgres]
# Initialize the Airflow database
airflow db init
# Create a user to access the Airflow web UI
airflow users create \
--username admin \
--firstname Admin \
--lastname User \
--role Admin \
--email admin@example.com
# Start the Airflow webserver
airflow webserver -p 8080Output
Successfully installed apache-airflow-2.x.x
Airflow database initialized
User admin created
Starting webserver on port 8080
Common Pitfalls
Common mistakes when installing Airflow include:
- Not using a virtual environment, which can cause package conflicts.
- Installing without specifying extras needed for your database backend.
- Skipping the
airflow db initstep, which is required to set up Airflow's internal database. - Running commands without proper permissions or Python version (Airflow requires Python 3.7+).
bash
pip install apache-airflow
# Missing extras for database support
# Wrong: skipping database initialization
# airflow db init
# Correct:
pip install apache-airflow[postgres]
airflow db initQuick Reference
Summary tips for installing Airflow:
- Use Python 3.7 or higher.
- Always install inside a virtual environment.
- Specify database extras like
[postgres]or[mysql]as needed. - Run
airflow db initafter installation. - Create a user before starting the webserver.
Key Takeaways
Install Airflow using pip with the command 'pip install apache-airflow'.
Use extras like '[postgres]' to add database support during installation.
Always initialize the Airflow database with 'airflow db init' before use.
Run Airflow inside a Python virtual environment to avoid conflicts.
Create an Airflow user before starting the webserver for access.