In this article, we will have explained the necessary steps to install and configure Flask on Ubuntu 20.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo
privileges. All the commands in this tutorial should be run as a non-root user.
Flask is a free and open-source micro web framework written in Python. It is classified as a microframework because it does not require particular tools or libraries. It has no database abstraction layer, form validation, or any other components where pre-existing third-party libraries provide common functions. It is designed to make getting started quick and easy.
Install Flask on ubuntu 20.04
Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.
sudo apt update sudo apt upgrade
Step 2. Install Python.
Ubuntu 20.04 arrived with Python 3.8. You can verify that Python is installed on your system using the following command below:
python3 -V
The recommended way to create a virtual environment is by using the venv
module, which is provided by the python3-venv
package. Run the following command to install the package:
sudo apt install python3-pip python3-dev build-essential libssl-dev libffi-dev python3-setuptools
Next, you can install a virtual environment using the below command:
sudo apt install python3-venv
Once the module is installed, now create a new directory and switch to that directory:
mkdir flaskapp cd flaskapp
After that, run the below command inside the directory to create a virtual environment:
python3 -m venv venv
To start using the virtual environment, you need to activate it with the activate
script:
source venv/bin/activate
Step 3. Install Flask on Ubuntu system.
Within the activated environment, use the following command to install Flask:
pip install Flask
To confirm that flask is installed, run:
python -m flask --version
Output:
(venv) [email protected]:~/flask_dir# python -m flask --version Python 3.8.5 Flask 1.1.2 Werkzeug 1.0.1
That’s all you need to do to install the Flask on Ubuntu 20.04 LTS Focal Fossa. I hope you find this quick tip helpful. For further reading on Flask, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.