Installing Flask on Linux: A Comprehensive Guide
Flask, a popular Python web framework, is widely used for building small to medium-sized web applications. If you're a Linux user eager to start developing with Flask, this guide will walk you through the installation process step by step. Let's dive in!
Prerequisites
Before installing Flask, ensure you have the following prerequisites on your Linux system:
- Python 3.6 or later
- pip (Python's package installer) - comes bundled with Python
Installing Flask via pip
The recommended way to install Flask is using pip. Open your terminal and type the following command:

pip install flask
If you're using a specific Python version, make sure to use the corresponding pip version. For example, for Python 3.8, use:
pip3.8 install flask
Once the installation is complete, you should see a message similar to "Successfully installed Flask-2.0.1".
Verifying the Installation
To confirm that Flask is installed correctly, create a new Python file (e.g., `app.py`) and add the following code:

from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return "Hello, World!"
if __name__ == '__main__':
app.run(debug=True)
Then, run the application using:
python app.py
If everything is set up correctly, you should see the message "Running on http://127.0.0.1:5000/" and be able to access the application at http://127.0.0.1:5000/ in your web browser.
Installing Flask as a Virtual Environment
It's a good practice to install Flask within a virtual environment to isolate dependencies. Here's how to create and activate a virtual environment, then install Flask:

- Create a new virtual environment:
python3 -m venv flask_env - Activate the virtual environment:
- For bash:
source flask_env/bin/activate - For fish:
source flask_env/bin/activate.fish - For zsh:
source flask_env/bin/activate.zsh
- For bash:
- Install Flask:
pip install flask
Troubleshooting Common Issues
| Issue | Solution |
|---|---|
| Flask not found after installation | Try importing Flask in a Python shell: from flask import Flask. If successful, the issue might be with your Python interpreter configuration. |
| Permission denied when installing Flask | Use sudo to run the installation command with elevated privileges: sudo pip install flask. |
That's it! You've successfully installed Flask on your Linux system and are ready to start building web applications. Happy coding!






















