How to Install Flask on Ubuntu 20.04 LTS

Flask is an open-source web framework built with Python programming language. The software is a minimalistic, light, fast framework that doesn’t include ORM, form validation, and other third-party libs. Flash ships with only the essential tools to develop your web applications and maintain them compared to Django, another popular web framework development software. Flask is based on Werkzeug and uses Jinja2 as a template engine.

The installation of Flask can be done in two ways. The first is installing the software from Ubuntu’s official “apt” repository package manager, which is the easiest; however, most people will recommend installing Flask in a virtual environment.

Update Ubuntu

First, make sure your Ubuntu system is up to date. You will need root access or sudo privileges for the installation.

sudo apt update && sudo apt upgrade -y

Install Required Packages

To successfully install the Flask framework, you will need to ensure the default Python package is installed on your system. Run the following command that will either install or return an already installed message.

sudo apt install python3

Install PIP

You will need to install PIP for Python, enabling you to create virtual environments. As stated, you will install Flask most commonly in a virtual environment.

sudo apt install build-essential python3-pip libffi-dev python3-dev python3-setuptools libssl-dev -y

Install Virtual Environment

Now, you can install the virtual environment to isolate and run Flask. You do this with the following.

sudo apt install python3-venv -y

Create Flask Location Directory

Once the virtual environment is installed, create a flask direct and open the created directory using the following command.

mkdir -p ~/projects/flask && cd ~/projects/flask

This is just an example, feel free to modify it if required.

Create Virtual Environment

In the directory, you now need to run the command to create the virtual environment as follows.

python3 -m venv venv

Now, activate the virtual environment.

source venv/bin/activate

Once activated, you will notice the terminal command line, which now has “venv” to indicate that you are currently working in the virtual environment that has been created.

How to Install Flask on Ubuntu 20.04

Install Flask

The final stage is installing the actual Flask software in your virtual environment. You do this with Pip3, which will install all the components needed for Flask, such as Jinja2, Werkzeug WSG web application library, and its modules.

pip3 install flask

Now, confirm the version of Flask to make sure the installation has been completed correctly.

python -m flask --version

Example output:

How to Install Flask on Ubuntu 20.04

Congratulations, you have successfully installed Flask.

Comments and Conclusion

The tutorial has shown you how to set up a Python virtual environment and install Flask. The Flask documentation is the best start to visit to learn how to create and deploy your Python applications using Flask for developers needing documentation.



Follow LinuxCapable.com!

Like to get automatic updates? Follow us on one of our social media accounts!