How to Install Flask on Ubuntu

Install Flask on Ubuntu inside a Python virtual environment with pip (recommended), or from the python3-flask apt package, verify with python -m flask --version, run a Hello World app with flask run, and uninstall per method.

Published

Updated

Read time 6 min read

Reviewed byDeepak Prasad

Install Flask on Ubuntu banner with Python logo and micro web framework terminal motif

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-flask 3.1.0-2ubuntu1.1 (apt).

NOTE
Use a virtual environment per Flask project so each app can pin its own Flask and dependency versions. Reserve 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 python3 by default. Confirm with python3 --version.
  • sudo for apt packages (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.


Install Python tooling

Refresh indexes and install the venv module (and pip if your image is minimal):

bash
sudo apt update
sudo apt install -y python3 python3-venv python3-pip

Check versions:

bash
python3 --version
pip3 --version
text
Python 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:

bash
mkdir -p ~/flask_app && cd ~/flask_app
python3 -m venv venv
source venv/bin/activate

Your prompt shows (venv). Inside the venv, python and pip point at the isolated interpreter:

bash
which python pip
text
/home/user/flask_app/venv/bin/python
/home/user/flask_app/venv/bin/pip

Install Flask with pip

bash
pip install Flask
text
Collecting 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.8

Pin a specific release when a tutorial requires it:

bash
pip install 'Flask==3.1.3'

Verify the installation

bash
python -m flask --version
text
Python 3.13.3
Flask 3.1.3
Werkzeug 3.1.8

flask --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.

bash
sudo apt update
apt-cache policy python3-flask
sudo apt install -y python3-flask

On Ubuntu 25.04:

text
python3-flask:
 Candidate: 3.1.0-2ubuntu1.1

Verify:

bash
python3 -m flask --version
dpkg -l python3-flask
text
Python 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 Jinja2

The 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):

python
from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello_world:
 return 'Hello World!'
Output

Set the app module and start the development server:

bash
export FLASK_APP=hello.py
flask run
text
* 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 quit

Open 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):

bash
flask run --host=0.0.0.0

Stop the server with Ctrl+C. Leave the venv with:

bash
deactivate

For 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:

bash
source ~/flask_app/venv/bin/activate
pip install --upgrade Flask
python -m flask --version

Apt package:

bash
sudo apt update && sudo apt upgrade -y python3-flask

Reinstall project dependencies from requirements.txt after major upgrades:

bash
pip install -r requirements.txt --upgrade

Uninstall Flask

Remove a virtual environment

bash
deactivate
rm -rf ~/flask_app/venv

Delete ~/flask_app entirely if you no longer need the project.

Remove the apt package

bash
sudo apt purge -y python3-flask
sudo apt autoremove -y

Troubleshooting

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
WARNING
Do not run 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


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.

Frequently Asked Questions

1. How do I install Flask on Ubuntu?

Install python3-venv, create a virtual environment with python3 -m venv venv, activate it with source venv/bin/activate, then run pip install Flask. Verify with python -m flask --version. For a quick system package without a venv, use sudo apt install python3-flask.

2. Should I install Flask with pip or apt on Ubuntu?

Use a virtual environment and pip for development—each project gets its own Flask version. Use sudo apt install python3-flask only for quick experiments or when you accept Ubuntu pinned versions system-wide. Do not pip install Flask globally on Ubuntu 24.04+; PEP 668 blocks it.

3. Why does pip install Flask fail with externally-managed-environment?

Ubuntu 24.04 and newer mark the system Python as externally managed. Create a venv with python3 -m venv venv, activate it, then pip install Flask inside the venv. Avoid --break-system-packages unless you fully understand the risk to apt and system tools.

4. How do I check the Flask version on Ubuntu?

Inside an activated venv run python -m flask --version or flask --version. For the apt package run python3 -m flask --version after sudo apt install python3-flask.

5. How do I run a Flask app after installing?

Save app code as hello.py, export FLASK_APP=hello.py, then run flask run. Open http://127.0.0.1:5000 in a browser. Use flask run --host=0.0.0.0 when testing from another machine on the LAN.

6. How do I uninstall Flask from Ubuntu?

For a venv, run deactivate then rm -rf venv. For the apt package run sudo apt purge -y python3-flask. Remove project directories separately if you no longer need your code.
Omer Cakmak

Linux Administrator

Highly skilled at managing Debian, Ubuntu, CentOS, Oracle Linux, and Red Hat servers. Proficient in bash scripting, Ansible, and AWX central server management, he handles server operations on …