How to Install Flask in Ubuntu 20.04

Two commonly used open-source Python web frameworks are Django and Flask. Django is a robust Python framework that allows users to rapidly develop and deploy their web applications by providing an MVC framework that aims at simplifying web app development with less code along with reusable components.

Meanwhile, Flask is a microframework that is lean and devoid of extra libraries or tools. It is minimalistic as it ships with only the basic tools to help you get off the ground with developing your applications.

Without much further ado, let’s jump right in and install the flask on Ubuntu 20.04.

Installing Flask in Ubuntu

1. To install flask on Ubuntu 20.04 using apt package manager, here are the steps to follow:

First, ensure that your system is updated as shown.

$ sudo apt update -y

Once the update is complete, head over to the next step.

2. Next, you will need to install pip alongside other Python dependencies which will enable you to create a virtual environment. It’s in the virtual environment that we are going to install flask.

In case you are wondering why we are not installing Python first, well, Ubuntu 20.04 already comes pre-packaged with Python 3.8, and so there’s no need to install it.

To confirm the presence of Python on Ubuntu 20.04 run:

$ python3 --version
Check Python Version in Ubuntu
Check Python Version in Ubuntu

Next, install pip3 and other Python tools as shown.

$ sudo apt install build-essential python3-pip libffi-dev python3-dev python3-setuptools libssl-dev
Install Pip in Ubuntu
Install Pip in Ubuntu

3. Thereafter, install a virtual environment that is going to isolate and run flask in a sandboxed environment.

$ sudo apt install python3-venv
Create Python Virtual Environment
Create a Python Virtual Environment

4. Now, create the flask directory and navigate into it.

$ mkdir flask_dir && cd flask_dir

5. Create a virtual environment using Python as follows.

$ python3 -m venv venv

6. Then activate it so that you can install the flask.

$ source venv/bin/activate

Notice how the prompt changes to (venv) to indicate that we are now working inside the virtual environment.

Active Python Virtual Environment
Active Python Virtual Environment

7. Lastly, install flask web framework using pip, which will install all the components of flask including Jinja2, werkzeug WSG web application library & its modules.

$ pip3 install flask
Install Flask in Ubuntu
Install Flask in Ubuntu

8. To confirm that flask is installed, run:

$ flask --version
Check Flask Version in Ubuntu
Check Flask Version in Ubuntu

Perfect! Flask is now installed on Ubuntu 20.04. You can now proceed to create and deploy your Python applications using flask.

Two small things before you go

If something didn’t work on your setup, leave a comment and tell me which distro and version you’re on. I read every one, and most of these articles got better because a reader pointed out what was missing.

And if it did work, share it. TecMint has stayed free for 14 years because people pass these articles around, and that traffic is what pays for writing the next one.

Leave a comment
Get two free Linux courses

Learn the Linux basics with two free courses and join 34,000+ readers getting practical TecMint tutorials and selected Pro TecMint articles every week.

Pro TecMint
Get lifetime access for $99

If you want to go beyond the free tutorials, Pro gives you 18 courses, 5 ebooks, and every future course I add. One payment, lifetime access, no renewals.

Winnie Ondara
Winnie Ondara
Contributor
About the author

My name is Winnie, a Linux enthusiast and passionate tech writer in Linux and DevOPs topics. I enjoy keeping abreast with the latest technologies in the Linux ecosystem and trying out new tools provided by the FOSS community.

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.