fbpx
How to Install Flask on Ubuntu and CentOS

Flask, a micro web framework written in Python, is an excellent tool for developers looking to create robust web applications. Its simplicity and flexibility make it a popular choice among developers worldwide. This article will guide you through the process of installing Flask on Ubuntu and CentOS.

Prerequisites

Make sure you have the following prerequisites before we start the installation process:

  1. A Virtono VPS running either Ubuntu or CentOS.
  2. Basic knowledge of the Linux command line.
  3. Python 3 installed on your system. Flask is a Python framework, so Python is a must-have.
  4. Pip, the Python package installer.

Installing Flask on Ubuntu

Let’s start with Ubuntu. Here’s a step-by-step guide to installing Flask on an Ubuntu system:

Step 1: Update Your System

You must update your system packages first. Then, enter the following command into the terminal:

sudo apt update && apt upgrade -y

Step 2: Install pip for Python 3

Next, install pip for Python 3 using the following command:

sudo apt-get install python3-pip
How to Install Flask on Ubuntu and CentOS

Step 3: Install Flask

You are now prepared to install Flask. To install Flask, use pip as shown below:

pip3 install Flask
How to Install Flask on Ubuntu

That’s it, then! Your Ubuntu system now has Flask installed successfully. You could make a straightforward Hello World application to check the installation.

Installing Flask on CentOS

The process of installing Flask on CentOS is slightly different. Here’s how you can do it:

Step 1: Update Your System

Just like with Ubuntu, the first step is to update your system packages. Open the terminal and type the following command:

sudo yum update

Step 2: Install EPEL Repository

CentOS requires the EPEL repository for pip installation. Install it using the following command:

sudo yum install epel-release

Step 3: Install pip for Python 3

Now, install pip for Python 3:

sudo yum install python3-pip

Step 4: Install Flask

Finally, install Flask using pip:

pip3 install Flask
How to Install Flask on CentOS

Congratulations! Your CentOS system now has Flask installed. You can build a basic Hello World application to check the installation.

Verifying Flask Installation

To verify the Flask installation on both Ubuntu and CentOS, you can create a simple Flask application.

Here are the steps:

  1. Create a new file named app.py using the following command:
nano app.py
  1. In the app.py file, add the following lines of code:
from flask import Flask
app = Flask(__name__)

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

if __name__ == '__main__':
    app.run(host='0.0.0.0')
  1. Save the file and run it using the following command:
python3 app.py
  1. Open a web browser and go to http://server-IP:5000. You should see “Hello, World!” displayed.
Install Flask on Ubuntu and CentOS

Final Thoughts

Installing Flask on Ubuntu and CentOS is simple and results in a top-notch web development tool. With Flask, developers of all experience levels can begin creating powerful web applications.


1 Comment

How To Install Rust On Ubuntu 22.04 - Virtono Community · September 21, 2023 at 11:40 AM

[…] and experienced developers. Rust has become a strong and cutting-edge option in the world of programming languages. Its emphasis on concurrency, performance, and safety has drawn developers from all over the world. […]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.