How to PROPERLY install flask on Ubuntu [Step-by-Step]

Flask is a micro web Framework written in Python that speeds up application development by providing basic backend components for developers to build on. Flask is simple and lightweight, one of the most manageable Frameworks and contains only the vital requirements for web development. It is designed to be highly extensible so developers can customize it as they see fit.

If you are using Ubuntu as a developer, this article is for you. Let's explain step by step what to do to install Flask on Ubuntu.



How to install flask on Ubuntu?

For installation, simply follow the steps below.

Step-1: Update System

First be sure the system is up to date:

foc@ubuntu22:~$ sudo apt update -y

Access to the repository has been checked and package lists have been pulled.


Step-2: Install Python and Pip Packages

To install Flask, basically python and pip packages must be installed. Mostly python is installed by default in the operating system. Check that Python is installed on your system:

foc@ubuntu22:~$ python3 --version
Python 3.10.6

If it is not installed, you can install the python and pip packages with the following command:

foc@ubuntu22:~$ sudo apt install python3 python3-pip -y


foc@ubuntu22:~$ sudo apt-get install python3 python3-pip -y

Check pip version:

foc@ubuntu22:~$ pip3 --version
pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10)


Step-3: Create a virtual environment

Create a virtual environment using Python as follows. First, install the env package of python:

foc@ubuntu22:~$ sudo apt install python3-venv -y

Create flask_folder and change to this directory:

foc@ubuntu22:~$ mkdir flask_folder && cd flask_folder

Create a virtual environment as below:

foc@ubuntu22:~/flask_folder$ python3 -m venv venv

Then activate env so that you can install the flask:

foc@ubuntu22:~/flask_folder$ source venv/bin/activate
(venv) foc@ubuntu22:~/flask_folder$


Step-4: Install Flask using pip3

As the last step, install flask with pip3:

(venv) foc@ubuntu22:~/flask_dir$ pip3 install flask
Collecting flask
Downloading Flask-2.2.2-py3-none-any.whl (101 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 101.5/101.5 KB 430.9 kB/s eta 0:00:00
Collecting Werkzeug>=2.2.2
Downloading Werkzeug-2.2.2-py3-none-any.whl (232 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 232.7/232.7 KB 1.7 MB/s eta 0:00:00
Collecting Jinja2>=3.0
Downloading Jinja2-3.1.2-py3-none-any.whl (133 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 133.1/133.1 KB 2.2 MB/s eta 0:00:00
Collecting itsdangerous>=2.0
Downloading itsdangerous-2.1.2-py3-none-any.whl (15 kB)
Collecting click>=8.0
Downloading click-8.1.3-py3-none-any.whl (96 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 96.6/96.6 KB 2.5 MB/s eta 0:00:00
Collecting MarkupSafe>=2.0
Downloading MarkupSafe-2.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25 kB)
Installing collected packages: MarkupSafe, itsdangerous, click, Werkzeug, Jinja2, flask
Successfully installed Jinja2-3.1.2 MarkupSafe-2.1.1 Werkzeug-2.2.2 click-8.1.3 flask-2.2.2 itsdangerous-2.1.2

Installation completed successfully. Check the version:

(venv) foc@ubuntu22:~/flask_dir$ flask --version
 Python 3.10.6 Flask 2.2.2 Werkzeug 2.2.2


What’s Next

Steps to Create Python Web App | Python Flask Example
Flask Templates with Jinja2 Explained in Detail
Deploy flask with gunicorn and nginx



We talked about installing Flask on Ubuntu. If you haven't written an app with Flask before, you can start from this "Steps to Create Python Web App | Python Flask Example" article.


References - Flask Installation


Didn't find what you were looking for? Perform a quick search across GoLinuxCloud

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can either use the comments section or contact me form.

Thank You for your support!!

Leave a Comment