Flask is a lightweight Python web framework built on Werkzeug and Jinja2. Unlike Django, it ships without an ORM, admin panel, or form layer—you add what you need through extensions. On Ubuntu, you can install Flask from pip inside a virtual environment (what Flask’s official docs recommend) or from the python3-flask apt package for a quick system-wide install.
Many tutorials often show bare pip install flask on the system Python. On Ubuntu 24.04 and newer that fails with externally-managed-environment—and even when it worked, global pip installs collide across projects. This guide uses a venv-first workflow, documents the apt shortcut, runs a Hello World app, and covers verify, update, and uninstall steps end to end.
Tested on: Ubuntu 25.04 (Plucky Puffin); kernel 6.14.0-37-generic; Python 3.13.3; Flask 3.1.3 (pip in venv);
python3-flask3.1.0-2ubuntu1.1 (apt).
sudo apt install python3-flask for quick trials or when you deliberately want Ubuntu’s packaged build.
Prerequisites
- Ubuntu 22.04 LTS, 24.04 LTS, or newer (25.04 tested here).
- Python 3—Ubuntu Desktop and Server images ship
python3by default. Confirm withpython3 --version. - sudo for
aptpackages (python3-venv,python3-pip,python3-flask). - Outbound HTTPS to PyPI when using
pip install Flask.
See check Ubuntu version if you are unsure which release you are on. For installing a newer Python beside the system default, see install latest Python on Ubuntu.
Choose an install method
| Method | Best for | Jump to |
|---|---|---|
| pip in a virtual environment | Developers building Flask apps—isolated deps per project, latest PyPI releases | Method 1 |
apt python3-flask |
Quick system-wide install, classroom labs, or scripts that use Ubuntu’s pinned package | Method 2 |
For most developers, create a venv and pip install Flask. Use apt only when you accept one shared Flask version for the whole system.
Method 1: Install Flask in a virtual environment (recommended)
Install Python tooling
Refresh indexes and install the venv module (and pip if your image is minimal):
sudo apt update
sudo apt install -y python3 python3-venv python3-pipCheck versions:
python3 --version
pip3 --versionPython 3.13.3
pip 25.0 from /usr/lib/python3/dist-packages/pip (python 3.13)Create and activate a virtual environment
Pick a project directory—~/flask_app is fine:
mkdir -p ~/flask_app && cd ~/flask_app
python3 -m venv venv
source venv/bin/activateYour prompt shows (venv). Inside the venv, python and pip point at the isolated interpreter:
which python pip/home/user/flask_app/venv/bin/python
/home/user/flask_app/venv/bin/pipInstall Flask with pip
pip install FlaskCollecting Flask
Downloading flask-3.1.3-py3-none-any.whl.metadata (3.2 kB)
...
Successfully installed Flask-3.1.3 blinker-1.9.0 click-8.4.2 itsdangerous-2.2.0 jinja2-3.1.6 markupsafe-3.0.3 werkzeug-3.1.8Pin a specific release when a tutorial requires it:
pip install 'Flask==3.1.3'Verify the installation
python -m flask --versionPython 3.13.3
Flask 3.1.3
Werkzeug 3.1.8flask --version prints the same lines when the venv is active.
Method 2: Install Flask from Ubuntu apt
Ubuntu ships python3-flask in main. It is simpler but ties you to Ubuntu’s package version and dependency set—not ideal when two projects need different Flask releases.
sudo apt update
apt-cache policy python3-flask
sudo apt install -y python3-flaskOn Ubuntu 25.04:
python3-flask:
Candidate: 3.1.0-2ubuntu1.1Verify:
python3 -m flask --version
dpkg -l python3-flaskPython 3.13.3
Flask 3.1.3
Werkzeug 3.1.8
ii python3-flask 3.1.0-2ubuntu1.1 all micro web framework based on Werkzeug and Jinja2The Debian version string (3.1.0-2ubuntu1.1) can differ from the runtime Flask line above—Ubuntu backports security fixes inside the same source package.
Run a minimal Hello World app
This matches the first-app flow in the Flask quickstart.
Create hello.py in your project directory (use the venv from Method 1, or Method 2’s system Python):
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world:
return 'Hello World!'Set the app module and start the development server:
export FLASK_APP=hello.py
flask run* Serving Flask app 'hello.py'
* Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment.
* Running on http://127.0.0.1:5000
Press CTRL+C to quitOpen http://127.0.0.1:5000 in a browser—you should see Hello World!.
To reach the dev server from another host on your network (VM LAN testing):
flask run --host=0.0.0.0Stop the server with Ctrl+C. Leave the venv with:
deactivateFor a fuller tutorial, continue with Steps to Create Python Web App | Python Flask Example, Flask Templates with Jinja2, and Deploy Flask with Gunicorn and Nginx.
Keep Flask updated
Inside a venv:
source ~/flask_app/venv/bin/activate
pip install --upgrade Flask
python -m flask --versionApt package:
sudo apt update && sudo apt upgrade -y python3-flaskReinstall project dependencies from requirements.txt after major upgrades:
pip install -r requirements.txt --upgradeUninstall Flask
Remove a virtual environment
deactivate
rm -rf ~/flask_app/venvDelete ~/flask_app entirely if you no longer need the project.
Remove the apt package
sudo apt purge -y python3-flask
sudo apt autoremove -yTroubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
error: externally-managed-environment |
pip install on system Python (24.04+) |
Create and activate a venv, then pip install Flask |
flask: command not found |
Venv not activated or Flask not installed | source venv/bin/activate and pip install Flask |
No module named flask |
Wrong interpreter | Use python -m flask inside the venv where Flask was installed |
Address already in use on port 5000 |
Another process on :5000 |
flask run --port 5001 or stop the other service |
| Apt Flask older than PyPI tutorial | Ubuntu pins versions | Use Method 1 venv + pip install 'Flask==X.Y.Z' |
python3: command not found |
Minimal image without Python | sudo apt install python3 python3-venv python3-pip |
pip install Flask with --break-system-packages on Ubuntu unless you are deliberately overriding PEP 668 and accept the risk to apt and system Python tools.
References
- Flask — Installation
- Flask — Quickstart
- On-site: Flask web app example, Flask templates, Flask with Gunicorn and Nginx, install latest Python on Ubuntu
Summary
Install Flask on Ubuntu by creating a virtual environment (python3 -m venv venv), activating it, and running pip install Flask—then verify with python -m flask --version. Run a first app with export FLASK_APP=hello.py and flask run. For a quick system package, use sudo apt install python3-flask, knowing Ubuntu pins versions and global pip install is blocked on modern releases.
Next steps: build a real app in the Flask Python web app example, add Jinja2 templates, and deploy with Gunicorn and Nginx when you outgrow the development server.

